Repository navigation
Expand file tree
/
Copy pathGuestTicketDto.java
More file actions
71 lines (66 loc) · 2.74 KB
/
Copy pathGuestTicketDto.java
File metadata and controls
71 lines (66 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package dev.escalated.dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import dev.escalated.models.Attachment;
import dev.escalated.models.Reply;
import dev.escalated.models.Ticket;
import dev.escalated.models.TicketPriority;
import dev.escalated.models.TicketStatus;
import java.time.Instant;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
/**
* A ticket as the guest holding its access token sees it: the fields the
* shared frontend's guest ticket page reads (reference, subject, description,
* status, priority, department name, attachments, replies) and nothing staff
* keep to themselves. Internal notes, the activity log, the assigned agent,
* SLA data, tags, links and side conversations are left out.
*/
public record GuestTicketDto(
Long id,
String reference,
String subject,
String description,
TicketStatus status,
TicketPriority priority,
String channel,
Map<String, String> department,
@JsonProperty("requester_name") String requesterName,
@JsonProperty("created_at") Instant createdAt,
@JsonProperty("updated_at") Instant updatedAt,
@JsonProperty("resolved_at") Instant resolvedAt,
@JsonProperty("closed_at") Instant closedAt,
List<Attachment> attachments,
List<GuestReplyDto> replies) {
public static GuestTicketDto from(Ticket ticket) {
List<GuestReplyDto> publicReplies = ticket.getReplies().stream()
.filter(reply -> !reply.isInternal())
.sorted(Comparator.comparing(Reply::getCreatedAt, Comparator.nullsLast(Comparator.naturalOrder())))
.map(GuestReplyDto::from)
.toList();
// Attachments sent with a reply travel with that reply; only the ones
// filed on the ticket itself belong here.
List<Attachment> ticketAttachments = ticket.getAttachments().stream()
.filter(attachment -> attachment.getReply() == null)
.toList();
return new GuestTicketDto(
ticket.getId(),
ticket.getTicketNumber(),
ticket.getSubject(),
ticket.getBody(),
ticket.getStatus(),
ticket.getPriority(),
ticket.getChannel(),
ticket.getDepartment() == null
? null
: Collections.singletonMap("name", ticket.getDepartment().getName()),
ticket.getRequesterName(),
ticket.getCreatedAt(),
ticket.getUpdatedAt(),
ticket.getResolvedAt(),
ticket.getClosedAt(),
ticketAttachments,
publicReplies);
}
}