Browse Source

gf框架搭建

master
maziyang 2 weeks ago
parent
commit
edfb5f9fb6
  1. 13
      internal/consts/vote.go
  2. 22
      internal/dao/article.go
  3. 91
      internal/dao/internal/article.go
  4. 2
      internal/dao/internal/user.go
  5. 2
      internal/dao/internal/vote_option.go
  6. 2
      internal/dao/internal/vote_poll.go
  7. 2
      internal/dao/internal/vote_record.go
  8. 22
      internal/model/do/article.go
  9. 1
      internal/model/do/user.go
  10. 2
      internal/model/do/vote_option.go
  11. 1
      internal/model/do/vote_poll.go
  12. 1
      internal/model/do/vote_record.go
  13. 20
      internal/model/entity/article.go
  14. 3
      internal/model/entity/user.go
  15. 13
      internal/model/entity/vote_option.go
  16. 1
      internal/model/entity/vote_poll.go
  17. 1
      internal/model/entity/vote_record.go

13
internal/consts/vote.go

@ -0,0 +1,13 @@
package consts
// 投票活动状态
const (
VoteStatusGoing = 1 //进行中
VoteStatusEnded = 0 //已结束
)
// 投票类型
const (
VoteTypeSingle = 0 //单选
VoteTypeMultiple = 1 //多选
)

22
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.

91
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)
}

2
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.

2
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.

2
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.

2
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.

22
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 //
}

1
internal/model/do/user.go

@ -18,4 +18,5 @@ type User struct {
Username interface{} //
Status interface{} //
CreateTime *gtime.Time //
UpdateTime *gtime.Time //
}

2
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 //
}

1
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 //
}

1
internal/model/do/vote_record.go

@ -18,4 +18,5 @@ type VoteRecord struct {
OptionId interface{} //
CreateTime *gtime.Time //
VoteIndex interface{} //
UpdateTime *gtime.Time //
}

20
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:""` //
}

3
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:""` //
}

13
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:""` //
}

1
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:""` //
}

1
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:""` //
}
Loading…
Cancel
Save