Browse Source
Merge remote-tracking branch 'origin/master'
Merge remote-tracking branch 'origin/master'
# Conflicts: # internal/cmd/cmd.go # internal/dao/internal/vote_option.go # internal/logic/logic.go # internal/model/do/vote_option.go # internal/model/entity/vote_option.gomaster
25 changed files with 211 additions and 102 deletions
-
58api/article/article.go
-
15api/hello/hello.go
-
12api/hello/v1/hello.go
-
2hack/config.yaml
-
6internal/cmd/cmd.go
-
60internal/controller/article/article.go
-
5internal/controller/hello/hello.go
-
15internal/controller/hello/hello_new.go
-
13internal/controller/hello/hello_v1_hello.go
-
2internal/dao/internal/article.go
-
6internal/dao/internal/user.go
-
4internal/dao/internal/vote_poll.go
-
10internal/dao/internal/vote_record.go
-
23internal/logic/article/article.go
-
5internal/logic/logic.go
-
2internal/model/do/article.go
-
6internal/model/do/user.go
-
2internal/model/do/vote_poll.go
-
8internal/model/do/vote_record.go
-
2internal/model/entity/article.go
-
14internal/model/entity/user.go
-
2internal/model/entity/vote_poll.go
-
14internal/model/entity/vote_record.go
-
23internal/service/article.go
-
4manifest/config/config.yaml
@ -0,0 +1,58 @@ |
|||
package article |
|||
|
|||
import ( |
|||
"github.com/gogf/gf/v2/frame/g" |
|||
"github.com/gogf/gf/v2/os/gtime" |
|||
) |
|||
|
|||
type ArticleReq struct { |
|||
g.Meta `path:"/addArticle" method:"post" tags:"添加文章"` |
|||
|
|||
//Article Article `json:"article"`
|
|||
//VotePoll VotePoll `json:"votePoll"`
|
|||
//VoteOption VoteOption `json:"voteOption"`
|
|||
//Article表字段
|
|||
UserId int64 `p:"userId" v:"required" dc:"用户 ID"` |
|||
ArticleTitle string `p:"articleTitle" v:"required#标题不能为空" dc:"文章标题"` |
|||
ArticleContent string `p:"articleContent" v:"required#内容不能为空" dc:"文章内容"` |
|||
VoteStatus int `p:"voteStatus" v:"required" dc:"是否投票"` |
|||
//VotePoll表字段
|
|||
ArticleId int64 `p:"articleId" dc:"文章ID"` |
|||
VoteTitle string `p:"voteTitle" v:"required#投票标题不能为空|len:max=24#投票标题不能超过24个字" dc:"投票标题"` |
|||
MultiOption int `p:"multiOption" v:"required" dc:"是否多选"` |
|||
DeadlineTime *gtime.Time `p:"deadlineTime" v:"required" dc:"截止时间"` |
|||
Status int `p:"status" v:"required" dc:"投票活动状态" d:"1"` |
|||
//VoteOption表字段
|
|||
VoteId int64 `p:"voteId" dc:"投票活动ID"` |
|||
OptionList []OptionList `p:"optionList" v:"required#选项不能为空" dc:"投票选项与第几个选项"` |
|||
} |
|||
|
|||
type OptionList struct { |
|||
OptionIndex int `json:"optionIndex" v:"required" dc:"选项序号"` |
|||
OptionContent string `json:"optionContent" v:"required#选项不能为空" dc:"投票选项"` |
|||
} |
|||
|
|||
type ArticleRes struct { |
|||
g.Meta `mime:"application/json"` |
|||
} |
|||
|
|||
//type Article struct {
|
|||
// g.Meta `mime:"application/json"`
|
|||
// UserId int64 `p:"userId" v:"required" dc:"用户 ID"`
|
|||
// ArticleTitle string `p:"articleTitle" v:"required#标题不能为空" dc:"文章标题"`
|
|||
// ArticleContent string `p:"articleContent" v:"required#内容不能为空" dc:"文章内容"`
|
|||
// VoteStatus int `p:"voteStatus" v:"required" dc:"是否投票"`
|
|||
//}
|
|||
//
|
|||
//type VotePoll struct {
|
|||
// g.Meta `mime:"application/json"`
|
|||
// ArticleId int64 `p:"articleId" v:"required" dc:"文章ID"`
|
|||
// VoteTitle string `p:"voteTitle" v:"required#投票标题不能为空|len:max=24#投票标题不能超过24个字" dc:"投票标题"`
|
|||
// MultiOption int `p:"multiOption" v:"required" dc:"是否多选"`
|
|||
// DeadlineTime *gtime.Time `p:"deadlineTime" v:"required" dc:"截止时间"`
|
|||
//}
|
|||
//
|
|||
//type VoteOption struct {
|
|||
// g.Meta `mime:"application/json"`
|
|||
// OptionList []string `p:"optionList" v:"required#选项不能为空" dc:"投票选项"`
|
|||
//}
|
@ -1,15 +0,0 @@ |
|||
// =================================================================================
|
|||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
|||
// =================================================================================
|
|||
|
|||
package hello |
|||
|
|||
import ( |
|||
"context" |
|||
|
|||
"practice_ArticleVote_Go/api/hello/v1" |
|||
) |
|||
|
|||
type IHelloV1 interface { |
|||
Hello(ctx context.Context, req *v1.HelloReq) (res *v1.HelloRes, err error) |
|||
} |
@ -1,12 +0,0 @@ |
|||
package v1 |
|||
|
|||
import ( |
|||
"github.com/gogf/gf/v2/frame/g" |
|||
) |
|||
|
|||
type HelloReq struct { |
|||
g.Meta `path:"/hello" tags:"Hello" method:"get" summary:"You first hello api"` |
|||
} |
|||
type HelloRes struct { |
|||
g.Meta `mime:"text/html" example:"string"` |
|||
} |
@ -0,0 +1,60 @@ |
|||
package article |
|||
|
|||
import ( |
|||
"context" |
|||
"fmt" |
|||
"practice_ArticleVote_Go/api/article" |
|||
"practice_ArticleVote_Go/internal/dao" |
|||
"practice_ArticleVote_Go/internal/service" |
|||
) |
|||
|
|||
var ArticlecController = &cArticle{} |
|||
|
|||
type cArticle struct { |
|||
service service.IArticle |
|||
} |
|||
|
|||
func (c *cArticle) AddArticle(ctx context.Context, req *article.ArticleReq) (res *article.ArticleRes, err error) { |
|||
|
|||
var Aid int64 |
|||
var Vid int64 |
|||
type VoteOption struct { |
|||
VoteId int64 |
|||
OptionContent string |
|||
OptionIndex int |
|||
Status int |
|||
} |
|||
var VoteOptions []VoteOption |
|||
|
|||
// 创建文章
|
|||
Aid, err = dao.Article.Ctx(ctx).Data(req).InsertAndGetId() |
|||
|
|||
if req.VoteStatus == 1 { |
|||
req.ArticleId = Aid |
|||
// 如果发起投票,创建投票活动
|
|||
Vid, err = dao.VotePoll.Ctx(ctx).Data(req).InsertAndGetId() |
|||
if err != nil { |
|||
return nil, fmt.Errorf("创建投票活动失败: %w", err) |
|||
} |
|||
|
|||
// 如果发起投票,创建投票选项
|
|||
for _, option := range req.OptionList { |
|||
VoteOptions = append(VoteOptions, VoteOption{ |
|||
VoteId: Vid, |
|||
OptionContent: option.OptionContent, |
|||
OptionIndex: option.OptionIndex, |
|||
Status: 1, |
|||
}) |
|||
} |
|||
_, err = dao.VoteOption.Ctx(ctx).Data(VoteOptions).Insert() |
|||
|
|||
if err != nil { |
|||
return nil, fmt.Errorf("创建投票选项失败: %w", err) |
|||
} |
|||
} |
|||
|
|||
if err != nil { |
|||
return nil, fmt.Errorf("创建文章失败: %w", err) |
|||
} |
|||
return |
|||
} |
@ -1,5 +0,0 @@ |
|||
// =================================================================================
|
|||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
|||
// =================================================================================
|
|||
|
|||
package hello |
@ -1,15 +0,0 @@ |
|||
// =================================================================================
|
|||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
|||
// =================================================================================
|
|||
|
|||
package hello |
|||
|
|||
import ( |
|||
"practice_ArticleVote_Go/api/hello" |
|||
) |
|||
|
|||
type ControllerV1 struct{} |
|||
|
|||
func NewV1() hello.IHelloV1 { |
|||
return &ControllerV1{} |
|||
} |
@ -1,13 +0,0 @@ |
|||
package hello |
|||
|
|||
import ( |
|||
"context" |
|||
"github.com/gogf/gf/v2/frame/g" |
|||
|
|||
"practice_ArticleVote_Go/api/hello/v1" |
|||
) |
|||
|
|||
func (c *ControllerV1) Hello(ctx context.Context, req *v1.HelloReq) (res *v1.HelloRes, err error) { |
|||
g.RequestFromCtx(ctx).Response.Writeln("Hello World!") |
|||
return |
|||
} |
@ -0,0 +1,23 @@ |
|||
package article |
|||
|
|||
import ( |
|||
"context" |
|||
"practice_ArticleVote_Go/internal/dao" |
|||
"practice_ArticleVote_Go/internal/model/do" |
|||
"practice_ArticleVote_Go/internal/service" |
|||
) |
|||
|
|||
func init() { |
|||
service.RegisterArticle(New()) |
|||
} |
|||
|
|||
func New() *iArticle { |
|||
return &iArticle{} |
|||
} |
|||
|
|||
type iArticle struct{} |
|||
|
|||
func (i iArticle) AddArticle(ctx context.Context, article do.Article) (Aid int64, err error) { |
|||
Aid, err = dao.Article.Ctx(ctx).Data(article).InsertAndGetId() |
|||
return Aid, err |
|||
} |
@ -1,9 +1,6 @@ |
|||
// ==========================================================================
|
|||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
|||
// ==========================================================================
|
|||
|
|||
package logic |
|||
|
|||
import ( |
|||
_ "practice_ArticleVote_Go/internal/logic/vote_record" |
|||
_ "practice_ArticleVote_Go/internal/logic/article" |
|||
) |
@ -0,0 +1,23 @@ |
|||
package service |
|||
|
|||
import ( |
|||
"context" |
|||
"practice_ArticleVote_Go/internal/model/do" |
|||
) |
|||
|
|||
type IArticle interface { |
|||
AddArticle(ctx context.Context, article do.Article) (Aid int64, err error) |
|||
} |
|||
|
|||
var localArticle IArticle |
|||
|
|||
func Article() IArticle { |
|||
if localArticle == nil { |
|||
panic("IArticle接口未实现或未注册") |
|||
} |
|||
return localArticle |
|||
} |
|||
|
|||
func RegisterArticle(i IArticle) { |
|||
localArticle = i |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue