item

package
v0.0.0-...-911e024 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxBooksOncePerItem = 10 // 设定每个 Item 可以关联的最大 Books 数量
	MaxTagsOncePerItem  = 5  // 设定每个 Item 可以拥有的最大 Tags 数量
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ReqCreateItem

type ReqCreateItem struct {
	Type       string              `json:"type"`
	Content    string              `json:"content"`
	Difficulty def.DifficultyLevel `json:"difficulty,omitempty"` // 难度,默认值为 NoviceNormal (0x01), todo: 考虑是否允许用户编辑,编辑后要引入写扩散
	Importance def.ImportanceLevel `json:"importance,omitempty"` // 重要程度,默认值为 DomainGeneral (0x01), todo: 考虑是否允许用户编辑
	BookIDs    []utils.UInt64      `json:"book_ids,omitempty"`   // 用于接收一个或多个 BookID
	Tags       []string            `json:"tags,omitempty"`       // 新增字段,用于接收一组 Tag 名称
}

type ReqGetItems

type ReqGetItems struct {
	UserID utils.UInt64 `form:"user_id" json:"user_id,omitempty"`
	BookID utils.UInt64 `form:"book_id" json:"book_id,omitempty"`
	Type   string       `form:"type" json:"type,omitempty"`
	Search string       `form:"search" json:"search,omitempty"`
}

type ReqUpdateItem

type ReqUpdateItem struct {
	Type       string              `json:"type,omitempty"`
	Content    string              `json:"content,omitempty"`
	Difficulty def.DifficultyLevel `json:"difficulty,omitempty"` // 难度,默认值为 NoviceNormal (0x01)
	Importance def.ImportanceLevel `json:"importance,omitempty"` // 重要程度,默认值为 DomainGeneral (0x01)
	Tags       []string            `json:"tags,omitempty"`       // 新增字段
}

type ReqUploadItems

type ReqUploadItems struct {
	BookID *utils.UInt64 `form:"book_id,omitempty"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(repo *gorm.DB) *Service

NewService creates a new service instance with dependencies wired in.

func (*Service) ApplyMux

func (svr *Service) ApplyMux(group gin.IRouter)

func (*Service) CreateItem

func (svr *Service) CreateItem(c *gin.Context)

CreateItem handles creating a new item with optional book affiliations and tags. @Summary Create a new item @Description Create a new item in the system with optional book affiliations and tags. @Tags item @Accept json @Produce json @Param item body ReqCreateItem true "Item creation data" @Success 201 {object} dto.RespItemCreate "Successfully created item with books and tags" @Failure 400 {object} utils.ErrorResponse "Bad Request if too many books or tags, or bad data" @Router /items [post]

func (*Service) DeleteItem

func (svr *Service) DeleteItem(c *gin.Context)

DeleteItem handles the deletion of an item. @Summary Delete an item @Description Delete an item from the system by ID. @Tags item @Accept json @Produce json @Param id path uint64 true "Item ID" @Success 200 {object} dto.RespItemDelete "Successfully deleted item" @Failure 400 {object} utils.ErrorResponse "Bad Request" @Router /items/{id} [delete]

func (*Service) GetItems

func (svr *Service) GetItems(c *gin.Context)

GetItems handles retrieving a list of items with optional filters and pagination. @Summary Get a list of items with optional filters @Description Get a list of items for the user with optional filters for book and type and support for pagination. @Tags item @Accept json @Produce json @Param user_id query uint64 false "User ID" @Param type query string false "Type of item" @Param page query int false "Page number for pagination" @Param limit query int false "Number of items per page" @Success 200 {object} dto.RespItemList "Successfully retrieved items" @Failure 400 {object} utils.ErrorResponse "Bad Request" @Router /items [get]

func (*Service) ReadItem

func (svr *Service) ReadItem(c *gin.Context)

ReadItem handles retrieving a single item by ID, including its tags. @Summary Get an item by ID @Description Get detailed information about an item, including its tags. @Tags item @Accept json @Produce json @Param id path uint64 true "Item ID" @Success 200 {object} dto.RespItemGet "Successfully retrieved item with tags" @Failure 400 {object} utils.ErrorResponse "Bad Request" @Router /items/{id} [get]

func (*Service) UpdateItem

func (svr *Service) UpdateItem(c *gin.Context)

UpdateItem handles updating an existing item's information and associated tags. @Summary Update an item @Description Update an item's type, content, or associated tags. @Tags item @Accept json @Produce json @Param id path uint64 true "Item ID" @Param item body ReqUpdateItem true "Item update data" @Success 200 {object} dto.RespItemUpdate "the updater" @Failure 400 {object} utils.ErrorResponse "Bad Request with invalid item ID or update data" @Failure 500 {object} utils.ErrorResponse "Internal Server Error with failing to update the item" @Router /items/{id} [put]

func (*Service) UploadItems

func (svr *Service) UploadItems(c *gin.Context)

UploadItems handles uploading a file to create multiple items. @Summary Upload items from a file @Description Upload a file to create multiple items in the system. @Tags item @Accept multipart/form-data @Produce json @Param file formData file true "File containing items data, support csv and toml file" @Param book_id query string false "Book ID" @Success 201 {object} dto.RespItemList "Successfully created items from file" @Failure 400 {object} utils.ErrorResponse "Bad Request" @Router /items/upload [post]

Jump to

Keyboard shortcuts

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