From 7e3aaad12e4b1a147ada18d52ada6153d148ffcd Mon Sep 17 00:00:00 2001 From: maziyang Date: Sat, 21 Jun 2025 10:41:17 +0800 Subject: [PATCH] =?UTF-8?q?[lrq]=E6=B7=BB=E5=8A=A0=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E4=B8=8E=E6=8A=95=E7=A5=A8=E6=B4=BB=E5=8A=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/article/article.go | 58 +++++++++++++++++++ api/hello/hello.go | 15 ----- api/hello/v1/hello.go | 12 ---- hack/config.yaml | 2 +- internal/cmd/cmd.go | 9 ++- internal/controller/article/article.go | 60 ++++++++++++++++++++ internal/controller/hello/hello.go | 5 -- internal/controller/hello/hello_new.go | 15 ----- internal/controller/hello/hello_v1_hello.go | 13 ----- internal/dao/internal/article.go | 2 +- internal/dao/internal/post.go | 87 ----------------------------- internal/dao/internal/remain_vote_number.go | 85 ---------------------------- internal/dao/internal/user.go | 6 +- internal/dao/internal/vote_option.go | 4 +- internal/dao/internal/vote_poll.go | 4 +- internal/dao/internal/vote_record.go | 10 ++-- internal/dao/post.go | 22 -------- internal/dao/remain_vote_number.go | 22 -------- internal/logic/article/article.go | 23 ++++++++ internal/logic/logic.go | 5 ++ internal/model/do/article.go | 2 +- internal/model/do/post.go | 20 ------- internal/model/do/remain_vote_number.go | 19 ------- internal/model/do/user.go | 6 +- internal/model/do/vote_option.go | 3 +- internal/model/do/vote_poll.go | 2 +- internal/model/do/vote_record.go | 8 +-- internal/model/entity/article.go | 2 +- internal/model/entity/post.go | 18 ------ internal/model/entity/remain_vote_number.go | 17 ------ internal/model/entity/user.go | 14 ++--- internal/model/entity/vote_option.go | 11 ++-- internal/model/entity/vote_poll.go | 2 +- internal/model/entity/vote_record.go | 14 ++--- internal/service/article.go | 23 ++++++++ main.go | 2 + manifest/config/config.yaml | 4 +- 37 files changed, 226 insertions(+), 400 deletions(-) create mode 100644 api/article/article.go delete mode 100644 api/hello/hello.go delete mode 100644 api/hello/v1/hello.go create mode 100644 internal/controller/article/article.go delete mode 100644 internal/controller/hello/hello.go delete mode 100644 internal/controller/hello/hello_new.go delete mode 100644 internal/controller/hello/hello_v1_hello.go delete mode 100644 internal/dao/internal/post.go delete mode 100644 internal/dao/internal/remain_vote_number.go delete mode 100644 internal/dao/post.go delete mode 100644 internal/dao/remain_vote_number.go create mode 100644 internal/logic/article/article.go create mode 100644 internal/logic/logic.go delete mode 100644 internal/model/do/post.go delete mode 100644 internal/model/do/remain_vote_number.go delete mode 100644 internal/model/entity/post.go delete mode 100644 internal/model/entity/remain_vote_number.go create mode 100644 internal/service/article.go diff --git a/api/article/article.go b/api/article/article.go new file mode 100644 index 0000000..416475a --- /dev/null +++ b/api/article/article.go @@ -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:"投票选项"` +//} diff --git a/api/hello/hello.go b/api/hello/hello.go deleted file mode 100644 index 3531af4..0000000 --- a/api/hello/hello.go +++ /dev/null @@ -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) -} diff --git a/api/hello/v1/hello.go b/api/hello/v1/hello.go deleted file mode 100644 index b4dd233..0000000 --- a/api/hello/v1/hello.go +++ /dev/null @@ -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"` -} diff --git a/hack/config.yaml b/hack/config.yaml index 5837e80..2e1a0e6 100644 --- a/hack/config.yaml +++ b/hack/config.yaml @@ -4,7 +4,7 @@ gfcli: gen: dao: - - link: "mysql:root:123456@tcp(127.0.0.1:3306)/link_test" + - link: "mysql:root:root@tcp(127.0.0.1:3306)/link_test" descriptionTag: true docker: diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 7c5f94c..ea84448 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -2,12 +2,11 @@ package cmd import ( "context" + "practice_ArticleVote_Go/internal/controller/article" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" "github.com/gogf/gf/v2/os/gcmd" - - "practice_ArticleVote_Go/internal/controller/hello" ) var ( @@ -17,12 +16,12 @@ var ( Brief: "start http server", Func: func(ctx context.Context, parser *gcmd.Parser) (err error) { s := g.Server() + s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(ghttp.MiddlewareHandlerResponse) - group.Bind( - hello.NewV1(), - ) + group.Bind(article.ArticlecController) }) + s.Run() return nil }, diff --git a/internal/controller/article/article.go b/internal/controller/article/article.go new file mode 100644 index 0000000..1e6229d --- /dev/null +++ b/internal/controller/article/article.go @@ -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 +} diff --git a/internal/controller/hello/hello.go b/internal/controller/hello/hello.go deleted file mode 100644 index f72082f..0000000 --- a/internal/controller/hello/hello.go +++ /dev/null @@ -1,5 +0,0 @@ -// ================================================================================= -// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. -// ================================================================================= - -package hello diff --git a/internal/controller/hello/hello_new.go b/internal/controller/hello/hello_new.go deleted file mode 100644 index c14fb88..0000000 --- a/internal/controller/hello/hello_new.go +++ /dev/null @@ -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{} -} diff --git a/internal/controller/hello/hello_v1_hello.go b/internal/controller/hello/hello_v1_hello.go deleted file mode 100644 index 9f36784..0000000 --- a/internal/controller/hello/hello_v1_hello.go +++ /dev/null @@ -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 -} diff --git a/internal/dao/internal/article.go b/internal/dao/internal/article.go index 2cb4956..e816d09 100644 --- a/internal/dao/internal/article.go +++ b/internal/dao/internal/article.go @@ -22,7 +22,7 @@ type ArticleDao struct { // ArticleColumns defines and stores column names for the table article. type ArticleColumns struct { Id string // - UserId string // + UserId string // 用户ID ArticleTitle string // 文章/视频标题 ArticleContent string // 文章/视频内容 VoteStatus string // 是否发起投票:1发起,0不发起 diff --git a/internal/dao/internal/post.go b/internal/dao/internal/post.go deleted file mode 100644 index 6d9fe20..0000000 --- a/internal/dao/internal/post.go +++ /dev/null @@ -1,87 +0,0 @@ -// ========================================================================== -// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. -// ========================================================================== - -package internal - -import ( - "context" - - "github.com/gogf/gf/v2/database/gdb" - "github.com/gogf/gf/v2/frame/g" -) - -// PostDao is the data access object for the table post. -type PostDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of the current DAO. - columns PostColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. -} - -// PostColumns defines and stores column names for the table post. -type PostColumns struct { - Id string // - PostTitle string // 文章/视频标题 - PostContent string // 文章/视频内容 - VoteStatus string // 是否发起投票:1发起,0不发起 - CreateTime string // -} - -// postColumns holds the columns for the table post. -var postColumns = PostColumns{ - Id: "id", - PostTitle: "post_title", - PostContent: "post_content", - VoteStatus: "vote_status", - CreateTime: "create_time", -} - -// NewPostDao creates and returns a new DAO object for table data access. -func NewPostDao(handlers ...gdb.ModelHandler) *PostDao { - return &PostDao{ - group: "default", - table: "post", - columns: postColumns, - handlers: handlers, - } -} - -// DB retrieves and returns the underlying raw database management object of the current DAO. -func (dao *PostDao) DB() gdb.DB { - return g.DB(dao.group) -} - -// Table returns the table name of the current DAO. -func (dao *PostDao) Table() string { - return dao.table -} - -// Columns returns all column names of the current DAO. -func (dao *PostDao) Columns() PostColumns { - return dao.columns -} - -// Group returns the database configuration group name of the current DAO. -func (dao *PostDao) Group() string { - return dao.group -} - -// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. -func (dao *PostDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) -} - -// Transaction wraps the transaction logic using function f. -// It rolls back the transaction and returns the error if function f returns a non-nil error. -// It commits the transaction and returns nil if function f returns nil. -// -// Note: Do not commit or roll back the transaction in function f, -// as it is automatically handled by this function. -func (dao *PostDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { - return dao.Ctx(ctx).Transaction(ctx, f) -} diff --git a/internal/dao/internal/remain_vote_number.go b/internal/dao/internal/remain_vote_number.go deleted file mode 100644 index 72f1d37..0000000 --- a/internal/dao/internal/remain_vote_number.go +++ /dev/null @@ -1,85 +0,0 @@ -// ========================================================================== -// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. -// ========================================================================== - -package internal - -import ( - "context" - - "github.com/gogf/gf/v2/database/gdb" - "github.com/gogf/gf/v2/frame/g" -) - -// RemainVoteNumberDao is the data access object for the table remain_vote_number. -type RemainVoteNumberDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of the current DAO. - columns RemainVoteNumberColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. -} - -// RemainVoteNumberColumns defines and stores column names for the table remain_vote_number. -type RemainVoteNumberColumns struct { - Id string // - UserId string // - RemainTimes string // - LastDate string // -} - -// remainVoteNumberColumns holds the columns for the table remain_vote_number. -var remainVoteNumberColumns = RemainVoteNumberColumns{ - Id: "id", - UserId: "user_id", - RemainTimes: "remain_times", - LastDate: "last_date", -} - -// NewRemainVoteNumberDao creates and returns a new DAO object for table data access. -func NewRemainVoteNumberDao(handlers ...gdb.ModelHandler) *RemainVoteNumberDao { - return &RemainVoteNumberDao{ - group: "default", - table: "remain_vote_number", - columns: remainVoteNumberColumns, - handlers: handlers, - } -} - -// DB retrieves and returns the underlying raw database management object of the current DAO. -func (dao *RemainVoteNumberDao) DB() gdb.DB { - return g.DB(dao.group) -} - -// Table returns the table name of the current DAO. -func (dao *RemainVoteNumberDao) Table() string { - return dao.table -} - -// Columns returns all column names of the current DAO. -func (dao *RemainVoteNumberDao) Columns() RemainVoteNumberColumns { - return dao.columns -} - -// Group returns the database configuration group name of the current DAO. -func (dao *RemainVoteNumberDao) Group() string { - return dao.group -} - -// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. -func (dao *RemainVoteNumberDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) -} - -// Transaction wraps the transaction logic using function f. -// It rolls back the transaction and returns the error if function f returns a non-nil error. -// It commits the transaction and returns nil if function f returns nil. -// -// Note: Do not commit or roll back the transaction in function f, -// as it is automatically handled by this function. -func (dao *RemainVoteNumberDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { - return dao.Ctx(ctx).Transaction(ctx, f) -} diff --git a/internal/dao/internal/user.go b/internal/dao/internal/user.go index 13c6294..278bdd1 100644 --- a/internal/dao/internal/user.go +++ b/internal/dao/internal/user.go @@ -22,9 +22,9 @@ type UserDao struct { // UserColumns defines and stores column names for the table user. type UserColumns struct { Id string // - Account string // - Password string // - Username string // + Account string // 精网号 + Password string // 用户密码 + Username string // 用户名 Status string // CreateTime string // UpdateTime string // diff --git a/internal/dao/internal/vote_option.go b/internal/dao/internal/vote_option.go index 3a8c086..f5e58a7 100644 --- a/internal/dao/internal/vote_option.go +++ b/internal/dao/internal/vote_option.go @@ -24,7 +24,8 @@ type VoteOptionColumns struct { Id string // VoteId string // 投票活动ID OptionContent string // 选项内容 - Status string // 选项状态 + OptionIndex string // 第几个选项 + Status string // 选项状态:1选择,0不选择 CreateTime string // } @@ -33,6 +34,7 @@ var voteOptionColumns = VoteOptionColumns{ Id: "id", VoteId: "vote_id", OptionContent: "option_content", + OptionIndex: "option_index", Status: "status", CreateTime: "create_time", } diff --git a/internal/dao/internal/vote_poll.go b/internal/dao/internal/vote_poll.go index c7005a3..396344d 100644 --- a/internal/dao/internal/vote_poll.go +++ b/internal/dao/internal/vote_poll.go @@ -27,8 +27,8 @@ type VotePollColumns struct { MultiOption string // 是否开启多选:1多选,0不多选 DeadlineTime string // 截止时间 CreateTime string // - Status string // 投票活动状态:1:进行中,0已结束 UpdateTime string // + Status string // 投票活动状态:1:进行中,0已结束 } // votePollColumns holds the columns for the table vote_poll. @@ -39,8 +39,8 @@ var votePollColumns = VotePollColumns{ MultiOption: "multi_option", DeadlineTime: "deadline_time", CreateTime: "create_time", - Status: "status", UpdateTime: "update_time", + Status: "status", } // NewVotePollDao creates and returns a new DAO object for table data access. diff --git a/internal/dao/internal/vote_record.go b/internal/dao/internal/vote_record.go index b7fb7f1..42d1b04 100644 --- a/internal/dao/internal/vote_record.go +++ b/internal/dao/internal/vote_record.go @@ -22,11 +22,11 @@ type VoteRecordDao struct { // VoteRecordColumns defines and stores column names for the table vote_record. type VoteRecordColumns struct { Id string // - UserId string // - VoteId string // - OptionId string // + UserId string // 用户ID + VoteId string // 投票活动ID + OptionId string // 投票选项ID + VoteIndex string // 已投票次数 CreateTime string // - VoteIndex string // UpdateTime string // } @@ -36,8 +36,8 @@ var voteRecordColumns = VoteRecordColumns{ UserId: "user_id", VoteId: "vote_id", OptionId: "option_id", - CreateTime: "create_time", VoteIndex: "vote_index", + CreateTime: "create_time", UpdateTime: "update_time", } diff --git a/internal/dao/post.go b/internal/dao/post.go deleted file mode 100644 index 54784dd..0000000 --- a/internal/dao/post.go +++ /dev/null @@ -1,22 +0,0 @@ -// ================================================================================= -// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed. -// ================================================================================= - -package dao - -import ( - "practice_ArticleVote_Go/internal/dao/internal" -) - -// postDao is the data access object for the table post. -// You can define custom methods on it to extend its functionality as needed. -type postDao struct { - *internal.PostDao -} - -var ( - // Post is a globally accessible object for table post operations. - Post = postDao{internal.NewPostDao()} -) - -// Add your custom methods and functionality below. diff --git a/internal/dao/remain_vote_number.go b/internal/dao/remain_vote_number.go deleted file mode 100644 index ee82e9d..0000000 --- a/internal/dao/remain_vote_number.go +++ /dev/null @@ -1,22 +0,0 @@ -// ================================================================================= -// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed. -// ================================================================================= - -package dao - -import ( - "practice_ArticleVote_Go/internal/dao/internal" -) - -// remainVoteNumberDao is the data access object for the table remain_vote_number. -// You can define custom methods on it to extend its functionality as needed. -type remainVoteNumberDao struct { - *internal.RemainVoteNumberDao -} - -var ( - // RemainVoteNumber is a globally accessible object for table remain_vote_number operations. - RemainVoteNumber = remainVoteNumberDao{internal.NewRemainVoteNumberDao()} -) - -// Add your custom methods and functionality below. diff --git a/internal/logic/article/article.go b/internal/logic/article/article.go new file mode 100644 index 0000000..584f21f --- /dev/null +++ b/internal/logic/article/article.go @@ -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 +} diff --git a/internal/logic/logic.go b/internal/logic/logic.go new file mode 100644 index 0000000..332bcdb --- /dev/null +++ b/internal/logic/logic.go @@ -0,0 +1,5 @@ +package logic + +import ( + _ "practice_ArticleVote_Go/internal/logic/article" +) diff --git a/internal/model/do/article.go b/internal/model/do/article.go index f4994d7..f34c33c 100644 --- a/internal/model/do/article.go +++ b/internal/model/do/article.go @@ -13,7 +13,7 @@ import ( type Article struct { g.Meta `orm:"table:article, do:true"` Id interface{} // - UserId interface{} // + UserId interface{} // 用户ID ArticleTitle interface{} // 文章/视频标题 ArticleContent interface{} // 文章/视频内容 VoteStatus interface{} // 是否发起投票:1发起,0不发起 diff --git a/internal/model/do/post.go b/internal/model/do/post.go deleted file mode 100644 index 93e74bc..0000000 --- a/internal/model/do/post.go +++ /dev/null @@ -1,20 +0,0 @@ -// ================================================================================= -// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. -// ================================================================================= - -package do - -import ( - "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/os/gtime" -) - -// Post is the golang structure of table post for DAO operations like Where/Data. -type Post struct { - g.Meta `orm:"table:post, do:true"` - Id interface{} // - PostTitle interface{} // 文章/视频标题 - PostContent interface{} // 文章/视频内容 - VoteStatus interface{} // 是否发起投票:1发起,0不发起 - CreateTime *gtime.Time // -} diff --git a/internal/model/do/remain_vote_number.go b/internal/model/do/remain_vote_number.go deleted file mode 100644 index 954fddf..0000000 --- a/internal/model/do/remain_vote_number.go +++ /dev/null @@ -1,19 +0,0 @@ -// ================================================================================= -// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. -// ================================================================================= - -package do - -import ( - "github.com/gogf/gf/v2/frame/g" - "github.com/gogf/gf/v2/os/gtime" -) - -// RemainVoteNumber is the golang structure of table remain_vote_number for DAO operations like Where/Data. -type RemainVoteNumber struct { - g.Meta `orm:"table:remain_vote_number, do:true"` - Id interface{} // - UserId interface{} // - RemainTimes interface{} // - LastDate *gtime.Time // -} diff --git a/internal/model/do/user.go b/internal/model/do/user.go index 207281c..a2b8e80 100644 --- a/internal/model/do/user.go +++ b/internal/model/do/user.go @@ -13,9 +13,9 @@ import ( type User struct { g.Meta `orm:"table:user, do:true"` Id interface{} // - Account interface{} // - Password interface{} // - Username interface{} // + Account interface{} // 精网号 + Password interface{} // 用户密码 + Username interface{} // 用户名 Status interface{} // CreateTime *gtime.Time // UpdateTime *gtime.Time // diff --git a/internal/model/do/vote_option.go b/internal/model/do/vote_option.go index 75cc178..e79842c 100644 --- a/internal/model/do/vote_option.go +++ b/internal/model/do/vote_option.go @@ -15,6 +15,7 @@ type VoteOption struct { Id interface{} // VoteId interface{} // 投票活动ID OptionContent interface{} // 选项内容 - Status interface{} // 选项状态 + OptionIndex interface{} // 第几个选项 + Status interface{} // 选项状态:1选择,0不选择 CreateTime *gtime.Time // } diff --git a/internal/model/do/vote_poll.go b/internal/model/do/vote_poll.go index 67ea16b..54cb5e5 100644 --- a/internal/model/do/vote_poll.go +++ b/internal/model/do/vote_poll.go @@ -18,6 +18,6 @@ type VotePoll struct { MultiOption interface{} // 是否开启多选:1多选,0不多选 DeadlineTime *gtime.Time // 截止时间 CreateTime *gtime.Time // - Status interface{} // 投票活动状态:1:进行中,0已结束 UpdateTime *gtime.Time // + Status interface{} // 投票活动状态:1:进行中,0已结束 } diff --git a/internal/model/do/vote_record.go b/internal/model/do/vote_record.go index 26a7058..3b9130e 100644 --- a/internal/model/do/vote_record.go +++ b/internal/model/do/vote_record.go @@ -13,10 +13,10 @@ import ( type VoteRecord struct { g.Meta `orm:"table:vote_record, do:true"` Id interface{} // - UserId interface{} // - VoteId interface{} // - OptionId interface{} // + UserId interface{} // 用户ID + VoteId interface{} // 投票活动ID + OptionId interface{} // 投票选项ID + VoteIndex interface{} // 已投票次数 CreateTime *gtime.Time // - VoteIndex interface{} // UpdateTime *gtime.Time // } diff --git a/internal/model/entity/article.go b/internal/model/entity/article.go index 0b7ff15..9484a4f 100644 --- a/internal/model/entity/article.go +++ b/internal/model/entity/article.go @@ -11,7 +11,7 @@ import ( // Article is the golang structure for table article. type Article struct { Id int64 `json:"id" orm:"id" description:""` // - UserId int64 `json:"userId" orm:"user_id" description:""` // + UserId int64 `json:"userId" orm:"user_id" description:"用户ID"` // 用户ID ArticleTitle string `json:"articleTitle" orm:"article_title" description:"文章/视频标题"` // 文章/视频标题 ArticleContent string `json:"articleContent" orm:"article_content" description:"文章/视频内容"` // 文章/视频内容 VoteStatus int `json:"voteStatus" orm:"vote_status" description:"是否发起投票:1发起,0不发起"` // 是否发起投票:1发起,0不发起 diff --git a/internal/model/entity/post.go b/internal/model/entity/post.go deleted file mode 100644 index 5b00938..0000000 --- a/internal/model/entity/post.go +++ /dev/null @@ -1,18 +0,0 @@ -// ================================================================================= -// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. -// ================================================================================= - -package entity - -import ( - "github.com/gogf/gf/v2/os/gtime" -) - -// Post is the golang structure for table post. -type Post struct { - Id int64 `json:"id" orm:"id" description:""` // - PostTitle string `json:"postTitle" orm:"post_title" description:"文章/视频标题"` // 文章/视频标题 - PostContent string `json:"postContent" orm:"post_content" description:"文章/视频内容"` // 文章/视频内容 - VoteStatus int `json:"voteStatus" orm:"vote_status" description:"是否发起投票:1发起,0不发起"` // 是否发起投票:1发起,0不发起 - CreateTime *gtime.Time `json:"createTime" orm:"create_time" description:""` // -} diff --git a/internal/model/entity/remain_vote_number.go b/internal/model/entity/remain_vote_number.go deleted file mode 100644 index 41823b8..0000000 --- a/internal/model/entity/remain_vote_number.go +++ /dev/null @@ -1,17 +0,0 @@ -// ================================================================================= -// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. -// ================================================================================= - -package entity - -import ( - "github.com/gogf/gf/v2/os/gtime" -) - -// RemainVoteNumber is the golang structure for table remain_vote_number. -type RemainVoteNumber struct { - Id int64 `json:"id" orm:"id" description:""` // - UserId int64 `json:"userId" orm:"user_id" description:""` // - RemainTimes int `json:"remainTimes" orm:"remain_times" description:""` // - LastDate *gtime.Time `json:"lastDate" orm:"last_date" description:""` // -} diff --git a/internal/model/entity/user.go b/internal/model/entity/user.go index 3dbd830..efbde32 100644 --- a/internal/model/entity/user.go +++ b/internal/model/entity/user.go @@ -10,11 +10,11 @@ import ( // User is the golang structure for table user. type User struct { - Id int64 `json:"id" orm:"id" description:""` // - Account string `json:"account" orm:"account" description:""` // - Password string `json:"password" orm:"password" description:""` // - Username string `json:"username" orm:"username" description:""` // - Status uint `json:"status" orm:"status" description:""` // - CreateTime *gtime.Time `json:"createTime" orm:"create_time" description:""` // - UpdateTime *gtime.Time `json:"updateTime" orm:"update_time" description:""` // + Id int64 `json:"id" orm:"id" description:""` // + Account string `json:"account" orm:"account" description:"精网号"` // 精网号 + Password string `json:"password" orm:"password" description:"用户密码"` // 用户密码 + Username string `json:"username" orm:"username" description:"用户名"` // 用户名 + Status uint `json:"status" orm:"status" description:""` // + CreateTime *gtime.Time `json:"createTime" orm:"create_time" description:""` // + UpdateTime *gtime.Time `json:"updateTime" orm:"update_time" description:""` // } diff --git a/internal/model/entity/vote_option.go b/internal/model/entity/vote_option.go index 48864fc..628b2d0 100644 --- a/internal/model/entity/vote_option.go +++ b/internal/model/entity/vote_option.go @@ -10,9 +10,10 @@ import ( // VoteOption is the golang structure for table vote_option. type VoteOption struct { - Id int64 `json:"id" orm:"id" description:""` // - VoteId int64 `json:"voteId" orm:"vote_id" description:"投票活动ID"` // 投票活动ID - OptionContent string `json:"optionContent" orm:"option_content" description:"选项内容"` // 选项内容 - Status uint `json:"status" orm:"status" description:"选项状态"` // 选项状态 - CreateTime *gtime.Time `json:"createTime" orm:"create_time" description:""` // + Id int64 `json:"id" orm:"id" description:""` // + VoteId int64 `json:"voteId" orm:"vote_id" description:"投票活动ID"` // 投票活动ID + OptionContent string `json:"optionContent" orm:"option_content" description:"选项内容"` // 选项内容 + OptionIndex int `json:"optionIndex" orm:"option_index" description:"第几个选项"` // 第几个选项 + Status uint `json:"status" orm:"status" description:"选项状态:1选择,0不选择"` // 选项状态:1选择,0不选择 + CreateTime *gtime.Time `json:"createTime" orm:"create_time" description:""` // } diff --git a/internal/model/entity/vote_poll.go b/internal/model/entity/vote_poll.go index 192d964..43459dc 100644 --- a/internal/model/entity/vote_poll.go +++ b/internal/model/entity/vote_poll.go @@ -16,6 +16,6 @@ type VotePoll struct { MultiOption int `json:"multiOption" orm:"multi_option" description:"是否开启多选:1多选,0不多选"` // 是否开启多选:1多选,0不多选 DeadlineTime *gtime.Time `json:"deadlineTime" orm:"deadline_time" description:"截止时间"` // 截止时间 CreateTime *gtime.Time `json:"createTime" orm:"create_time" description:""` // - Status int `json:"status" orm:"status" description:"投票活动状态:1:进行中,0已结束"` // 投票活动状态:1:进行中,0已结束 UpdateTime *gtime.Time `json:"updateTime" orm:"update_time" description:""` // + Status int `json:"status" orm:"status" description:"投票活动状态:1:进行中,0已结束"` // 投票活动状态:1:进行中,0已结束 } diff --git a/internal/model/entity/vote_record.go b/internal/model/entity/vote_record.go index a11c458..056a44e 100644 --- a/internal/model/entity/vote_record.go +++ b/internal/model/entity/vote_record.go @@ -10,11 +10,11 @@ import ( // VoteRecord is the golang structure for table vote_record. type VoteRecord struct { - Id int64 `json:"id" orm:"id" description:""` // - UserId int64 `json:"userId" orm:"user_id" description:""` // - VoteId int64 `json:"voteId" orm:"vote_id" description:""` // - OptionId int64 `json:"optionId" orm:"option_id" description:""` // - CreateTime *gtime.Time `json:"createTime" orm:"create_time" description:""` // - VoteIndex int `json:"voteIndex" orm:"vote_index" description:""` // - UpdateTime *gtime.Time `json:"updateTime" orm:"update_time" description:""` // + Id int64 `json:"id" orm:"id" description:""` // + UserId int64 `json:"userId" orm:"user_id" description:"用户ID"` // 用户ID + VoteId int64 `json:"voteId" orm:"vote_id" description:"投票活动ID"` // 投票活动ID + OptionId int64 `json:"optionId" orm:"option_id" description:"投票选项ID"` // 投票选项ID + VoteIndex int `json:"voteIndex" orm:"vote_index" description:"已投票次数"` // 已投票次数 + CreateTime *gtime.Time `json:"createTime" orm:"create_time" description:""` // + UpdateTime *gtime.Time `json:"updateTime" orm:"update_time" description:""` // } diff --git a/internal/service/article.go b/internal/service/article.go new file mode 100644 index 0000000..16e04ad --- /dev/null +++ b/internal/service/article.go @@ -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 +} diff --git a/main.go b/main.go index f9f623f..dcf78da 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,8 @@ import ( _ "practice_ArticleVote_Go/internal/packed" + _ "practice_ArticleVote_Go/internal/logic" + "github.com/gogf/gf/v2/os/gctx" "practice_ArticleVote_Go/internal/cmd" diff --git a/manifest/config/config.yaml b/manifest/config/config.yaml index 8b7dc92..b6cd1b9 100644 --- a/manifest/config/config.yaml +++ b/manifest/config/config.yaml @@ -12,4 +12,6 @@ logger: # https://goframe.org/docs/core/gdb-config-file database: default: - link: "mysql:root:123456@tcp(127.0.0.1:3306)/link_test" \ No newline at end of file + link: "mysql:root:root@tcp(127.0.0.1:3306)/link_test" + createdAt: "create_time" + updatedAt: "update_time" \ No newline at end of file