/
ticket.go
57 lines (47 loc) · 1.91 KB
/
ticket.go
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
package db
import (
"context"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"github.com/nam-truong-le/lambda-utils-go/v3/pkg/aws/ssm"
"github.com/nam-truong-le/lambda-utils-go/v3/pkg/mongodb"
)
const colTickets = "tickets"
func CollectionTickets(ctx context.Context) (*mongo.Collection, error) {
database, err := ssm.GetParameter(ctx, "/mongo/database", false)
if err != nil {
return nil, err
}
return mongodb.Collection(ctx, database, colTickets)
}
type TicketStatus string
const (
TicketStatusNew TicketStatus = "NEW"
TicketStatusClosed TicketStatus = "CLOSED"
TicketStatusInProgress TicketStatus = "IN_PROGRESS" // TicketStatusInProgress admin must process it
TicketStatusPending TicketStatus = "PENDING" // TicketStatusPending service worker must process it
)
type TicketCustomer struct {
FirstName string `bson:"firstName" json:"firstName"`
LastName string `bson:"lastName" json:"lastName"`
Telephone string `bson:"telephone" json:"telephone"`
Email string `bson:"email" json:"email"`
OrderReference string `bson:"orderReference" json:"orderReference"`
}
type TicketMessage struct {
From string `bson:"from" json:"from"`
Role string `bson:"role" json:"role"`
Text string `bson:"text" json:"text"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
}
type Ticket struct {
ID primitive.ObjectID `bson:"_id" json:"id"`
TicketNumber string `bson:"ticketNumber" json:"ticketNumber"`
Status TicketStatus `bson:"status" json:"status"`
StoreKey string `bson:"storeKey" json:"storeKey"`
Customer TicketCustomer `bson:"customer" json:"customer"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"`
Messages []TicketMessage `bson:"messages" json:"messages"`
}