正在显示
14 个修改的文件
包含
178 行增加
和
76 行删除
@@ -4,7 +4,7 @@ model: | @@ -4,7 +4,7 @@ model: | ||
4 | 4 | ||
5 | .PHONY: api | 5 | .PHONY: api |
6 | api: | 6 | api: |
7 | - goctl api go -api .\cmd\discuss\mini\dsl\core.api -dir cmd/discuss/api -style go_zero | 7 | + goctl api go -api .\cmd\discuss\api\dsl\core.api -dir cmd/discuss/api -style go_zero |
8 | 8 | ||
9 | .PHONY: swagger | 9 | .PHONY: swagger |
10 | swagger: | 10 | swagger: |
@@ -46,7 +46,6 @@ func main() { | @@ -46,7 +46,6 @@ func main() { | ||
46 | 46 | ||
47 | }) | 47 | }) |
48 | opts = append(opts, opt) | 48 | opts = append(opts, opt) |
49 | - | ||
50 | server := rest.MustNewServer(c.RestConf, opts...) | 49 | server := rest.MustNewServer(c.RestConf, opts...) |
51 | defer server.Stop() | 50 | defer server.Stop() |
52 | 51 |
@@ -15,41 +15,65 @@ | @@ -15,41 +15,65 @@ | ||
15 | "application/json" | 15 | "application/json" |
16 | ], | 16 | ], |
17 | "paths": { | 17 | "paths": { |
18 | - "v1/health": { | 18 | + "v1/mini/comment": { |
19 | "get": { | 19 | "get": { |
20 | - "summary": "健康", | ||
21 | - "operationId": "miniHealth", | 20 | + "summary": "小程序评论", |
21 | + "operationId": "miniComment", | ||
22 | "responses": { | 22 | "responses": { |
23 | "200": { | 23 | "200": { |
24 | "description": "A successful response.", | 24 | "description": "A successful response.", |
25 | "schema": { | 25 | "schema": { |
26 | - "$ref": "#/definitions/MiniHealthResposne" | 26 | + "$ref": "#/definitions/CommentResposne" |
27 | } | 27 | } |
28 | } | 28 | } |
29 | }, | 29 | }, |
30 | "requestBody": {}, | 30 | "requestBody": {}, |
31 | "tags": [ | 31 | "tags": [ |
32 | - "tool" | 32 | + "comment" |
33 | + ] | ||
34 | + } | ||
35 | + }, | ||
36 | + "v1/system/comment": { | ||
37 | + "get": { | ||
38 | + "summary": "系统评论", | ||
39 | + "operationId": "systemComment", | ||
40 | + "responses": { | ||
41 | + "200": { | ||
42 | + "description": "A successful response.", | ||
43 | + "schema": { | ||
44 | + "$ref": "#/definitions/CommentResposne" | ||
45 | + } | ||
46 | + } | ||
47 | + }, | ||
48 | + "requestBody": {}, | ||
49 | + "tags": [ | ||
50 | + "comment" | ||
33 | ] | 51 | ] |
34 | } | 52 | } |
35 | } | 53 | } |
36 | }, | 54 | }, |
37 | "definitions": { | 55 | "definitions": { |
38 | - "MiniHealthRequest": { | 56 | + "Comment": { |
57 | + "type": "object", | ||
58 | + "title": "Comment" | ||
59 | + }, | ||
60 | + "CommentRequest": { | ||
39 | "type": "object", | 61 | "type": "object", |
40 | - "title": "MiniHealthRequest" | 62 | + "title": "CommentRequest" |
41 | }, | 63 | }, |
42 | - "MiniHealthResposne": { | 64 | + "CommentResposne": { |
43 | "type": "object", | 65 | "type": "object", |
44 | "properties": { | 66 | "properties": { |
45 | - "ok": { | ||
46 | - "type": "boolean", | ||
47 | - "format": "boolean" | 67 | + "list": { |
68 | + "type": "array", | ||
69 | + "items": { | ||
70 | + "$ref": "#/definitions/Comment" | ||
71 | + } | ||
48 | } | 72 | } |
49 | }, | 73 | }, |
50 | - "title": "MiniHealthResposne", | 74 | + "title": "CommentResposne", |
51 | "required": [ | 75 | "required": [ |
52 | - "ok" | 76 | + "list" |
53 | ] | 77 | ] |
54 | } | 78 | } |
55 | }, | 79 | }, |
@@ -3,26 +3,46 @@ syntax = "v1" | @@ -3,26 +3,46 @@ syntax = "v1" | ||
3 | info( | 3 | info( |
4 | title: "天联鹰蜓" | 4 | title: "天联鹰蜓" |
5 | desc: "天联鹰蜓" | 5 | desc: "天联鹰蜓" |
6 | - author: "小火箭" | 6 | + author: "email" |
7 | email: "email" | 7 | email: "email" |
8 | version: "v1" | 8 | version: "v1" |
9 | ) | 9 | ) |
10 | 10 | ||
11 | + | ||
12 | +// 小程序接口 | ||
11 | @server( | 13 | @server( |
12 | prefix: v1 | 14 | prefix: v1 |
13 | - group: tool | 15 | + group: comment |
16 | + jwt: MiniAuth | ||
14 | ) | 17 | ) |
15 | service Core { | 18 | service Core { |
16 | - @doc "健康" | ||
17 | - @handler miniHealth | ||
18 | - get /health (MiniHealthRequest) returns (MiniHealthResposne) | 19 | + @doc "小程序评论" |
20 | + @handler miniComment | ||
21 | + get /mini/comment (CommentRequest) returns (CommentResposne) | ||
22 | +} | ||
23 | + | ||
24 | + | ||
25 | +// 后台接口 | ||
26 | +@server( | ||
27 | + prefix: v1 | ||
28 | + group: comment | ||
29 | + jwt: SystemAuth | ||
30 | +) | ||
31 | +service Core { | ||
32 | + @doc "系统评论" | ||
33 | + @handler systemComment | ||
34 | + get /system/comment (CommentRequest) returns (CommentResposne) | ||
19 | } | 35 | } |
20 | 36 | ||
21 | type( | 37 | type( |
22 | - MiniHealthRequest struct{ | 38 | + CommentRequest struct{ |
23 | 39 | ||
24 | } | 40 | } |
25 | - MiniHealthResposne struct{ | ||
26 | - Ok bool `json:"ok"` | 41 | + CommentResposne struct{ |
42 | + List []Comment `json:"list"` | ||
43 | + } | ||
44 | + | ||
45 | + Comment struct{ | ||
46 | + | ||
27 | } | 47 | } |
28 | ) | 48 | ) |
@@ -10,9 +10,13 @@ Log: | @@ -10,9 +10,13 @@ Log: | ||
10 | MaxSize: 1 # 2MB | 10 | MaxSize: 1 # 2MB |
11 | TimeFormat: 2006-01-02 15:04:05.000 | 11 | TimeFormat: 2006-01-02 15:04:05.000 |
12 | 12 | ||
13 | -JwtAuth: | ||
14 | - AccessSecret: digital-platform | ||
15 | - Expire: 360000 | 13 | +SystemAuth: |
14 | + AccessSecret: discuss-secret | ||
15 | + AccessExpire: 360000 | ||
16 | + | ||
17 | +MiniAuth: | ||
18 | + AccessSecret: discuss-secret | ||
19 | + AccessExpire: 360000 | ||
16 | 20 | ||
17 | Redis: | 21 | Redis: |
18 | Host: 127.0.0.1:6379 | 22 | Host: 127.0.0.1:6379 |
1 | -package tool | 1 | +package comment |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
5 | "net/http" | 4 | "net/http" |
6 | 5 | ||
7 | "github.com/zeromicro/go-zero/rest/httpx" | 6 | "github.com/zeromicro/go-zero/rest/httpx" |
8 | - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/tool" | 7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment" |
9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
11 | ) | 10 | ) |
12 | 11 | ||
13 | -func MiniHealthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 12 | +func MiniCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
14 | return func(w http.ResponseWriter, r *http.Request) { | 13 | return func(w http.ResponseWriter, r *http.Request) { |
15 | - var req types.MiniHealthRequest | 14 | + var req types.CommentRequest |
16 | if err := httpx.Parse(r, &req); err != nil { | 15 | if err := httpx.Parse(r, &req); err != nil { |
17 | httpx.ErrorCtx(r.Context(), w, err) | 16 | httpx.ErrorCtx(r.Context(), w, err) |
18 | return | 17 | return |
19 | } | 18 | } |
20 | 19 | ||
21 | - l := tool.NewMiniHealthLogic(r.Context(), svcCtx) | ||
22 | - resp, err := l.MiniHealth(&req) | ||
23 | - result.HttpResult(r, w, resp, err) | 20 | + l := comment.NewMiniCommentLogic(r.Context(), svcCtx) |
21 | + resp, err := l.MiniComment(&req) | ||
22 | + if err != nil { | ||
23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
24 | + } else { | ||
25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
26 | + } | ||
24 | } | 27 | } |
25 | } | 28 | } |
1 | +package comment | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
10 | +) | ||
11 | + | ||
12 | +func SystemCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
14 | + var req types.CommentRequest | ||
15 | + if err := httpx.Parse(r, &req); err != nil { | ||
16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
17 | + return | ||
18 | + } | ||
19 | + | ||
20 | + l := comment.NewSystemCommentLogic(r.Context(), svcCtx) | ||
21 | + resp, err := l.SystemComment(&req) | ||
22 | + if err != nil { | ||
23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
24 | + } else { | ||
25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
26 | + } | ||
27 | + } | ||
28 | +} |
@@ -4,7 +4,7 @@ package handler | @@ -4,7 +4,7 @@ package handler | ||
4 | import ( | 4 | import ( |
5 | "net/http" | 5 | "net/http" |
6 | 6 | ||
7 | - tool "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/tool" | 7 | + comment "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/handler/comment" |
8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
9 | 9 | ||
10 | "github.com/zeromicro/go-zero/rest" | 10 | "github.com/zeromicro/go-zero/rest" |
@@ -15,10 +15,23 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -15,10 +15,23 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
15 | []rest.Route{ | 15 | []rest.Route{ |
16 | { | 16 | { |
17 | Method: http.MethodGet, | 17 | Method: http.MethodGet, |
18 | - Path: "/health", | ||
19 | - Handler: tool.MiniHealthHandler(serverCtx), | 18 | + Path: "/mini/comment", |
19 | + Handler: comment.MiniCommentHandler(serverCtx), | ||
20 | }, | 20 | }, |
21 | }, | 21 | }, |
22 | + rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), | ||
23 | + rest.WithPrefix("/v1"), | ||
24 | + ) | ||
25 | + | ||
26 | + server.AddRoutes( | ||
27 | + []rest.Route{ | ||
28 | + { | ||
29 | + Method: http.MethodGet, | ||
30 | + Path: "/system/comment", | ||
31 | + Handler: comment.SystemCommentHandler(serverCtx), | ||
32 | + }, | ||
33 | + }, | ||
34 | + rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), | ||
22 | rest.WithPrefix("/v1"), | 35 | rest.WithPrefix("/v1"), |
23 | ) | 36 | ) |
24 | } | 37 | } |
1 | -package tool | 1 | +package comment |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
6 | - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
7 | 5 | ||
8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
@@ -11,31 +9,22 @@ import ( | @@ -11,31 +9,22 @@ import ( | ||
11 | "github.com/zeromicro/go-zero/core/logx" | 9 | "github.com/zeromicro/go-zero/core/logx" |
12 | ) | 10 | ) |
13 | 11 | ||
14 | -type MiniHealthLogic struct { | 12 | +type MiniCommentLogic struct { |
15 | logx.Logger | 13 | logx.Logger |
16 | ctx context.Context | 14 | ctx context.Context |
17 | svcCtx *svc.ServiceContext | 15 | svcCtx *svc.ServiceContext |
18 | } | 16 | } |
19 | 17 | ||
20 | -func NewMiniHealthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniHealthLogic { | ||
21 | - return &MiniHealthLogic{ | 18 | +func NewMiniCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniCommentLogic { |
19 | + return &MiniCommentLogic{ | ||
22 | Logger: logx.WithContext(ctx), | 20 | Logger: logx.WithContext(ctx), |
23 | ctx: ctx, | 21 | ctx: ctx, |
24 | svcCtx: svcCtx, | 22 | svcCtx: svcCtx, |
25 | } | 23 | } |
26 | } | 24 | } |
27 | 25 | ||
28 | -func (l *MiniHealthLogic) MiniHealth(req *types.MiniHealthRequest) (resp *types.MiniHealthResposne, err error) { | ||
29 | - // 普通查询 | ||
30 | - var conn = l.svcCtx.DefaultDBConn() | ||
31 | - l.svcCtx.CommentRepository.FindOne(l.ctx, conn, 0) | 26 | +func (l *MiniCommentLogic) MiniComment(req *types.CommentRequest) (resp *types.CommentResposne, err error) { |
27 | + // todo: add your logic here and delete this line | ||
32 | 28 | ||
33 | - // 事务查询 | ||
34 | - if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
35 | - l.svcCtx.CommentRepository.FindOne(ctx, l.svcCtx.DefaultDBConn(), 0) | ||
36 | - return nil | ||
37 | - }, true); err != nil { | ||
38 | - return nil, xerr.NewErrMsgErr("健康检查失败", err) | ||
39 | - } | ||
40 | return | 29 | return |
41 | } | 30 | } |
1 | +package comment | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
8 | + | ||
9 | + "github.com/zeromicro/go-zero/core/logx" | ||
10 | +) | ||
11 | + | ||
12 | +type SystemCommentLogic struct { | ||
13 | + logx.Logger | ||
14 | + ctx context.Context | ||
15 | + svcCtx *svc.ServiceContext | ||
16 | +} | ||
17 | + | ||
18 | +func NewSystemCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemCommentLogic { | ||
19 | + return &SystemCommentLogic{ | ||
20 | + Logger: logx.WithContext(ctx), | ||
21 | + ctx: ctx, | ||
22 | + svcCtx: svcCtx, | ||
23 | + } | ||
24 | +} | ||
25 | + | ||
26 | +func (l *SystemCommentLogic) SystemComment(req *types.CommentRequest) (resp *types.CommentResposne, err error) { | ||
27 | + // todo: add your logic here and delete this line | ||
28 | + | ||
29 | + return | ||
30 | +} |
1 | // Code generated by goctl. DO NOT EDIT. | 1 | // Code generated by goctl. DO NOT EDIT. |
2 | package types | 2 | package types |
3 | 3 | ||
4 | -type MiniHealthRequest struct { | 4 | +type CommentRequest struct { |
5 | } | 5 | } |
6 | 6 | ||
7 | -type MiniHealthResposne struct { | ||
8 | - Ok bool `json:"ok"` | 7 | +type CommentResposne struct { |
8 | + List []Comment `json:"list"` | ||
9 | +} | ||
10 | + | ||
11 | +type Comment struct { | ||
12 | + Id int64 `json:"id"` | ||
13 | + Content string `json:"content"` | ||
9 | } | 14 | } |
@@ -2,25 +2,13 @@ package config | @@ -2,25 +2,13 @@ package config | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "github.com/zeromicro/go-zero/core/stores/cache" | 4 | "github.com/zeromicro/go-zero/core/stores/cache" |
5 | - "github.com/zeromicro/go-zero/zrpc" | ||
6 | - "time" | ||
7 | ) | 5 | ) |
8 | 6 | ||
9 | -type JWT struct { | ||
10 | - Secret string `json:",optional"` | ||
11 | - Expires time.Duration `json:",optional"` | ||
12 | -} | ||
13 | -type JwtAuth struct { | 7 | +type Auth struct { |
14 | AccessSecret string | 8 | AccessSecret string |
15 | - Expire int64 | 9 | + AccessExpire int64 |
16 | } | 10 | } |
17 | type Config struct { | 11 | type Config struct { |
18 | - JwtAuth JwtAuth `json:",optional"` | ||
19 | - UserRpc zrpc.RpcClientConf `json:",optional"` | ||
20 | - AuthRpc zrpc.RpcClientConf `json:",optional"` | ||
21 | - PostRpc zrpc.RpcClientConf `json:",optional"` | ||
22 | - CommentRpc zrpc.RpcClientConf `json:",optional"` | ||
23 | - JWT JWT `json:",optional"` | ||
24 | DB struct { | 12 | DB struct { |
25 | DataSource string | 13 | DataSource string |
26 | } `json:",optional"` | 14 | } `json:",optional"` |
@@ -28,10 +16,7 @@ type Config struct { | @@ -28,10 +16,7 @@ type Config struct { | ||
28 | DTM DTM `json:",optional"` | 16 | DTM DTM `json:",optional"` |
29 | Sms Sms `json:",optional"` | 17 | Sms Sms `json:",optional"` |
30 | Oss Oss `json:",optional"` | 18 | Oss Oss `json:",optional"` |
31 | - Wechat Wechat `json:",optional"` // 学员端微信 | ||
32 | - CoachClient Wechat `json:",optional"` // 教练端微信 | ||
33 | - OfficialAccount Wechat `json:",optional"` | ||
34 | - ThirdWechatApps []Wechat `json:",optional"` | 19 | + Wechat Wechat `json:",optional"` |
35 | } | 20 | } |
36 | 21 | ||
37 | type DTM struct { | 22 | type DTM struct { |
-
请 注册 或 登录 后发表评论