@@ -24,8 +24,8 @@ import (
24
24
// abstracted for ease of change later on.
25
25
type Project database.Project
26
26
27
- // ProjectVersion is the JSON representation of a Coder project version.
28
- type ProjectVersion struct {
27
+ // ProjectHistory is the JSON representation of Coder project version history .
28
+ type ProjectHistory struct {
29
29
ID uuid.UUID `json:"id"`
30
30
ProjectID uuid.UUID `json:"project_id"`
31
31
CreatedAt time.Time `json:"created_at"`
@@ -42,7 +42,6 @@ type CreateProjectRequest struct {
42
42
43
43
// CreateProjectVersionRequest enables callers to create a new Project Version.
44
44
type CreateProjectVersionRequest struct {
45
- Name string `json:"name,omitempty" validate:"username"`
46
45
StorageMethod database.ProjectStorageMethod `json:"storage_method" validate:"oneof=inline-archive,required"`
47
46
StorageSource []byte `json:"storage_source" validate:"max=1048576,required"`
48
47
}
@@ -51,7 +50,7 @@ type projects struct {
51
50
Database database.Store
52
51
}
53
52
54
- // allProjects lists all projects across organizations for a user .
53
+ // Lists all projects the authenticated user has access to .
55
54
func (p * projects ) allProjects (rw http.ResponseWriter , r * http.Request ) {
56
55
apiKey := httpmw .APIKey (r )
57
56
organizations , err := p .Database .GetOrganizationsByUserID (r .Context (), apiKey .UserID )
@@ -79,7 +78,7 @@ func (p *projects) allProjects(rw http.ResponseWriter, r *http.Request) {
79
78
render .JSON (rw , r , projects )
80
79
}
81
80
82
- // allProjectsForOrganization lists all projects for a specific organization.
81
+ // Lists all projects in an organization.
83
82
func (p * projects ) allProjectsForOrganization (rw http.ResponseWriter , r * http.Request ) {
84
83
organization := httpmw .OrganizationParam (r )
85
84
projects , err := p .Database .GetProjectsByOrganizationIDs (r .Context (), []string {organization .ID })
@@ -96,7 +95,7 @@ func (p *projects) allProjectsForOrganization(rw http.ResponseWriter, r *http.Re
96
95
render .JSON (rw , r , projects )
97
96
}
98
97
99
- // createProject makes a new project in an organization.
98
+ // Creates a new project in an organization.
100
99
func (p * projects ) createProject (rw http.ResponseWriter , r * http.Request ) {
101
100
var createProject CreateProjectRequest
102
101
if ! httpapi .Read (rw , r , & createProject ) {
@@ -142,16 +141,16 @@ func (p *projects) createProject(rw http.ResponseWriter, r *http.Request) {
142
141
render .JSON (rw , r , project )
143
142
}
144
143
145
- // project returns a single project parsed from the URL path .
144
+ // Returns a single project.
146
145
func (* projects ) project (rw http.ResponseWriter , r * http.Request ) {
147
146
project := httpmw .ProjectParam (r )
148
147
149
148
render .Status (r , http .StatusOK )
150
149
render .JSON (rw , r , project )
151
150
}
152
151
153
- // projectVersions lists versions for a single project.
154
- func (p * projects ) projectVersions (rw http.ResponseWriter , r * http.Request ) {
152
+ // Lists history for a single project.
153
+ func (p * projects ) allProjectHistory (rw http.ResponseWriter , r * http.Request ) {
155
154
project := httpmw .ProjectParam (r )
156
155
157
156
history , err := p .Database .GetProjectHistoryByProjectID (r .Context (), project .ID )
@@ -164,15 +163,18 @@ func (p *projects) projectVersions(rw http.ResponseWriter, r *http.Request) {
164
163
})
165
164
return
166
165
}
167
- versions := make ([]ProjectVersion , 0 )
166
+ apiHistory := make ([]ProjectHistory , 0 )
168
167
for _ , version := range history {
169
- versions = append (versions , convertProjectHistory (version ))
168
+ apiHistory = append (apiHistory , convertProjectHistory (version ))
170
169
}
171
170
render .Status (r , http .StatusOK )
172
- render .JSON (rw , r , versions )
171
+ render .JSON (rw , r , apiHistory )
173
172
}
174
173
175
- func (p * projects ) createProjectVersion (rw http.ResponseWriter , r * http.Request ) {
174
+ // Creates a new version of the project. An import job is queued to parse
175
+ // the storage method provided. Once completed, the import job will specify
176
+ // the version as latest.
177
+ func (p * projects ) createProjectHistory (rw http.ResponseWriter , r * http.Request ) {
176
178
var createProjectVersion CreateProjectVersionRequest
177
179
if ! httpapi .Read (rw , r , & createProjectVersion ) {
178
180
return
@@ -204,6 +206,8 @@ func (p *projects) createProjectVersion(rw http.ResponseWriter, r *http.Request)
204
206
Name : namesgenerator .GetRandomName (1 ),
205
207
StorageMethod : createProjectVersion .StorageMethod ,
206
208
StorageSource : createProjectVersion .StorageSource ,
209
+ // TODO: Make this do something!
210
+ ImportJobID : uuid .New (),
207
211
})
208
212
if err != nil {
209
213
httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
@@ -218,8 +222,8 @@ func (p *projects) createProjectVersion(rw http.ResponseWriter, r *http.Request)
218
222
render .JSON (rw , r , convertProjectHistory (history ))
219
223
}
220
224
221
- func convertProjectHistory (history database.ProjectHistory ) ProjectVersion {
222
- return ProjectVersion {
225
+ func convertProjectHistory (history database.ProjectHistory ) ProjectHistory {
226
+ return ProjectHistory {
223
227
ID : history .ID ,
224
228
ProjectID : history .ProjectID ,
225
229
CreatedAt : history .CreatedAt ,
0 commit comments