-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathevent.go
More file actions
135 lines (105 loc) · 3.26 KB
/
event.go
File metadata and controls
135 lines (105 loc) · 3.26 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package domain
import (
"context"
"time"
"github.com/gofrs/uuid"
"github.com/traPtitech/knoQ/domain/filters"
)
type ScheduleStatus int
const (
Pending ScheduleStatus = iota + 1
Attendance
Absent
)
type Event struct {
ID uuid.UUID
Name string
Description string
Room Room
Group Group
TimeStart time.Time
TimeEnd time.Time
CreatedBy User
Admins []User
Tags []EventTag
AllowTogether bool
Attendees []Attendee
Open bool
Model
}
type EventTag struct {
Tag Tag
Locked bool
}
type Attendee struct {
UserID uuid.UUID
Schedule ScheduleStatus
}
func (e *Event) TimeConsistency() bool {
return e.TimeStart.Before(e.TimeEnd)
}
func (e *Event) RoomTimeConsistency() bool {
times := e.Room.CalcAvailableTime(e.AllowTogether)
for _, t := range times {
start := t.TimeStart
end := t.TimeEnd
if (start.Equal(e.TimeStart) || start.Before(e.TimeStart)) &&
(end.Equal(e.TimeEnd) || end.After(e.TimeEnd)) {
return true
}
}
return false
}
func (e *Event) AdminsValidation() bool {
return len(e.Admins) != 0
}
// WriteEventParams is used create and update
type WriteEventParams struct {
Name string
Description string
GroupID uuid.UUID
RoomID uuid.UUID
Place string // option
TimeStart time.Time
TimeEnd time.Time
Admins []uuid.UUID
Tags []EventTagParams
AllowTogether bool
Open bool
}
func (e *WriteEventParams) TimeConsistency() bool {
return e.TimeStart.Before((e.TimeEnd))
}
type EventTagParams struct {
Name string
Locked bool
}
// EventRepository is implemented by ...
type EventService interface {
CreateEvent(ctx context.Context, reqID uuid.UUID, eventParams WriteEventParams) (*Event, error)
UpdateEvent(ctx context.Context, reqID uuid.UUID, eventID uuid.UUID, eventParams WriteEventParams) (*Event, error)
AddEventTag(ctx context.Context, reqID uuid.UUID, eventID uuid.UUID, tagName string, locked bool) error
DeleteEvent(ctx context.Context, reqID uuid.UUID, eventID uuid.UUID) error
// DeleteTagInEvent delete a tag in that Event
DeleteEventTag(ctx context.Context, reqID uuid.UUID, eventID uuid.UUID, tagName string) error
UpsertMeEventSchedule(ctx context.Context, reqID uuid.UUID, eventID uuid.UUID, schedule ScheduleStatus) error
GetEvent(ctx context.Context, eventID uuid.UUID) (*Event, error)
GetEvents(ctx context.Context, reqID uuid.UUID, expr filters.Expr) ([]*Event, error)
IsEventAdmins(ctx context.Context, reqID uuid.UUID, eventID uuid.UUID) bool
GetEventsWithGroup(ctx context.Context, reqID uuid.UUID, expr filters.Expr) ([]*Event, error)
// GetEventActivities(day int) ([]*Event, error)
}
type UpsertEventArgs struct {
WriteEventParams
CreatedBy uuid.UUID
}
type EventRepository interface {
CreateEvent(args UpsertEventArgs) (*Event, error)
UpdateEvent(eventID uuid.UUID, args UpsertEventArgs) (*Event, error)
AddEventTag(eventID uuid.UUID, params EventTagParams) error
DeleteEvent(eventID uuid.UUID) error
DeleteEventTag(eventID uuid.UUID, tagName string, deleteLocked bool) error
UpsertEventSchedule(eventID, userID uuid.UUID, scheduleStatus ScheduleStatus) error
GetEvent(eventID uuid.UUID) (*Event, error)
GetAllEvents(expr filters.Expr) ([]*Event, error)
}