-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.go
More file actions
74 lines (62 loc) · 2.1 KB
/
Copy pathproject.go
File metadata and controls
74 lines (62 loc) · 2.1 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
package deploykit
import (
"context"
"time"
)
// Project represents a deployable application project.
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// ProjectService manages projects.
type ProjectService interface {
// CreateProject creates a new project. The ID and timestamps are set
// by the implementation. On success, the created project is returned.
CreateProject(ctx context.Context, create ProjectCreate) (*Project, error)
// GetProject returns a project by ID.
// Returns ENOTFOUND if the project does not exist.
GetProject(ctx context.Context, id string) (*Project, error)
// ListProjects returns a filtered, paginated list of projects
// and the total matching count.
ListProjects(ctx context.Context, filter ProjectFilter) ([]*Project, int, error)
// UpdateProject applies a partial update to a project by ID.
// Returns the updated project. Returns ENOTFOUND if not found.
UpdateProject(ctx context.Context, id string, update ProjectUpdate) (*Project, error)
// DeleteProject permanently removes a project by ID.
// Returns ENOTFOUND if not found.
DeleteProject(ctx context.Context, id string) error
}
// ProjectCreate holds fields required to create a project.
type ProjectCreate struct {
Name string `json:"name"`
}
// Validate checks that all required fields are present.
func (c *ProjectCreate) Validate() error {
ve := NewValidationErrors()
if c.Name == "" {
ve.Add("name", "Name is required.")
}
return ve.Err()
}
// ProjectUpdate holds fields that can be updated on a project.
// Nil pointer fields are left unchanged.
type ProjectUpdate struct {
Name *string `json:"name"`
}
// Validate checks update fields.
func (u *ProjectUpdate) Validate() error {
ve := NewValidationErrors()
if u.Name != nil && *u.Name == "" {
ve.Add("name", "Name cannot be empty.")
}
return ve.Err()
}
// ProjectFilter controls filtering and pagination for listing projects.
type ProjectFilter struct {
Name *string
Offset int
Limit int
}