Skip to content

Commit 9c4937f

Browse files
committed
some renames
1 parent d746668 commit 9c4937f

File tree

9 files changed

+194
-103
lines changed

9 files changed

+194
-103
lines changed

models/project/column.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ const (
3434
CardTypeImagesAndText
3535
)
3636

37+
func (p CardType) ToString() string {
38+
switch p {
39+
case CardTypeImagesAndText:
40+
return "ImagesAndText"
41+
case CardTypeTextOnly:
42+
fallthrough
43+
default:
44+
return "TextOnly"
45+
}
46+
}
47+
48+
func ToCardType(s string) CardType {
49+
switch s {
50+
case "ImagesAndText":
51+
return CardTypeImagesAndText
52+
case "TextOnly":
53+
fallthrough
54+
default:
55+
return CardTypeTextOnly
56+
}
57+
}
58+
3759
// ColumnColorPattern is a regexp witch can validate ColumnColor
3860
var ColumnColorPattern = regexp.MustCompile("^#[0-9a-fA-F]{6}$")
3961

models/project/template.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ const (
2525
TemplateTypeBugTriage
2626
)
2727

28+
func (p TemplateType) ToString() string {
29+
switch p {
30+
case TemplateTypeBasicKanban:
31+
return "BasicKanban"
32+
case TemplateTypeBugTriage:
33+
return "BugTriage"
34+
case TemplateTypeNone:
35+
fallthrough
36+
default:
37+
return ""
38+
}
39+
}
40+
41+
// ToTemplateType converts a string to a TemplateType
42+
func ToTemplateType(s string) TemplateType {
43+
switch s {
44+
case "BasicKanban":
45+
return TemplateTypeBasicKanban
46+
case "BugTriage":
47+
return TemplateTypeBugTriage
48+
default:
49+
return TemplateTypeNone
50+
}
51+
}
52+
2853
// GetTemplateConfigs retrieves the template configs of configurations project columns could have
2954
func GetTemplateConfigs() []TemplateConfig {
3055
return []TemplateConfig{

modules/structs/project.go

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,53 @@ package structs
55

66
import "time"
77

8+
// NewProjectOption options when creating a new project
89
// swagger:model
9-
type NewProjectPayload struct {
10+
type NewProjectOption struct {
1011
// required:true
11-
Title string `json:"title" binding:"Required"`
12+
// Keep compatibility with Github API to use "name" instead of "title"
13+
Name string `json:"name" binding:"Required"`
1214
// required:true
13-
BoardType uint8 `json:"board_type"`
15+
// enum: , BasicKanban, BugTriage
16+
// Note: this is the same as TemplateType in models/project/template.go
17+
TemplateType string `json:"template_type"`
1418
// required:true
15-
CardType uint8 `json:"card_type"`
16-
Description string `json:"description"`
19+
// enum: TextOnly, ImagesAndText
20+
CardType string `json:"card_type"`
21+
// Keep compatibility with Github API to use "body" instead of "description"
22+
Body string `json:"body"`
1723
}
1824

25+
// UpdateProjectOption options when updating a project
1926
// swagger:model
20-
type UpdateProjectPayload struct {
27+
type UpdateProjectOption struct {
2128
// required:true
22-
Title string `json:"title" binding:"Required"`
23-
Description string `json:"description"`
29+
// Keep compatibility with Github API to use "name" instead of "title"
30+
Name string `json:"name" binding:"Required"`
31+
// Keep compatibility with Github API to use "body" instead of "description"
32+
Body string `json:"body"`
2433
}
2534

35+
// Project represents a project
2636
// swagger:model
2737
type Project struct {
28-
ID int64 `json:"id"`
29-
Title string `json:"title"`
30-
Description string `json:"description"`
31-
TemplateType uint8 `json:"board_type"`
32-
IsClosed bool `json:"is_closed"`
38+
ID int64 `json:"id"`
39+
// Keep compatibility with Github API to use "name" instead of "title"
40+
Name string `json:"name"`
41+
// Keep compatibility with Github API to use "body" instead of "description"
42+
Body string `json:"body"`
43+
// required:true
44+
// enum: , BasicKanban, BugTriage
45+
// Note: this is the same as TemplateType in models/project/template.go
46+
TemplateType string `json:"template_type"`
47+
// enum: open, closed
48+
State string `json:"state"`
3349
// swagger:strfmt date-time
3450
Created time.Time `json:"created_at"`
3551
// swagger:strfmt date-time
3652
Updated time.Time `json:"updated_at"`
3753
// swagger:strfmt date-time
38-
Closed time.Time `json:"closed_at"`
54+
Closed *time.Time `json:"closed_at"`
3955

4056
Repo *RepositoryMeta `json:"repository"`
4157
Creator *User `json:"creator"`

routers/api/v1/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ func Routes() *web.Router {
11651165

11661166
m.Group("/projects", func() {
11671167
m.Get("", projects.ListUserProjects)
1168-
m.Post("", bind(api.NewProjectPayload{}), projects.CreateUserProject)
1168+
m.Post("", bind(api.NewProjectOption{}), projects.CreateUserProject)
11691169
})
11701170
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryUser), reqToken())
11711171

@@ -1475,7 +1475,7 @@ func Routes() *web.Router {
14751475
m.Methods("HEAD,GET", "/{ball_type:tarball|zipball|bundle}/*", reqRepoReader(unit.TypeCode), repo.DownloadArchive)
14761476

14771477
m.Group("/projects", func() {
1478-
m.Post("", bind(api.NewProjectPayload{}), projects.CreateRepoProject)
1478+
m.Post("", bind(api.NewProjectOption{}), projects.CreateRepoProject)
14791479
})
14801480
}, repoAssignment(), checkTokenPublicOnly())
14811481
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryRepository))
@@ -1699,7 +1699,7 @@ func Routes() *web.Router {
16991699
}, reqToken(), reqOrgOwnership())
17001700

17011701
m.Group("/projects", func() {
1702-
m.Post("", bind(api.NewProjectPayload{}), projects.CreateOrgProject)
1702+
m.Post("", bind(api.NewProjectOption{}), projects.CreateOrgProject)
17031703
})
17041704
}, tokenRequiresScopes(auth_model.AccessTokenScopeCategoryOrganization), orgAssignment(true), checkTokenPublicOnly())
17051705
m.Group("/teams/{teamid}", func() {

routers/api/v1/projects/project.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ import (
1616
)
1717

1818
func innerCreateProject(ctx *context.APIContext, projectType project_model.Type) {
19-
form := web.GetForm(ctx).(*api.NewProjectPayload)
19+
form := web.GetForm(ctx).(*api.NewProjectOption)
2020
project := &project_model.Project{
21-
RepoID: 0,
22-
OwnerID: ctx.Doer.ID,
23-
Title: form.Title,
24-
Description: form.Description,
21+
Title: form.Name,
22+
Description: form.Body,
2523
CreatorID: ctx.Doer.ID,
26-
TemplateType: project_model.TemplateType(form.BoardType),
24+
TemplateType: project_model.ToTemplateType(form.TemplateType),
2725
Type: projectType,
2826
}
2927

30-
if ctx.ContextUser != nil {
31-
project.OwnerID = ctx.ContextUser.ID
28+
if ctx.ContextUser == nil {
29+
ctx.APIError(http.StatusForbidden, "Not authenticated")
30+
return
3231
}
32+
project.OwnerID = ctx.ContextUser.ID
3333

3434
if projectType == project_model.TypeRepository {
3535
project.RepoID = ctx.Repo.Repository.ID
@@ -67,7 +67,7 @@ func CreateUserProject(ctx *context.APIContext) {
6767
// - name: project
6868
// in: body
6969
// required: true
70-
// schema: { "$ref": "#/definitions/NewProjectPayload" }
70+
// schema: { "$ref": "#/definitions/NewProjectOption" }
7171
// responses:
7272
// "201":
7373
// "$ref": "#/responses/Project"
@@ -95,7 +95,7 @@ func CreateOrgProject(ctx *context.APIContext) {
9595
// - name: project
9696
// in: body
9797
// required: true
98-
// schema: { "$ref": "#/definitions/NewProjectPayload" }
98+
// schema: { "$ref": "#/definitions/NewProjectOption" }
9999
// responses:
100100
// "201":
101101
// "$ref": "#/responses/Project"
@@ -128,7 +128,7 @@ func CreateRepoProject(ctx *context.APIContext) {
128128
// - name: project
129129
// in: body
130130
// required: true
131-
// schema: { "$ref": "#/definitions/NewProjectPayload" }
131+
// schema: { "$ref": "#/definitions/NewProjectOption" }
132132
// responses:
133133
// "201":
134134
// "$ref": "#/responses/Project"
@@ -158,7 +158,7 @@ func GetProject(ctx *context.APIContext) {
158158
// "$ref": "#/responses/forbidden"
159159
// "404":
160160
// "$ref": "#/responses/notFound"
161-
project, err := project_model.GetProjectByID(ctx, ctx.FormInt64(":id"))
161+
project, err := project_model.GetProjectByID(ctx, ctx.FormInt64("id"))
162162
if err != nil {
163163
if project_model.IsErrProjectNotExist(err) {
164164
ctx.APIError(http.StatusNotFound, err)
@@ -193,15 +193,15 @@ func UpdateProject(ctx *context.APIContext) {
193193
// - name: project
194194
// in: body
195195
// required: true
196-
// schema: { "$ref": "#/definitions/UpdateProjectPayload" }
196+
// schema: { "$ref": "#/definitions/UpdateProjectOption" }
197197
// responses:
198198
// "200":
199199
// "$ref": "#/responses/Project"
200200
// "403":
201201
// "$ref": "#/responses/forbidden"
202202
// "404":
203203
// "$ref": "#/responses/notFound"
204-
form := web.GetForm(ctx).(*api.UpdateProjectPayload)
204+
form := web.GetForm(ctx).(*api.UpdateProjectOption)
205205
project, err := project_model.GetProjectByID(ctx, ctx.FormInt64("id"))
206206
if err != nil {
207207
if project_model.IsErrProjectNotExist(err) {
@@ -211,11 +211,11 @@ func UpdateProject(ctx *context.APIContext) {
211211
}
212212
return
213213
}
214-
if project.Title != form.Title {
215-
project.Title = form.Title
214+
if project.Title != form.Name {
215+
project.Title = form.Name
216216
}
217-
if project.Description != form.Description {
218-
project.Description = form.Description
217+
if project.Description != form.Body {
218+
project.Description = form.Body
219219
}
220220

221221
err = project_model.UpdateProject(ctx, project)
@@ -249,7 +249,7 @@ func DeleteProject(ctx *context.APIContext) {
249249
// "404":
250250
// "$ref": "#/responses/notFound"
251251

252-
if err := project_model.DeleteProjectByID(ctx, ctx.FormInt64(":id")); err != nil {
252+
if err := project_model.DeleteProjectByID(ctx, ctx.FormInt64("id")); err != nil {
253253
ctx.APIErrorInternal(err)
254254
return
255255
}

routers/api/v1/swagger/options.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,11 @@ type swaggerParameterBodies struct {
221221
UpdateVariableOption api.UpdateVariableOption
222222

223223
// in:body
224-
NewProjectPayload api.NewProjectPayload
224+
LockIssueOption api.LockIssueOption
225225

226226
// in:body
227-
UpdateProjectPayload api.UpdateProjectPayload
228-
LockIssueOption api.LockIssueOption
227+
NewProjectOption api.NewProjectOption
228+
229+
// in:body
230+
UpdateProjectOption api.UpdateProjectOption
229231
}

services/convert/project.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ import (
88

99
project_model "code.gitea.io/gitea/models/project"
1010
api "code.gitea.io/gitea/modules/structs"
11+
"code.gitea.io/gitea/modules/util"
1112
)
1213

1314
func ToAPIProject(ctx context.Context, project *project_model.Project) (*api.Project, error) {
1415
apiProject := &api.Project{
15-
Title: project.Title,
16-
Description: project.Description,
17-
TemplateType: uint8(project.TemplateType),
18-
IsClosed: project.IsClosed,
16+
Name: project.Title,
17+
Body: project.Description,
18+
TemplateType: project.TemplateType.ToString(),
19+
State: util.Iif(project.IsClosed, "closed", "open"),
1920
Created: project.CreatedUnix.AsTime(),
2021
Updated: project.UpdatedUnix.AsTime(),
21-
Closed: project.ClosedDateUnix.AsTime(),
22+
}
23+
if !project.ClosedDateUnix.IsZero() {
24+
tm := project.ClosedDateUnix.AsTime()
25+
apiProject.Closed = &tm
2226
}
2327

2428
if err := project.LoadRepo(ctx); err != nil {

0 commit comments

Comments
 (0)