Skip to content

Commit

Permalink
feat(admin, hitokoto): admin hitokoto management
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Sep 24, 2023
1 parent 525b366 commit 59265e1
Show file tree
Hide file tree
Showing 41 changed files with 715 additions and 264 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ linters-settings:
- name: unused-parameter
severity: warning
disabled: true
stylecheck:
checks:
- all
- '-ST1003'

linters:
disable-all: true
Expand Down
16 changes: 0 additions & 16 deletions api/admin/admin.go

This file was deleted.

24 changes: 0 additions & 24 deletions api/admin/v1/grant_authority.go

This file was deleted.

16 changes: 0 additions & 16 deletions api/admin/v1/modify_sentence.go

This file was deleted.

10 changes: 10 additions & 0 deletions api/hitokoto/adminV1/delete_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package adminV1

import "github.com/gogf/gf/v2/frame/g"

type DeleteListReq struct {
g.Meta `path:"/hitokoto" method:"DELETE" summary:"批量删除句子" tags:"句子"`
UUIDs []string `json:"uuids" dc:"句子 UUID" v:"required|length:1,100" in:"query"`
}

type DeleteListRes struct{}
14 changes: 14 additions & 0 deletions api/hitokoto/adminV1/get_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package adminV1

import (
"github.com/gogf/gf/v2/frame/g"
"github.com/hitokoto-osc/reviewer/internal/model"
)

// GetListReq 获取句子列表
type GetListReq struct {
g.Meta `path:"/hitokoto" method:"GET" summary:"获取句子列表" tags:"句子"`
model.GetHitokotoV1SchemaListInput
}

type GetListRes model.GetHitokotoV1SchemaListOutput
14 changes: 14 additions & 0 deletions api/hitokoto/adminV1/move.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package adminV1

import (
"github.com/gogf/gf/v2/frame/g"
"github.com/hitokoto-osc/reviewer/internal/consts"
)

type MoveSentenceReq struct {
g.Meta `path:"/hitokoto/:uuid" method:"POST" summary:"移动句子" tags:"句子"`
UUID string `json:"uuid" dc:"句子 UUID" v:"required|regex:^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$#请输入 UUID|UUID 非法" in:"path"` //nolint:lll
Target consts.HitokotoStatus `json:"target" dc:"目标状态" v:"required|in:pending,approved,rejected" in:"query"`
}

type MoveSentenceRes struct{}
15 changes: 15 additions & 0 deletions api/hitokoto/adminV1/update_one.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package adminV1

import (
"github.com/gogf/gf/v2/frame/g"
"github.com/hitokoto-osc/reviewer/internal/model"
)

type UpdateOneReq struct {
g.Meta `path:"/hitokoto/:uuid" method:"PUT" summary:"更新句子" tags:"句子"`
UUID string `json:"uuid" dc:"句子 UUID" v:"required|regex:^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$#请输入 UUID|UUID 非法" in:"path"` //nolint:lll
// 句子相关
model.DoHitokotoV1Update
}

type UpdateOneRes struct{}
8 changes: 8 additions & 0 deletions api/hitokoto/hitokoto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions api/hitokoto/v1/hitokoto.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ type GetHitokotoReq struct {
UUID string `json:"uuid" dc:"一言 UUID" v:"required|regex:^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$#请输入 UUID|UUID 非法" in:"path"` //nolint:lll
}

type GetHitokotoRes struct {
model.HitokotoV1Schema
}
type GetHitokotoRes model.HitokotoV1WithPoll
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ module github.com/hitokoto-osc/reviewer
go 1.20

require (
github.com/duke-git/lancet/v2 v2.2.6
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.4
github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.4
github.com/gogf/gf/v2 v2.5.4
github.com/google/uuid v1.3.1
github.com/meilisearch/meilisearch-go v0.25.1
github.com/rabbitmq/amqp091-go v1.8.1
github.com/samber/lo v1.38.1
golang.org/x/sync v0.3.0
)

Expand All @@ -34,14 +36,15 @@ require (
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/redis/go-redis/v9 v9.1.0 // indirect
github.com/redis/go-redis/v9 v9.2.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.50.0 // indirect
go.opentelemetry.io/otel v1.18.0 // indirect
go.opentelemetry.io/otel/metric v1.18.0 // indirect
go.opentelemetry.io/otel/sdk v1.18.0 // indirect
go.opentelemetry.io/otel/trace v1.18.0 // indirect
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
Expand Down
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/bsm/ginkgo/v2 v2.9.5 h1:rtVBYPs3+TC5iLUVOis1B9tjLTup7Cj5IfzosKtvTJ0=
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
Expand All @@ -14,6 +14,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/duke-git/lancet/v2 v2.2.6 h1:i0p8J85ujU1OslVIeEn+006OqVMdR7C+O7CHnMML+qI=
github.com/duke-git/lancet/v2 v2.2.6/go.mod h1:zGa2R4xswg6EG9I6WnyubDbFO/+A/RROxIbXcwryTsc=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
Expand Down Expand Up @@ -71,11 +73,13 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rabbitmq/amqp091-go v1.8.1 h1:RejT1SBUim5doqcL6s7iN6SBmsQqyTgXb1xMlH0h1hA=
github.com/rabbitmq/amqp091-go v1.8.1/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
github.com/redis/go-redis/v9 v9.1.0 h1:137FnGdk+EQdCbye1FW+qOEcY5S+SpY9T0NiuqvtfMY=
github.com/redis/go-redis/v9 v9.1.0/go.mod h1:urWj3He21Dj5k4TK1y59xH8Uj6ATueP8AH1cY3lZl4c=
github.com/redis/go-redis/v9 v9.2.0 h1:zwMdX0A4eVzse46YN18QhuDiM4uf3JmkOB4VZrdt5uI=
github.com/redis/go-redis/v9 v9.2.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand All @@ -100,6 +104,8 @@ go.opentelemetry.io/otel/trace v1.18.0/go.mod h1:T2+SGJGuYZY3bjj5rgh/hN7KIrlpWC5
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a h1:4iLhBPcpqFmylhnkbY3W0ONLUYYkDAW9xMFLfxgsvCw=
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
Expand Down
4 changes: 1 addition & 3 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (

"github.com/hitokoto-osc/reviewer/internal/consts"

"github.com/hitokoto-osc/reviewer/internal/controller/admin"

"github.com/hitokoto-osc/reviewer/internal/service"

"github.com/hitokoto-osc/reviewer/internal/controller/index"
Expand Down Expand Up @@ -104,7 +102,7 @@ var (
group.GET("/poll/mark", poll.NewV1().GetPollMarks) // 此路由无需验证审核员权限
group.Group("/admin", func(group *ghttp.RouterGroup) {
group.Middleware(service.Middleware().GuardV1(consts.UserRoleAdmin))
group.Bind(admin.NewV1())
group.Bind(hitokoto.NewAdminV1())
})
})
})
Expand Down
1 change: 1 addition & 0 deletions internal/consts/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
type PollStatus int

const (
PollStatusUnknown PollStatus = -1 // 未知,比如投票不存在
PollStatusNotOpen PollStatus = 0 // 未开放投票
PollStatusOpen PollStatus = 1 // 投票正常开放
PollStatusProcessing PollStatus = 2 // 处理中,停止投票
Expand Down
5 changes: 0 additions & 5 deletions internal/controller/admin/admin.go

This file was deleted.

15 changes: 0 additions & 15 deletions internal/controller/admin/admin_new.go

This file was deleted.

14 changes: 0 additions & 14 deletions internal/controller/admin/admin_v1_grant_user_authority.go

This file was deleted.

14 changes: 0 additions & 14 deletions internal/controller/admin/admin_v1_modify_sentence.go

This file was deleted.

20 changes: 20 additions & 0 deletions internal/controller/hitokoto/hitokoto_adminV1_delete_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package hitokoto

import (
"context"

"github.com/hitokoto-osc/reviewer/internal/service"

"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"

"github.com/hitokoto-osc/reviewer/api/hitokoto/adminV1"
)

func (c *ControllerAdminV1) DeleteList(ctx context.Context, req *adminV1.DeleteListReq) (res *adminV1.DeleteListRes, err error) {
err = service.Hitokoto().Delete(ctx, req.UUIDs)
if err != nil {
return nil, gerror.WrapCode(gcode.CodeInternalError, err)
}
return nil, nil
}
27 changes: 27 additions & 0 deletions internal/controller/hitokoto/hitokoto_adminV1_move_sentence.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package hitokoto

import (
"context"

"github.com/hitokoto-osc/reviewer/internal/service"

"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"

"github.com/hitokoto-osc/reviewer/api/hitokoto/adminV1"
)

func (c *ControllerAdminV1) MoveSentence(ctx context.Context, req *adminV1.MoveSentenceReq) (res *adminV1.MoveSentenceRes, err error) {
sentence, err := service.Hitokoto().GetHitokotoV1SchemaByUUID(ctx, req.UUID)
if err != nil {
return nil, gerror.WrapCode(gcode.CodeInternalError, err)
}
if sentence == nil {
return nil, gerror.NewCode(gcode.CodeNotFound, "未找到指定的句子")
}
err = service.Hitokoto().Move(ctx, sentence, req.Target)
if err != nil {
return nil, err
}
return nil, nil
}
27 changes: 27 additions & 0 deletions internal/controller/hitokoto/hitokoto_adminV1_update_one.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package hitokoto

import (
"context"

"github.com/hitokoto-osc/reviewer/internal/service"

"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"

"github.com/hitokoto-osc/reviewer/api/hitokoto/adminV1"
)

func (c *ControllerAdminV1) UpdateOne(ctx context.Context, req *adminV1.UpdateOneReq) (res *adminV1.UpdateOneRes, err error) {
sentence, err := service.Hitokoto().GetHitokotoV1SchemaByUUID(ctx, req.UUID)
if err != nil {
return nil, gerror.WrapCode(gcode.CodeInternalError, err)
}
if sentence == nil {
return nil, gerror.NewCode(gcode.CodeNotFound, "未找到指定的句子")
}
err = service.Hitokoto().UpdateByUUID(ctx, sentence, &req.DoHitokotoV1Update)
if err != nil {
return nil, err
}
return nil, nil
}
Loading

0 comments on commit 59265e1

Please sign in to comment.