service

package
v0.0.0-...-8406b6b Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	ID            uint32     `json:"id"`
	Title         string     `json:"title"`
	Desc          string     `json:"desc"`
	Content       string     `json:"content"`
	CoverImageUrl string     `json:"cover_image_url"`
	State         uint8      `json:"state"`
	Tag           *model.Tag `json:"tag"`
}

type ArticleListRequest

type ArticleListRequest struct {
	TagID uint32 `form:"tag_id" binding:"gte=1"`
	State uint8  `form:"state,default=1" binding:"oneof=0 1"`
}

type ArticleRequest

type ArticleRequest struct {
	ID    uint32 `form:"id" binding:"required,gte=1"`
	State uint8  `form:"state,default=1" binding:"oneof=0 1"`
}

type AuthRequest

type AuthRequest struct {
	AppKey    string `header:"app_key" binding:"required"`
	AppSecret string `header:"app_secret" binding:"required"`
}

type CountTagRequest

type CountTagRequest struct {
	Name  string `form:"name" binding:"max=100"`
	State uint8  `form:"state,default=1" binding:"oneof=0 1"`
}

CountTagRequest 定义了 Request 结构体作为接口入参的基准,而本项目由于并不会太复杂,所以直接放在了 service 层中便于使用 若后续业务不断增长,程序越来越复杂,service 也冗杂了,可以考虑将抽离一层接口校验层,便于解耦逻辑。

type CreateArticleRequest

type CreateArticleRequest struct {
	TagID         uint32 `form:"tag_id" binding:"required,gte=1"`
	Title         string `form:"title" binding:"required,min=2,max=100"`
	Desc          string `form:"desc" binding:"required,min=2,max=255"`
	Content       string `form:"content" binding:"required,min=2,max=4294967295"`
	CoverImageUrl string `form:"cover_image_url" binding:"required,url"`
	CreatedBy     string `form:"created_by" binding:"required,min=2,max=100"`
	State         uint8  `form:"state,default=1" binding:"oneof=0 1"`
}

type CreateTagRequest

type CreateTagRequest struct {
	Name      string `form:"name" json:"name" binding:"required,min=2,max=100" `            // 标签名称
	CreatedBy string `form:"created_by" json:"created_by" binding:"required,min=2,max=100"` //创建者
	State     uint8  `form:"state,default=1" json:"state" binding:"oneof=0 1"`              //状态,是否启用(0 为禁用、1 为启用)
}

type DeleteArticleRequest

type DeleteArticleRequest struct {
	ID uint32 `form:"id" binding:"required,gte=1"`
}

type DeleteTagRequest

type DeleteTagRequest struct {
	ID uint32 `form:"id" binding:"required,gte=1"`
}

type FileInfo

type FileInfo struct {
	Name      string
	AccessUrl string
}

type Service

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

func New

func New(ctx context.Context) Service

New 所有Service都走这里的逻辑

func (*Service) CheckAuth

func (svc *Service) CheckAuth(param *AuthRequest) error

CheckAuth 查询数据库只为了校验是否存在这条记录

func (*Service) CountTag

func (svc *Service) CountTag(param *CountTagRequest) (int, error)

func (*Service) CreateTag

func (svc *Service) CreateTag(param *CreateTagRequest) error

func (*Service) DeleteTag

func (svc *Service) DeleteTag(param *DeleteTagRequest) error

func (*Service) GetTagList

func (svc *Service) GetTagList(param *TagListRequest, pager *app.Pager) ([]*model.Tag, error)

func (*Service) UpdateTag

func (svc *Service) UpdateTag(param *UpdateTagRequest) error

func (*Service) UploadFile

func (svc *Service) UploadFile(fileType upload.FileType, file multipart.File, fileHeader *multipart.FileHeader) (*FileInfo, error)

type TagListRequest

type TagListRequest struct {
	Name  string `form:"name" binding:"max=100"`
	State uint8  `form:"state,default=1" binding:"oneof=0 1"`
}

type UpdateArticleRequest

type UpdateArticleRequest struct {
	ID            uint32 `form:"id" binding:"required,gte=1"`
	TagID         uint32 `form:"tag_id" binding:"required,gte=1"`
	Title         string `form:"title" binding:"min=2,max=100"`
	Desc          string `form:"desc" binding:"min=2,max=255"`
	Content       string `form:"content" binding:"min=2,max=4294967295"`
	CoverImageUrl string `form:"cover_image_url" binding:"url"`
	ModifiedBy    string `form:"modified_by" binding:"required,min=2,max=100"`
	State         uint8  `form:"state,default=1" binding:"oneof=0 1"`
}

type UpdateTagRequest

type UpdateTagRequest struct {
	ID         uint32 `form:"id" binding:"required,gte=1"`                  // 标签id
	Name       string `form:"name" binding:"max=100"`                       // 标签名称
	State      *uint8 `form:"state" binding:"omitempty,oneof=0 1"`          //状态,是否启用(0 为禁用、1 为启用)
	ModifiedBy string `form:"modified_by" binding:"required,min=2,max=100"` // 修改者
}

Jump to

Keyboard shortcuts

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