project

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoPermission       = "无权限"
	AlreadyReceived    = "已有用户领取,不允许删除"
	TimeTooEarly       = "未到开启时间"
	TimeTooLate        = "已经结束"
	TrustLevelNotMatch = "需要信任等级 %d"
	UnknownError       = "未知异常"
	ScoreNotEnough     = "分数未达标"
	SameIPReceived     = "已有相同IP领取"
	NoStock            = "无库存"
	NotFound           = "项目不存在"
	AlreadyReported    = "已举报过当前项目"
	RequirementsFailed = "未达到项目发起者设置的条件"
	TooManyRequests    = "创建项目太频繁,请稍后再试"
)
View Source
const (
	ProjectObjKey = "project_obj"
)

Variables

This section is empty.

Functions

func CreateProject

func CreateProject(c *gin.Context)

CreateProject @Tags project @Accept json @Produce json @Param project body CreateProjectRequestBody true "项目信息" @Success 200 {object} ProjectResponse @Router /api/v1/projects [post]

func DeleteProject

func DeleteProject(c *gin.Context)

DeleteProject @Tags project @Accept json @Produce json @Param id path string true "项目ID" @Success 200 {object} ProjectResponse @Router /api/v1/projects/{id} [delete]

func GetProject

func GetProject(c *gin.Context)

GetProject @Tags project @Summary 获取指定项目信息 (Get specific project information) @Description 获取指定项目所有信息以及领取情况 (Get all information and claim status for a specific project) @Produce json @Param id path string true "项目ID (Project ID)" @Success 200 {object} ProjectResponse{data=GetProjectResponseData} @Router /api/v1/projects/{id} [get]

func ListMyProjects

func ListMyProjects(c *gin.Context)

ListMyProjects @Tags project @Param request query ListProjectsRequest true "request query" @Produce json @Success 200 {object} ListProjectsResponse @Router /api/v1/projects/mine [get]

func ListProjectReceivers

func ListProjectReceivers(c *gin.Context)

ListProjectReceivers @Tags project @Accept json @Produce json @Param id path string true "项目ID (Project ID)" @Param request query ListProjectReceiversRequest true "request query" @Success 200 {object} ProjectResponse @Router /api/v1/projects/{id}/receivers [get]

func ListProjects

func ListProjects(c *gin.Context)

ListProjects @Tags project @Param request query ListProjectsRequest true "request query" @Produce json @Success 200 {object} ListProjectsResponse @Router /api/v1/projects [get]

func ListReceiveHistory

func ListReceiveHistory(c *gin.Context)

ListReceiveHistory @Tags project @Param request query ListReceiveHistoryRequest true "request query" @Produce json @Success 200 {object} ListReceiveHistoryResponse @Router /api/v1/projects/received [get]

func ListReceiveHistoryChart

func ListReceiveHistoryChart(c *gin.Context)

ListReceiveHistoryChart @Tags project @Param request query ListReceiveHistoryChartRequest true "request query" @Produce json @Success 200 {object} ListReceiveHistoryChartResponse @Router /api/v1/projects/received/chart [get]

func ListTags

func ListTags(c *gin.Context)

ListTags @Tags project @Accept json @Produce json @Success 200 {object} ListTagsResponse @Router /api/v1/tags [get]

func ProjectCreateRateLimitMiddleware

func ProjectCreateRateLimitMiddleware() gin.HandlerFunc

func ProjectCreatorPermMiddleware

func ProjectCreatorPermMiddleware() gin.HandlerFunc

func ReceiveProject

func ReceiveProject(c *gin.Context)

ReceiveProject @Tags project @Accept json @Produce json @Param id path string true "project id" @Success 200 {object} ProjectResponse @Router /api/v1/projects/{id}/receive [post]

func ReceiveProjectMiddleware

func ReceiveProjectMiddleware() gin.HandlerFunc

func ReportProject

func ReportProject(c *gin.Context)

ReportProject @Tags project @Accept json @Produce json @Param id path string true "项目ID" @Param project body ReportProjectRequestBody true "举报信息" @Success 200 {object} ProjectResponse @Router /api/v1/projects/{id}/report [post]

func SetProjectToContext

func SetProjectToContext(c *gin.Context, project *Project)

SetProjectToContext 将Project对象存储到Context中

func UpdateProject

func UpdateProject(c *gin.Context)

UpdateProject @Tags project @Accept json @Produce json @Param id path string true "项目ID" @Param project body UpdateProjectRequestBody true "项目信息" @Success 200 {object} ProjectResponse @Router /api/v1/projects/{id} [put]

Types

type CreateProjectRequestBody

type CreateProjectRequestBody struct {
	ProjectRequest
	DistributionType DistributionType `json:"distribution_type" binding:"oneof=0 1"`
	ProjectItems     []string         `json:"project_items" binding:"required,min=1,dive,min=1,max=1024"`
	TopicId          uint64           `json:"topic_id" binding:"omitempty,gt=0"`
}

type DistributionType

type DistributionType int8
const (
	DistributionTypeOneForEach DistributionType = iota
	DistributionTypeLottery
	DistributionTypeInvite
)

type GetProjectResponseData

type GetProjectResponseData struct {
	Project             `json:",inline"` // 内嵌所有 Project 字段
	CreatorUsername     string           `json:"creator_username"`
	CreatorNickname     string           `json:"creator_nickname"`
	Tags                []string         `json:"tags"`
	AvailableItemsCount int64            `json:"available_items_count"`
	IsReceived          bool             `json:"is_received"`
	ReceivedContent     string           `json:"received_content"`
}

type ListProjectReceiversRequest

type ListProjectReceiversRequest struct {
	Current int    `json:"current" form:"current" binding:"min=1"`
	Size    int    `json:"size" form:"size" binding:"min=1,max=100"`
	Search  string `json:"search" form:"search" binding:"max=1024"`
}

type ListProjectsRequest

type ListProjectsRequest struct {
	Current int      `json:"current" form:"current" binding:"min=1"`
	Size    int      `json:"size" form:"size" binding:"min=1,max=100"`
	Tags    []string `json:"tags" form:"tags" binding:"dive,min=1,max=16"`
}

type ListProjectsResponse

type ListProjectsResponse struct {
	ErrorMsg string                    `json:"error_msg"`
	Data     *ListProjectsResponseData `json:"data"`
}

type ListProjectsResponseData

type ListProjectsResponseData struct {
	Total   int64                             `json:"total"`
	Results *[]ListProjectsResponseDataResult `json:"results"`
}

func ListMyProjectsWithTags

func ListMyProjectsWithTags(ctx context.Context, creatorID uint64, offset, limit int, tags []string) (*ListProjectsResponseData, error)

ListMyProjectsWithTags 查询我创建的项目列表及其标签

func ListProjectsWithTags

func ListProjectsWithTags(ctx context.Context, offset, limit int, tags []string, currentUser *oauth.User) (*ListProjectsResponseData, error)

ListProjectsWithTags 查询未结束的项目列表及其标签

type ListProjectsResponseDataResult

type ListProjectsResponseDataResult struct {
	ID                string            `json:"id"`
	Name              string            `json:"name"`
	Description       string            `json:"description"`
	DistributionType  DistributionType  `json:"distribution_type"`
	TotalItems        int64             `json:"total_items"`
	StartTime         time.Time         `json:"start_time"`
	EndTime           time.Time         `json:"end_time"`
	MinimumTrustLevel oauth.TrustLevel  `json:"minimum_trust_level"`
	AllowSameIP       bool              `json:"allow_same_ip"`
	RiskLevel         int8              `json:"risk_level"`
	HideFromExplore   bool              `json:"hide_from_explore"`
	Tags              utils.StringArray `json:"tags"`
	CreatedAt         time.Time         `json:"created_at"`
}

type ListReceiveHistoryChartRequest

type ListReceiveHistoryChartRequest struct {
	Day int `json:"day" form:"day" binding:"min=1,max=180"`
}

type ListReceiveHistoryChartResponse

type ListReceiveHistoryChartResponse struct {
	ErrorMsg string                     `json:"error_msg"`
	Data     []ReceiveHistoryChartPoint `json:"data"`
}

type ListReceiveHistoryRequest

type ListReceiveHistoryRequest struct {
	Current int    `json:"current" form:"current" binding:"min=1"`
	Size    int    `json:"size" form:"size" binding:"min=1,max=100"`
	Search  string `json:"search" form:"search" binding:"max=255"`
}

type ListReceiveHistoryResponse

type ListReceiveHistoryResponse struct {
	ErrorMsg string                         `json:"error_msg"`
	Data     ListReceiveHistoryResponseData `json:"data"`
}

type ListReceiveHistoryResponseData

type ListReceiveHistoryResponseData struct {
	Total   int64                                  `json:"total"`
	Results []ListReceiveHistoryResponseDataResult `json:"results"`
}

type ListReceiveHistoryResponseDataResult

type ListReceiveHistoryResponseDataResult struct {
	ProjectID              string     `json:"project_id"`
	ProjectName            string     `json:"project_name"`
	ProjectCreator         string     `json:"project_creator"`
	ProjectCreatorNickname string     `json:"project_creator_nickname"`
	Content                string     `json:"content"`
	ReceivedAt             *time.Time `json:"received_at"`
}

type ListTagsResponse

type ListTagsResponse struct {
	ErrorMsg string   `json:"error_msg"`
	Data     []string `json:"data"`
}

type Project

type Project struct {
	ID                string           `json:"id" gorm:"primaryKey;size:64"`
	Name              string           `json:"name" gorm:"size:32"`
	Description       string           `json:"description" gorm:"size:1024"`
	DistributionType  DistributionType `json:"distribution_type"`
	TotalItems        int64            `json:"total_items"`
	StartTime         time.Time        `json:"start_time"`
	EndTime           time.Time        `json:"end_time" gorm:"index:idx_projects_end_completed_trust_risk,priority:1"`
	MinimumTrustLevel oauth.TrustLevel `json:"minimum_trust_level" gorm:"index:idx_projects_end_completed_trust_risk,priority:4"`
	AllowSameIP       bool             `json:"allow_same_ip"`
	RiskLevel         int8             `json:"risk_level" gorm:"index:idx_projects_end_completed_trust_risk,priority:5"`
	CreatorID         uint64           `json:"creator_id" gorm:"index"`
	IsCompleted       bool             `json:"is_completed" gorm:"index:idx_projects_end_completed_trust_risk,priority:2"`
	Status            ProjectStatus    `json:"status" gorm:"default:0;index;index:idx_projects_end_completed_trust_risk,priority:3"`
	ReportCount       uint8            `json:"report_count" gorm:"default:0"`
	HideFromExplore   bool             `json:"hide_from_explore" gorm:"default:false"`
	Creator           oauth.User       `json:"-" gorm:"foreignKey:CreatorID"`
	CreatedAt         time.Time        `json:"created_at" gorm:"autoCreateTime"`
	UpdatedAt         time.Time        `json:"updated_at" gorm:"autoUpdateTime"`
}

func GetProjectFromContext

func GetProjectFromContext(c *gin.Context) (*Project, bool)

GetProjectFromContext 从Context中获取Project对象

func (*Project) CheckSameIPReceived

func (p *Project) CheckSameIPReceived(ctx context.Context, ip string) (bool, error)

func (*Project) CreateItems

func (p *Project) CreateItems(ctx context.Context, tx *gorm.DB, items []string, userName string, topicId uint64) error

func (*Project) CreateItemsWithFilter

func (p *Project) CreateItemsWithFilter(ctx context.Context, tx *gorm.DB, items []string, enableFilter bool) error

func (*Project) Exact

func (p *Project) Exact(tx *gorm.DB, id string, isNormal bool) error

func (*Project) GetFilteredItemsCount

func (p *Project) GetFilteredItemsCount(ctx context.Context, tx *gorm.DB, items []string, enableFilter bool) (int64, error)

func (*Project) GetReceivedItem

func (p *Project) GetReceivedItem(ctx context.Context, userID uint64) (*ProjectItem, error)

func (*Project) GetTags

func (p *Project) GetTags(tx *gorm.DB) ([]string, error)

GetTags retrieves all tags associated with the project.

func (*Project) HasStock

func (p *Project) HasStock(ctx context.Context) (bool, error)

func (*Project) IsReceivable

func (p *Project) IsReceivable(ctx context.Context, now time.Time, user *oauth.User, ip string) error

func (*Project) ItemsKey

func (p *Project) ItemsKey() string

func (*Project) PrepareReceive

func (p *Project) PrepareReceive(ctx context.Context, userName string) (uint64, error)

func (*Project) RefreshTags

func (p *Project) RefreshTags(tx *gorm.DB, tags []string) error

func (*Project) SameIPCacheKey

func (p *Project) SameIPCacheKey(ip string) string

func (*Project) Stock

func (p *Project) Stock(ctx context.Context) (int64, error)

type ProjectItem

type ProjectItem struct {
	ID         uint64      `json:"id" gorm:"primaryKey,autoIncrement"`
	ProjectID  string      `json:"project_id" gorm:"size:64;index;uniqueIndex:idx_project_receiver"`
	Project    Project     `json:"-" gorm:"foreignKey:ProjectID"`
	ReceiverID *uint64     `json:"receiver_id" gorm:"index;uniqueIndex:idx_project_receiver"`
	Receiver   *oauth.User `json:"-" gorm:"foreignKey:ReceiverID"`
	Content    string      `json:"content" gorm:"size:1024"`
	CreatedAt  time.Time   `json:"created_at" gorm:"autoCreateTime"`
	UpdatedAt  time.Time   `json:"updated_at" gorm:"autoUpdateTime"`
	ReceivedAt *time.Time  `json:"received_at" gorm:"index"`
}

func (*ProjectItem) Exact

func (p *ProjectItem) Exact(tx *gorm.DB, id uint64) error

type ProjectReport

type ProjectReport struct {
	ID         uint64    `json:"id" gorm:"primaryKey,autoIncrement"`
	ProjectID  string    `json:"project_id" gorm:"size:64;index;uniqueIndex:idx_project_reporter"`
	ReporterID uint64    `json:"reporter_id" gorm:"index;uniqueIndex:idx_project_reporter"`
	Reason     string    `json:"reason" gorm:"size:255"`
	CreatedAt  time.Time `json:"created_at" gorm:"autoCreateTime"`
	UpdatedAt  time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}

type ProjectRequest

type ProjectRequest struct {
	Name              string           `json:"name" binding:"required,min=1,max=32"`
	Description       string           `json:"description" binding:"max=1024"`
	ProjectTags       []string         `json:"project_tags" binding:"dive,min=1,max=16"`
	StartTime         time.Time        `json:"start_time" binding:"required"`
	EndTime           time.Time        `json:"end_time" binding:"required,gtfield=StartTime"`
	MinimumTrustLevel oauth.TrustLevel `json:"minimum_trust_level" binding:"oneof=0 1 2 3 4"`
	AllowSameIP       bool             `json:"allow_same_ip"`
	RiskLevel         int8             `json:"risk_level" binding:"min=0,max=100"`
	HideFromExplore   bool             `json:"hide_from_explore"`
}

type ProjectResponse

type ProjectResponse struct {
	ErrorMsg string      `json:"error_msg"`
	Data     interface{} `json:"data"`
}

type ProjectStatus

type ProjectStatus uint8
const (
	ProjectStatusNormal ProjectStatus = iota
	ProjectStatusHidden
	ProjectStatusViolation
)

type ProjectTag

type ProjectTag struct {
	ID        uint64  `json:"id" gorm:"primaryKey,autoIncrement"`
	ProjectID string  `json:"project_id" gorm:"size:64;index;uniqueIndex:idx_project_tag"`
	Project   Project `json:"-" gorm:"foreignKey:ProjectID"`
	Tag       string  `json:"tag" gorm:"size:16;index;uniqueIndex:idx_project_tag"`
}

type ProjectWithTags

type ProjectWithTags struct {
	Project
	Tags string `gorm:"column:tags"`
}

ProjectWithTags 返回项目及其标签

type ProjectsPage

type ProjectsPage struct {
	Total int64
	Items []ProjectWithTags
}

ProjectsPage 返回分页的项目列表及其标签

type ReceiveHistoryChartPoint

type ReceiveHistoryChartPoint struct {
	Date  string `json:"date"`
	Label string `json:"label"`
	Count int64  `json:"count"`
}

type ReportProjectRequestBody

type ReportProjectRequestBody struct {
	Reason string `json:"reason" binding:"required,min=1,max=255"`
}

type TopicResponse

type TopicResponse struct {
	HighestPostNumber uint       `json:"highest_post_number"`
	Tags              []TopicTag `json:"tags"`
	Closed            bool       `json:"closed"`
}

type TopicTag

type TopicTag struct {
	Id   int    `json:"id"`
	Name string `json:"name"`
	Slug string `json:"slug"`
}

type UpdateProjectRequestBody

type UpdateProjectRequestBody struct {
	ProjectRequest
	ProjectItems []string `json:"project_items" binding:"dive,min=1,max=1024"`
	EnableFilter bool     `json:"enable_filter"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL