-
Notifications
You must be signed in to change notification settings - Fork 1
/
profiles.go
104 lines (88 loc) · 2.9 KB
/
profiles.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
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
// Sophrosyne
// Copyright (C) 2024 Mads R. Havmand
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package sophrosyne
import (
"context"
"time"
)
type Profile struct {
ID string
Name string
Checks []Check
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
}
func (p Profile) EntityType() string { return "Profile" }
func (p Profile) EntityID() string { return p.ID }
type ProfileService interface {
GetProfile(ctx context.Context, id string) (Profile, error)
GetProfileByName(ctx context.Context, name string) (Profile, error)
GetProfiles(ctx context.Context, cursor *DatabaseCursor) ([]Profile, error)
CreateProfile(ctx context.Context, profile CreateProfileRequest) (Profile, error)
UpdateProfile(ctx context.Context, profile UpdateProfileRequest) (Profile, error)
DeleteProfile(ctx context.Context, name string) error
}
type GetProfileRequest struct {
ID string `json:"id"`
Name string `json:"name" validate:"required_without=ID,excluded_with=ID"`
}
type GetProfileResponse struct {
Name string `json:"name"`
Checks []string `json:"checks"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
DeletedAt string `json:"deletedAt,omitempty"`
}
func (r *GetProfileResponse) FromProfile(p Profile) *GetProfileResponse {
var c []string
for _, entry := range p.Checks {
c = append(c, entry.Name)
}
r.Name = p.Name
r.Checks = c
r.CreatedAt = p.CreatedAt.Format(TimeFormatInResponse)
r.UpdatedAt = p.UpdatedAt.Format(TimeFormatInResponse)
if p.DeletedAt != nil {
r.DeletedAt = p.DeletedAt.Format(TimeFormatInResponse)
}
return r
}
type GetProfilesRequest struct {
Cursor string `json:"cursor"`
}
type GetProfilesResponse struct {
Profiles []GetProfileResponse `json:"profiles"`
Cursor string `json:"cursor"`
Total int `json:"total"`
}
type CreateProfileRequest struct {
Name string `json:"name" validate:"required"`
Checks []string `json:"checks"`
}
type CreateProfileResponse struct {
GetProfileResponse
}
type UpdateProfileRequest struct {
Name string `json:"name" validate:"required"`
Checks []string `json:"checks"`
}
type UpdateProfileResponse struct {
GetProfileResponse
}
type DeleteProfileRequest struct {
Name string `json:"name" validate:"required"`
}