project

package
v1.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoPermission       = "无权限"
	AlreadyReceived    = "已有用户领取,不允许删除"
	TimeTooEarly       = "未到开启时间"
	TimeTooLate        = "已经结束"
	TrustLevelNotMatch = "需要信任等级 %d"
	UnknownError       = "未知异常"
	SameIPReceived     = "已有相同IP领取"
	NoStock            = "无库存"
	NotFound           = "项目不存在"
	AlreadyReported    = "已举报过当前项目"
)

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 @Params request query ListProjectsRequest true "request query" @Produce json @Success 200 {object} ListProjectsResponse @Router /api/v1/projects/mine [get]

func ListProjects

func ListProjects(c *gin.Context)

ListProjects @Tags project @Params 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 @Params request query ListReceiveHistoryRequest true "request query" @Produce json @Success 200 {object} ListReceiveHistoryResponse @Router /api/v1/projects/received [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 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 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"`
}

type DistributionType

type DistributionType int8
const (
	DistributionTypeOneForEach DistributionType = iota
	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 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"`
	Tags              utils.StringArray `json:"tags"`
	CreatedAt         time.Time         `json:"created_at"`
}

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"`
}

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"`
	Creator           oauth.User       `json:"-" gorm:"foreignKey:CreatorID"`
	CreatedAt         time.Time        `json:"created_at" gorm:"autoCreateTime"`
	UpdatedAt         time.Time        `json:"updated_at" gorm:"autoUpdateTime"`
}

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) error

func (*Project) Exact

func (p *Project) Exact(tx *gorm.DB, id string, isNormal bool) 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, user *oauth.User, ip string) error

func (*Project) ItemsKey

func (p *Project) ItemsKey() string

func (*Project) PrepareReceive

func (p *Project) PrepareReceive(ctx context.Context) (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"`
}

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"`
}

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 ReportProjectRequestBody

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

type UpdateProjectRequestBody

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

Jump to

Keyboard shortcuts

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