Skip to content

Commit 0d6eba4

Browse files
committed
Update
1 parent da0b2e6 commit 0d6eba4

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

routers/web/shared/starlists/star_lists.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
package starlists
22

3-
import "code.gitea.io/gitea/services/context"
3+
import (
4+
repo_model "code.gitea.io/gitea/models/repo"
5+
"code.gitea.io/gitea/modules/log"
6+
"code.gitea.io/gitea/modules/web"
7+
"code.gitea.io/gitea/services/context"
8+
"code.gitea.io/gitea/services/forms"
9+
)
410

511
func GetByName(ctx *context.Context) {
612

713
}
814

915
func Create(ctx *context.Context) {
16+
form := web.GetForm(ctx).(*forms.StarListForm)
1017

18+
log.Info("form: %+v", *form)
19+
20+
err := repo_model.InsertStarList(ctx, &repo_model.StarList{
21+
UID: ctx.Doer.ID,
22+
Name: form.Name,
23+
Desc: form.Desc,
24+
})
25+
if err != nil {
26+
ctx.ServerError("InsertStarList", err)
27+
return
28+
}
29+
30+
ctx.Redirect(ctx.Doer.HomeLink() + "?tab=stars")
1131
}
1232

1333
func UpdateByName(ctx *context.Context) {

routers/web/web.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,11 +1613,11 @@ func registerRoutes(m *web.Router) {
16131613
m.Post("/action/{action:accept_transfer|reject_transfer}", reqSignIn, repo.ActionTransfer)
16141614
}, optSignIn, context.RepoAssignment)
16151615

1616-
m.Group("/stars/{username}/lists", func() {
1617-
m.Post("", starlists.Create) // 创建一个新的list
1618-
m.Get("/{listname}", starlists.GetByName) // 获取当前listname的所有repo
1619-
m.Post("/{listname}", starlists.UpdateByName) // 更新当前listname的所有repo
1620-
m.Delete("/{listname}", starlists.DeleteByName) // 删除当前listname
1616+
m.Group("/stars/lists", func() {
1617+
m.Post("", web.Bind(forms.StarListForm{}), starlists.Create) // 创建一个新的list
1618+
m.Get("/{listname}", starlists.GetByName) // 获取当前listname的所有repo
1619+
m.Post("/{listname}", starlists.UpdateByName) // 更新当前listname的所有repo
1620+
m.Delete("/{listname}", starlists.DeleteByName) // 删除当前listname
16211621
})
16221622

16231623
m.Group("/{username}/{reponame}", func() {

services/forms/star_list_form.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package forms
2+
3+
import (
4+
"net/http"
5+
6+
"code.gitea.io/gitea/modules/web/middleware"
7+
"code.gitea.io/gitea/services/context"
8+
"gitea.com/go-chi/binding"
9+
)
10+
11+
type StarListForm struct {
12+
Action string `binding:"Required"`
13+
ID int64 `binding:"OmitEmpty"`
14+
UID int64 `binding:"Required"`
15+
Name string `binding:"Required;MaxSize(50)"`
16+
Desc string `binding:"OmitEmpty"`
17+
}
18+
19+
func (s *StarListForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
20+
ctx := context.GetValidateContext(req)
21+
return middleware.Validate(errs, ctx.Data, s, ctx.Locale)
22+
}

0 commit comments

Comments
 (0)