Documentation
¶
Index ¶
- Constants
- func CreateProject(c *gin.Context)
- func DeleteProject(c *gin.Context)
- func GetProject(c *gin.Context)
- func ListMyProjects(c *gin.Context)
- func ListProjects(c *gin.Context)
- func ListReceiveHistory(c *gin.Context)
- func ListTags(c *gin.Context)
- func ProjectCreatorPermMiddleware() gin.HandlerFunc
- func ReceiveProject(c *gin.Context)
- func ReceiveProjectMiddleware() gin.HandlerFunc
- func ReportProject(c *gin.Context)
- func UpdateProject(c *gin.Context)
- type CreateProjectRequestBody
- type DistributionType
- type GetProjectResponseData
- type ListProjectsRequest
- type ListProjectsResponse
- type ListProjectsResponseData
- type ListProjectsResponseDataResult
- type ListReceiveHistoryRequest
- type ListReceiveHistoryResponse
- type ListReceiveHistoryResponseData
- type ListReceiveHistoryResponseDataResult
- type ListTagsResponse
- type Project
- func (p *Project) CheckSameIPReceived(ctx context.Context, ip string) (bool, error)
- func (p *Project) CreateItems(ctx context.Context, tx *gorm.DB, items []string) error
- func (p *Project) Exact(tx *gorm.DB, id string, isNormal bool) error
- func (p *Project) GetReceivedItem(ctx context.Context, userID uint64) (*ProjectItem, error)
- func (p *Project) GetTags(tx *gorm.DB) ([]string, error)
- func (p *Project) HasStock(ctx context.Context) (bool, error)
- func (p *Project) IsReceivable(ctx context.Context, user *oauth.User, ip string) error
- func (p *Project) ItemsKey() string
- func (p *Project) PrepareReceive(ctx context.Context) (uint64, error)
- func (p *Project) RefreshTags(tx *gorm.DB, tags []string) error
- func (p *Project) SameIPCacheKey(ip string) string
- func (p *Project) Stock(ctx context.Context) (int64, error)
- type ProjectItem
- type ProjectReport
- type ProjectRequest
- type ProjectResponse
- type ProjectStatus
- type ProjectTag
- type ProjectWithTags
- type ProjectsPage
- type ReportProjectRequestBody
- type UpdateProjectRequestBody
Constants ¶
const ( NoPermission = "无权限" AlreadyReceived = "已有用户领取,不允许删除" TimeTooEarly = "未到开启时间" TimeTooLate = "已经结束" TrustLevelNotMatch = "需要信任等级 %d" UnknownError = "未知异常" SameIPReceived = "已有相同IP领取" NoStock = "无库存" NotFound = "项目不存在" AlreadyReported = "已举报过当前项目" )
Variables ¶
This section is empty.
Functions ¶
func CreateProject ¶
CreateProject @Tags project @Accept json @Produce json @Param project body CreateProjectRequestBody true "项目信息" @Success 200 {object} ProjectResponse @Router /api/v1/projects [post]
func DeleteProject ¶
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 ¶
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 ¶
ListMyProjects @Tags project @Params request query ListProjectsRequest true "request query" @Produce json @Success 200 {object} ListProjectsResponse @Router /api/v1/projects/mine [get]
func ListProjects ¶
ListProjects @Tags project @Params request query ListProjectsRequest true "request query" @Produce json @Success 200 {object} ListProjectsResponse @Router /api/v1/projects [get]
func ListReceiveHistory ¶
ListReceiveHistory @Tags project @Params request query ListReceiveHistoryRequest true "request query" @Produce json @Success 200 {object} ListReceiveHistoryResponse @Router /api/v1/projects/received [get]
func ListTags ¶
ListTags @Tags project @Accept json @Produce json @Success 200 {object} ListTagsResponse @Router /api/v1/tags [get]
func ProjectCreatorPermMiddleware ¶
func ProjectCreatorPermMiddleware() gin.HandlerFunc
func ReceiveProject ¶
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 ¶
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 ¶
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 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 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 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 (*Project) CreateItems ¶
func (*Project) GetReceivedItem ¶
func (*Project) IsReceivable ¶
func (*Project) PrepareReceive ¶
func (*Project) SameIPCacheKey ¶
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"` }
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 ProjectWithTags ¶
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"` }