-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.go
134 lines (107 loc) · 3.16 KB
/
project.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
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
package coolify_sdk
import (
"errors"
"fmt"
"time"
client "github.com/marconneves/coolify-sdk-go/client"
)
type ProjectInstance struct {
client *client.Client
}
type Project struct {
ID int64 `json:"id"`
UUID string `json:"uuid"`
Name string `json:"name"`
Description *string `json:"description"`
Environments []Environment `json:"environments"`
}
type Environment struct {
ID int64 `json:"id"`
Name string `json:"name"`
Description *string `json:"description"`
ProjectId int64 `json:"project_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (t *ProjectInstance) List() (*[]Project, error) {
body, err := t.client.HttpRequest("projects", "GET")
if err != nil {
return nil, err
}
return client.DecodeResponse(body, &[]Project{})
}
func (t *ProjectInstance) Get(uuid string) (*Project, error) {
if uuid == "" {
return nil, errors.New("uuid is required")
}
body, err := t.client.HttpRequest(fmt.Sprintf("projects/%v", uuid), "GET")
if err != nil {
return nil, err
}
return client.DecodeResponse(body, &Project{})
}
type CreateProjectDTO struct {
Description *string `json:"description,omitempty"`
Name *string `json:"name,omitempty"`
}
type CreateProjectResponse struct {
UUID string `json:"uuid"`
}
func (t *ProjectInstance) Create(server *CreateProjectDTO) (*string, error) {
buf, err := client.EncodeRequest(server)
if err != nil {
return nil, err
}
body, err := t.client.HttpRequest("projects", "POST", *buf)
if err != nil {
return nil, err
}
response, err := client.DecodeResponse(body, &CreateProjectResponse{})
if err != nil {
return nil, err
}
return &response.UUID, nil
}
func (t *ProjectInstance) Delete(uuid string) error {
if uuid == "" {
return errors.New("uuid is required")
}
_, err := t.client.HttpRequest(fmt.Sprintf("projects/%v", uuid), "DELETE")
if err != nil {
return err
}
return nil
}
type UpdateProjectDTO struct {
Description *string `json:"description,omitempty"`
Name *string `json:"name,omitempty"`
}
func (t *ProjectInstance) Update(uuid string, server *UpdateProjectDTO) error {
if uuid == "" {
return errors.New("uuid is required")
}
buf, err := client.EncodeRequest(server)
if err != nil {
return err
}
_, err = t.client.HttpRequest(fmt.Sprintf("projects/%v", uuid), "PATCH", *buf)
return err
}
type EnvironmentData struct {
Id int64 `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
ProjectID int64 `json:"project_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (t *ProjectInstance) Environment(uuid string, environment string) (*EnvironmentData, error) {
if uuid == "" {
return nil, errors.New("uuid is required")
}
body, err := t.client.HttpRequest(fmt.Sprintf("projects/%v/%v/", uuid, environment), "GET")
if err != nil {
return nil, err
}
return client.DecodeResponse(body, &EnvironmentData{})
}