File tree Expand file tree Collapse file tree 3 files changed +48
-6
lines changed Expand file tree Collapse file tree 3 files changed +48
-6
lines changed Original file line number Diff line number Diff line change 11package 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
511func GetByName (ctx * context.Context ) {
612
713}
814
915func 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
1333func UpdateByName (ctx * context.Context ) {
Original file line number Diff line number Diff 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 () {
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments