diff --git a/internal/consts/vote.go b/internal/consts/vote.go new file mode 100644 index 0000000..e7da1c1 --- /dev/null +++ b/internal/consts/vote.go @@ -0,0 +1,13 @@ +package consts + +// 投票活动状态 +const ( + VoteStatusGoing = 1 //进行中 + VoteStatusEnded = 0 //已结束 +) + +// 投票类型 +const ( + VoteTypeSingle = 0 //单选 + VoteTypeMultiple = 1 //多选 +) diff --git a/internal/dao/article.go b/internal/dao/article.go new file mode 100644 index 0000000..5a24db1 --- /dev/null +++ b/internal/dao/article.go @@ -0,0 +1,22 @@ +// ================================================================================= +// 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" +) + +// articleDao is the data access object for the table article. +// You can define custom methods on it to extend its functionality as needed. +type articleDao struct { + *internal.ArticleDao +} + +var ( + // Article is a globally accessible object for table article operations. + Article = articleDao{internal.NewArticleDao()} +) + +// Add your custom methods and functionality below. diff --git a/internal/dao/internal/article.go b/internal/dao/internal/article.go new file mode 100644 index 0000000..2cb4956 --- /dev/null +++ b/internal/dao/internal/article.go @@ -0,0 +1,91 @@ +// ========================================================================== +// 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" +) + +// ArticleDao is the data access object for the table article. +type ArticleDao 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 ArticleColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. +} + +// ArticleColumns defines and stores column names for the table article. +type ArticleColumns struct { + Id string // + UserId string // + ArticleTitle string // 文章/视频标题 + ArticleContent string // 文章/视频内容 + VoteStatus string // 是否发起投票:1发起,0不发起 + CreateTime string // + UpdateTime string // +} + +// articleColumns holds the columns for the table article. +var articleColumns = ArticleColumns{ + Id: "id", + UserId: "user_id", + ArticleTitle: "article_title", + ArticleContent: "article_content", + VoteStatus: "vote_status", + CreateTime: "create_time", + UpdateTime: "update_time", +} + +// NewArticleDao creates and returns a new DAO object for table data access. +func NewArticleDao(handlers ...gdb.ModelHandler) *ArticleDao { + return &ArticleDao{ + group: "default", + table: "article", + columns: articleColumns, + handlers: handlers, + } +} + +// DB retrieves and returns the underlying raw database management object of the current DAO. +func (dao *ArticleDao) DB() gdb.DB { + return g.DB(dao.group) +} + +// Table returns the table name of the current DAO. +func (dao *ArticleDao) Table() string { + return dao.table +} + +// Columns returns all column names of the current DAO. +func (dao *ArticleDao) Columns() ArticleColumns { + return dao.columns +} + +// Group returns the database configuration group name of the current DAO. +func (dao *ArticleDao) 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 *ArticleDao) 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 *ArticleDao) 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 e04a545..13c6294 100644 --- a/internal/dao/internal/user.go +++ b/internal/dao/internal/user.go @@ -27,6 +27,7 @@ type UserColumns struct { Username string // Status string // CreateTime string // + UpdateTime string // } // userColumns holds the columns for the table user. @@ -37,6 +38,7 @@ var userColumns = UserColumns{ Username: "username", Status: "status", CreateTime: "create_time", + UpdateTime: "update_time", } // NewUserDao creates and returns a new DAO object for table data access. diff --git a/internal/dao/internal/vote_option.go b/internal/dao/internal/vote_option.go index 712af32..3a8c086 100644 --- a/internal/dao/internal/vote_option.go +++ b/internal/dao/internal/vote_option.go @@ -25,6 +25,7 @@ type VoteOptionColumns struct { VoteId string // 投票活动ID OptionContent string // 选项内容 Status string // 选项状态 + CreateTime string // } // voteOptionColumns holds the columns for the table vote_option. @@ -33,6 +34,7 @@ var voteOptionColumns = VoteOptionColumns{ VoteId: "vote_id", OptionContent: "option_content", Status: "status", + CreateTime: "create_time", } // NewVoteOptionDao creates and returns a new DAO object for table data access. diff --git a/internal/dao/internal/vote_poll.go b/internal/dao/internal/vote_poll.go index 392a3eb..3f6b885 100644 --- a/internal/dao/internal/vote_poll.go +++ b/internal/dao/internal/vote_poll.go @@ -28,6 +28,7 @@ type VotePollColumns struct { DeadlineTime string // 截止时间 CreateTime string // Status string // 投票活动状态:1:进行中,0已结束 + UpdateTime string // } // votePollColumns holds the columns for the table vote_poll. @@ -39,6 +40,7 @@ var votePollColumns = VotePollColumns{ DeadlineTime: "deadline_time", CreateTime: "create_time", Status: "status", + UpdateTime: "update_time", } // 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 2f11a67..b7fb7f1 100644 --- a/internal/dao/internal/vote_record.go +++ b/internal/dao/internal/vote_record.go @@ -27,6 +27,7 @@ type VoteRecordColumns struct { OptionId string // CreateTime string // VoteIndex string // + UpdateTime string // } // voteRecordColumns holds the columns for the table vote_record. @@ -37,6 +38,7 @@ var voteRecordColumns = VoteRecordColumns{ OptionId: "option_id", CreateTime: "create_time", VoteIndex: "vote_index", + UpdateTime: "update_time", } // NewVoteRecordDao creates and returns a new DAO object for table data access. diff --git a/internal/model/do/article.go b/internal/model/do/article.go new file mode 100644 index 0000000..f4994d7 --- /dev/null +++ b/internal/model/do/article.go @@ -0,0 +1,22 @@ +// ================================================================================= +// 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" +) + +// Article is the golang structure of table article for DAO operations like Where/Data. +type Article struct { + g.Meta `orm:"table:article, do:true"` + Id interface{} // + UserId interface{} // + ArticleTitle interface{} // 文章/视频标题 + ArticleContent interface{} // 文章/视频内容 + VoteStatus interface{} // 是否发起投票:1发起,0不发起 + CreateTime *gtime.Time // + UpdateTime *gtime.Time // +} diff --git a/internal/model/do/user.go b/internal/model/do/user.go index 12811c1..207281c 100644 --- a/internal/model/do/user.go +++ b/internal/model/do/user.go @@ -18,4 +18,5 @@ type User struct { 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 96b5d19..75cc178 100644 --- a/internal/model/do/vote_option.go +++ b/internal/model/do/vote_option.go @@ -6,6 +6,7 @@ package do import ( "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" ) // VoteOption is the golang structure of table vote_option for DAO operations like Where/Data. @@ -15,4 +16,5 @@ type VoteOption struct { VoteId interface{} // 投票活动ID OptionContent interface{} // 选项内容 Status interface{} // 选项状态 + CreateTime *gtime.Time // } diff --git a/internal/model/do/vote_poll.go b/internal/model/do/vote_poll.go index e96b19d..82a9f6b 100644 --- a/internal/model/do/vote_poll.go +++ b/internal/model/do/vote_poll.go @@ -19,4 +19,5 @@ type VotePoll struct { DeadlineTime *gtime.Time // 截止时间 CreateTime *gtime.Time // Status interface{} // 投票活动状态:1:进行中,0已结束 + UpdateTime *gtime.Time // } diff --git a/internal/model/do/vote_record.go b/internal/model/do/vote_record.go index e791ae9..26a7058 100644 --- a/internal/model/do/vote_record.go +++ b/internal/model/do/vote_record.go @@ -18,4 +18,5 @@ type VoteRecord struct { OptionId interface{} // CreateTime *gtime.Time // VoteIndex interface{} // + UpdateTime *gtime.Time // } diff --git a/internal/model/entity/article.go b/internal/model/entity/article.go new file mode 100644 index 0000000..0b7ff15 --- /dev/null +++ b/internal/model/entity/article.go @@ -0,0 +1,20 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package entity + +import ( + "github.com/gogf/gf/v2/os/gtime" +) + +// 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:""` // + 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不发起 + CreateTime *gtime.Time `json:"createTime" orm:"create_time" description:""` // + UpdateTime *gtime.Time `json:"updateTime" orm:"update_time" description:""` // +} diff --git a/internal/model/entity/user.go b/internal/model/entity/user.go index f82904f..3dbd830 100644 --- a/internal/model/entity/user.go +++ b/internal/model/entity/user.go @@ -14,6 +14,7 @@ type User struct { Account string `json:"account" orm:"account" description:""` // Password string `json:"password" orm:"password" description:""` // Username string `json:"username" orm:"username" description:""` // - Status int `json:"status" orm:"status" 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 46eec2d..48864fc 100644 --- a/internal/model/entity/vote_option.go +++ b/internal/model/entity/vote_option.go @@ -4,10 +4,15 @@ package entity +import ( + "github.com/gogf/gf/v2/os/gtime" +) + // 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 int `json:"status" orm:"status" 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:"选项内容"` // 选项内容 + Status uint `json:"status" orm:"status" description:"选项状态"` // 选项状态 + 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 a63276f..450ceab 100644 --- a/internal/model/entity/vote_poll.go +++ b/internal/model/entity/vote_poll.go @@ -17,4 +17,5 @@ type VotePoll struct { 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:""` // } diff --git a/internal/model/entity/vote_record.go b/internal/model/entity/vote_record.go index 7537384..a11c458 100644 --- a/internal/model/entity/vote_record.go +++ b/internal/model/entity/vote_record.go @@ -16,4 +16,5 @@ type VoteRecord struct { 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:""` // }