service

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2020 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPageSlugExist added in v0.3.0

func CheckPageSlugExist(pageID uint64, slug string) bool

CheckPageSlugExist check if page slug name exist

func CheckSubjectNameExist added in v0.3.0

func CheckSubjectNameExist(subjectID uint64, name string) bool

CheckSubjectNameExist check the subject name

func CheckTaxonomyNameExist added in v0.3.0

func CheckTaxonomyNameExist(name, taxonomy string) bool

CheckTaxonomyNameExist check if taxonomy name are aleady exist

func CreateSubject added in v0.3.0

func CreateSubject(r *SubjectCreateRequest) error

CreateSubject create a subject

func CreateTaxonomy added in v0.3.0

func CreateTaxonomy(r *TaxonomyCreateRequest) error

CreateTaxonomy create term taxonomy

func CreateUser added in v0.3.0

func CreateUser(u *UserCreateRequest) (string, string, error)

CreateUser create a new user

func DeleteMedia added in v0.3.0

func DeleteMedia(userID uint64) error

DeleteMedia delete media

func DeletePost

func DeletePost(postType string, articleID uint64) error

DeletePost delete post by soft delete Note: meta data was reserved

func DeleteSubject

func DeleteSubject(subjectID uint64) error

DeleteSubject delete subject directly

func DeleteTaxonomy

func DeleteTaxonomy(termID uint64, taxonomyType string) error

DeleteTaxonomy delete term directly

func DeleteUser added in v0.3.0

func DeleteUser(userID int) error

DeleteUser delete user by ID

func GetArticleSubejctID added in v0.3.0

func GetArticleSubejctID(articleID uint64) ([]uint64, error)

GetArticleSubejct get article's subject by article id

func GetDefaultOptionNamesByType added in v0.3.0

func GetDefaultOptionNamesByType(settingType string) []string

GetDefaultOptionsByType get default setting's option name

func GetMediaByID added in v0.3.0

func GetMediaByID(ID uint64) (*model.Media, error)

GetMediaByID get media by ID

func GetOptionsByType

func GetOptionsByType(settingType string) (map[string]string, error)

GetOptionsByType get default options by setting type

func IfTaxonomyHasChild

func IfTaxonomyHasChild(termID uint64, taxonomyType string) (bool, error)

IfTaxonomyHasChild check the taxonomy has children or not

func RestorePost

func RestorePost(postID uint64) error

RestorePost restore the post which had been put to the trash this restore action will set the post as a draft status

func TrashPost

func TrashPost(postID uint64) error

TrashPost put the post into the trash by "delete" button The different between DeleteArticle and TrashPost is that TrashPost just set the status to deleted

func UpdateArticle

func UpdateArticle(a *ArticleUpdateRequest) error

UpdateArticle update article TODO: In this version, article meta data just update description, it should be more than one choise.

func UpdateMedia

func UpdateMedia(r *MediaUpdateRequest, userID int) (err error)

UpdateMedia update media info

func UpdateOptions

func UpdateOptions(options map[string]interface{}) error

UpdateOptions update options

func UpdatePage

func UpdatePage(p *PageUpdateRequest) (err error)

UpdatePage update page

func UpdateSubject

func UpdateSubject(r *SubjectUpdateRequest) error

UpdateSubject udpate subject info

func UpdateTaxonomy

func UpdateTaxonomy(r *TaxonomyUpdateRequest, termID uint64) error

UpdateTaxonomy update term and term taxonomy

func UpdateUser

func UpdateUser(u *UserUpdateRequest, userID int) error

UpdateUser update user info by id

func UpdateUserAvatar

func UpdateUserAvatar(c *gin.Context, userID string, file *multipart.FileHeader) error

UpdateUserAvatar update user avatar

func UpdateUserPassword

func UpdateUserPassword(u *UserUpdatePasswordRequest, userID int) error

UpdateUserPassword just reset user's password

func UpdateUserStatus

func UpdateUserStatus(u *UserUpdateStatusRequest, userID int) error

UpdateUserStatus update user status

func UploadMedia added in v0.3.0

func UploadMedia(c *gin.Context, userID, usage string, file *multipart.FileHeader) (ID uint64, GUID string, err error)

UploadMedia upload media and save record

Types

type ArticleCreateRequest added in v0.3.0

type ArticleCreateRequest struct {
	Status        string   `json:"status"`
	Title         string   `json:"title"`
	Content       string   `json:"content"`
	ContentHTML   string   `json:"content_html"`
	Description   string   `json:"description"`
	CommentStatus uint64   `json:"comment_status"`
	CoverPicture  string   `json:"cover_picture"`
	PostedTime    string   `json:"posted_time"`
	IfTop         uint64   `json:"if_top"`
	Category      []uint64 `json:"category"`
	Tag           []uint64 `json:"tag"`
	Subject       []uint64 `json:"subject"`
}

ArticleCreateRequest struct of article create params

type ArticleCreateResponse added in v0.3.0

type ArticleCreateResponse struct {
	ID   uint64 `json:"id"`
	GUID string `json:"guid"`
}

ArticleCreateResponse return the new article id and url

func CreateArticle added in v0.3.0

func CreateArticle(r *ArticleCreateRequest, userID uint64) (*ArticleCreateResponse, error)

CreateArticle create article

type ArticleDetail

type ArticleDetail struct {
	ID              uint64                 `json:"id"`
	Title           string                 `json:"title"`
	ContentMarkdown string                 `json:"content_markdown"`
	Status          string                 `json:"status"`
	CommentStatus   uint64                 `json:"comment_status"`
	IfTop           uint64                 `json:"if_top"`
	GUID            string                 `json:"guid"`
	CoverPicture    string                 `json:"cover_picture"`
	PostDate        string                 `json:"post_date"`
	MetaData        map[string]interface{} `json:"meta_date"`
	Category        []uint64               `json:"category"`
	Tag             []uint64               `json:"tag"`
	Subject         []uint64               `json:"subject"`
}

ArticleDetail struct for article info detail

func GetArticleDetail

func GetArticleDetail(articleID uint64) (*ArticleDetail, error)

GetArticleDetail get article detail by id

type ArticleListRequest added in v0.3.0

type ArticleListRequest struct {
	Title  string `form:"title"`
	Page   int    `form:"page"`
	Number int    `form:"number"`
	Sort   string `form:"sort"`
	Status string `form:"status"`
}

ArticleListRequest is the article list request struct

type ArticleListResponse added in v0.3.0

type ArticleListResponse struct {
	TotalCount  int64       `json:"totalCount"`
	TotalPage   uint64      `json:"totalPage"`
	ArticleList []*PostInfo `json:"articleList"`
}

ArticleListResponse is the article list response struct

type ArticleUpdateRequest added in v0.3.0

type ArticleUpdateRequest struct {
	ID            uint64   `json:"id"`
	Status        string   `json:"status"`
	Title         string   `json:"title"`
	Content       string   `json:"content"`
	ContentHTML   string   `json:"content_html"`
	Description   string   `json:"description"`
	CommentStatus uint64   `json:"comment_status"`
	CoverPicture  string   `json:"cover_picture"`
	PostedTime    string   `json:"posted_time"`
	IfTop         uint64   `json:"if_top"`
	Category      []uint64 `json:"category"`
	Tag           []uint64 `json:"tag"`
	Subject       []uint64 `json:"subject"`
}

ArticleUpdateRequest struct for update article

type DashboardData added in v0.2.1

type DashboardData struct {
	TotalViews    int64
	TotalComments int64
	TotalArticles int64
	TotalMedia    int64
}

DashboardData some statistics index

func GetDashboardStatisticsData added in v0.2.1

func GetDashboardStatisticsData() (*DashboardData, error)

GetDashboardStatisticsData get dashboard statistics data TODO store in cache first

type ListTheme added in v0.3.0

type ListTheme struct {
	Name      string `json:"name"`
	Thumbnail string `json:"thumbnail"`
}

OptionListTheme the list of all theme

type LoginRequest added in v0.3.0

type LoginRequest struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
}

LoginRequest is the login request params struct

type MediaDetail

type MediaDetail struct {
	MediaInfo
	Slug        string `json:"slug"`
	Description string `json:"description"`
}

MediaDetail media info in detail inclue Mediainfo struct

func GetMediaDetail added in v0.3.0

func GetMediaDetail(ID uint64) (*MediaDetail, error)

GetMedia return media info if database select success

type MediaInfo

type MediaInfo struct {
	ID         uint64 `json:"id"`
	Title      string `json:"title"`
	GUID       string `json:"url"`
	Type       string `json:"type"`
	UploadTime string `json:"upload_time"`
}

MediaInfo is the media struct for media list

func ListMedia

func ListMedia(limit, page int) ([]*MediaInfo, int64, error)

ListMedia returns current page media list and the total number of media

type MediaList

type MediaList struct {
	Lock  *sync.Mutex
	IDMap map[uint64]*MediaInfo
}

MediaList media list

type MediaListRequest added in v0.3.0

type MediaListRequest struct {
	Limit int `form:"limit"`
	Page  int `form:"page"`
}

MediaListRequest is the media list request struct

type MediaListResponse added in v0.3.0

type MediaListResponse struct {
	TotalCount int64        `json:"totalCount"`
	MediaList  []*MediaInfo `json:"mediaList"`
}

MediaListResponse returns total number of media and current page of media

type MediaUpdateRequest added in v0.3.0

type MediaUpdateRequest struct {
	ID          uint64 `json:"id"`
	Title       string `json:"title"`
	Slug        string `json:"slug"`
	Description string `json:"description"`
}

MediaUpdateRequest is the update media request params struct

type MediaUploadResponse added in v0.3.0

type MediaUploadResponse struct {
	ID  uint64 `json:"id"`
	URL string `json:"url"`
}

MediaUploadResponse is the upload media request's response struct

type OptionListResponse added in v0.3.0

type OptionListResponse struct {
	Options   map[string]string `json:"options"`
	ExtraData interface{}       `json:"extraData"`
}

OptionListResponse option list and extra data if exist

func ListOption added in v0.3.0

func ListOption(settingType string) (*OptionListResponse, error)

ListOption get option list by setting type

type OptionUpdateRequest added in v0.3.0

type OptionUpdateRequest struct {
	Parms map[string]interface{}
}

OptionUpdateRequest update request include params which are dynamitly

type PageCreateRequest added in v0.3.0

type PageCreateRequest struct {
	Status        string `json:"status"`
	Title         string `json:"title"`
	Content       string `json:"content"`
	ContentHTML   string `json:"content_html"`
	Description   string `json:"description"`
	CommentStatus uint64 `json:"comment_status"`
	CoverPicture  string `json:"cover_picture"`
	PostedTime    string `json:"posted_time"`
	Slug          string `json:"slug"`
	PageTemplate  string `json:"page_template"`
	ParentID      uint64 `json:"parent_id"`
}

PageCreateRequest struct of page create params

type PageCreateResponse added in v0.3.0

type PageCreateResponse struct {
	ID   uint64 `json:"id"`
	GUID string `json:"guid"`
}

PageCreateResponse return the new page id and url

func CreatePage added in v0.3.0

func CreatePage(r *PageCreateRequest, userID uint64) (*PageCreateResponse, error)

CreatePage create page

type PageDetail

type PageDetail struct {
	ID              uint64                 `json:"id"`
	Title           string                 `json:"title"`
	ContentMarkdown string                 `json:"content_markdown"`
	Slug            string                 `json:"slug"`
	ParentID        uint64                 `json:"parent_id"`
	Status          string                 `json:"status"`
	CommentStatus   uint64                 `json:"comment_status"`
	GUID            string                 `json:"guid"`
	CoverPicture    string                 `json:"cover_picture"`
	PostDate        string                 `json:"post_date"`
	MetaData        map[string]interface{} `json:"meta_date"`
}

PageDetail struct for page info detail

func GetPageDetail

func GetPageDetail(pageID uint64) (*PageDetail, error)

GetPageDetail get page detail by id

type PageListRequest added in v0.3.0

type PageListRequest struct {
	Title  string `form:"title"`
	Page   int    `form:"page"`
	Number int    `form:"number"`
	Sort   string `form:"sort"`
	Status string `form:"status"`
}

PageListRequest is the page list request struct

type PageListResponse added in v0.3.0

type PageListResponse struct {
	TotalCount int64       `json:"totalCount"`
	TotalPage  uint64      `json:"totalPage"`
	PageList   []*PostInfo `json:"pageList"`
}

PageListResponse is the page list response struct

type PageUpdateRequest added in v0.3.0

type PageUpdateRequest struct {
	ID            uint64 `json:"id"`
	Status        string `json:"status"`
	Title         string `json:"title"`
	Content       string `json:"content"`
	ContentHTML   string `json:"content_html"`
	Description   string `json:"description"`
	CommentStatus uint64 `json:"comment_status"`
	CoverPicture  string `json:"cover_picture"`
	PostedTime    string `json:"posted_time"`
	Slug          string `json:"slug"`
	PageTemplate  string `json:"page_template"`
	ParentID      uint64 `json:"parent_id"`
}

PageUpdateRequest struct of page update params

type PostInfo

type PostInfo struct {
	ID           uint64 `json:"id"`
	UserID       uint64 `json:"userId"`
	Title        string `json:"title"`
	Status       string `json:"status"`
	PostDate     string `json:"post_date"`
	CommentCount uint64 `json:"comment_count"`
	ViewCount    uint64 `json:"view_count"`
}

PostInfo is post info for post list

func ListArticle added in v0.3.0

func ListArticle(postType string, r *ArticleListRequest) ([]*PostInfo, int64, error)

ListArticle article list

func ListPage added in v0.3.0

func ListPage(postType string, r *PageListRequest) ([]*PostInfo, int64, error)

ListPage page list

func ListPost

func ListPost(postType, title string, page, number int, sort, status string) ([]*PostInfo, int64, error)

ListPost post list

type PostList

type PostList struct {
	Lock  *sync.Mutex
	IDMap map[uint64]*PostInfo
}

PostList post list

type SubjectCreateRequest added in v0.3.0

type SubjectCreateRequest struct {
	Name        string `json:"name"`
	Slug        string `json:"slug"`
	ParentID    uint64 `json:"parent_id"`
	CoverImage  uint64 `json:"cover_image"`
	Description string `json:"description"`
}

SubjectCreateRequest struct bind to create subject

type SubjectDetail

type SubjectDetail struct {
	ID               uint64 `json:"id"`
	ParentID         uint64 `json:"parent_id"`
	Name             string `json:"name"`
	Slug             string `json:"slug"`
	Description      string `json:"description"`
	CoverImage       uint64 `json:"cover_image"`
	CoverImageStatus string `json:"cover_image_status"`
	CoverURL         string `json:"cover_url"`
}

SubjectDetail subject info

func GetSubjectInfo

func GetSubjectInfo(subjectID uint64) (*SubjectDetail, error)

GetSubjectInfo get subject detail by id

type SubjectTreeNode

type SubjectTreeNode struct {
	ID          uint64             `json:"id"`
	ParentID    uint64             `json:"parent_id"`
	Name        string             `json:"name"`
	Slug        string             `json:"slug"`
	Description string             `json:"description"`
	Count       uint64             `json:"count"`
	LastUpdated string             `json:"last_updated"`
	Children    []*SubjectTreeNode `json:"children"`
}

SubjectTreeNode tree struct of subject list

func GetSubjectList

func GetSubjectList() ([]*SubjectTreeNode, error)

GetSubjectList get subject list by tree struct

type SubjectUpdateRequest added in v0.3.0

type SubjectUpdateRequest struct {
	ID          uint64 `json:"ID"`
	Name        string `json:"name"`
	Slug        string `json:"slug"`
	ParentID    uint64 `json:"parent_id"`
	CoverImage  uint64 `json:"cover_image"`
	Description string `json:"description"`
}

SubjectUpdateRequest struct bind to update subject

type TaxonomyCreateRequest added in v0.3.0

type TaxonomyCreateRequest struct {
	Name        string `json:"name"`
	Slug        string `json:"slug"`
	Description string `json:"description"`
	ParentID    uint64 `json:"parentId"`
	Taxonomy    string `json:"taxonomy"` // category or tag
}

TaxonomyCreateRequest struct to crate taxonomy include category and tag

type TaxonomyUpdateRequest added in v0.3.0

type TaxonomyUpdateRequest struct {
	ID          uint64 `json:"id"`
	Name        string `json:"name"`
	Slug        string `json:"slug"`
	Description string `json:"description"`
	ParentID    uint64 `json:"parentId"`
	Taxonomy    string `json:"taxonomy"` // category or tag
}

TaxonomyUpdateRequest param struct to update taxonomy include category and tag

type TermInfo

type TermInfo struct {
	ID          uint64 `json:"term_id"`
	Name        string `json:"name"`
	Slug        string `json:"slug"`
	Description string `json:"description"`
	Pid         uint64 `json:"parent_term_id"`
	Level       uint64 `json:"level"`
}

TermInfo terms info

func GetTaxonomyInfo

func GetTaxonomyInfo(termID uint64) (*TermInfo, error)

GetTaxonomyInfo get term info by term_id

type Token

type Token struct {
	Username string `json:"username"`
	Token    string `json:"token"`
}

Token represents a JSON web token.

func LoginAuth added in v0.3.0

func LoginAuth(c *gin.Context, username string, password string) (*Token, error)

LoginAuth user login authentication

type TreeNode

type TreeNode struct {
	ID           uint64      `json:"id"`
	Name         string      `json:"name"`
	Slug         string      `json:"slug"`
	Description  string      `json:"description"`
	Count        uint64      `json:"count"`
	TermID       uint64      `json:"term_id"`
	ParentTermID uint64      `json:"pid"`
	Level        uint64      `json:"level"`
	Children     []*TreeNode `json:"children"`
}

TreeNode TaxonomyTree's node struct

func GetTaxonomyList

func GetTaxonomyList(taxonomyType string) (taxonomyTree []*TreeNode, err error)

GetTaxonomyList get taxonomy tree by type and return a tree structure

func GetTaxonomyTree

func GetTaxonomyTree(allTermTaxonomy []*model.TermTaxonomy, pid uint64) []*TreeNode

GetTaxonomyTree return a taxonomy tree

type UserCreateRequest added in v0.3.0

type UserCreateRequest struct {
	Account       string `form:"account"`
	Nickname      string `form:"nickname"`
	Email         string `form:"email"`
	Role          string `form:"role"`
	Password      string `form:"password"`
	PasswordAgain string `form:"passwordAgain"`
	Website       string `form:"website"`
}

CreateRequest is the create user request params struct

type UserCreateResponse added in v0.3.0

type UserCreateResponse struct {
	Account  string
	Nickname string
}

CreateResponse is the create user request's response struct

type UserInfo

type UserInfo struct {
	ID             uint64 `json:"id"`
	Accout         string `json:"account"`
	Nickname       string `json:"nickname"`
	Email          string `json:"email"`
	Avatar         string `json:"avatar"`
	Roles          string `json:"roles"`
	Status         int    `json:"status"`
	Website        string `json:"website"`
	RegisteredTime string `json:"registered_time"`
	DeletedTime    string `json:"deleted_time"`
}

UserInfo is the user struct for user list

func GetUser

func GetUser(username string) (*UserInfo, error)

GetUser get userInfo by username(account)

func GetUserByToken added in v0.3.0

func GetUserByToken(t string) (*UserInfo, error)

GetUserByToken get userInfo by token(JWT)

func ListUser

func ListUser(username, role string, number, page, status int) ([]*UserInfo, int64, error)

ListUser show the user list in page

type UserList

type UserList struct {
	Lock  *sync.Mutex
	IDMap map[uint64]*UserInfo
}

UserList user list handle struct

type UserListRequest added in v0.3.0

type UserListRequest struct {
	Username string `form:"username"`
	Number   int    `form:"number"`
	Page     int    `form:"page"`
	Status   int    `form:"status"`
	Role     string `form:"role"`
}

ListRequest is the user list request struct

type UserListResponse added in v0.3.0

type UserListResponse struct {
	TotalCount int64       `json:"totalCount"`
	UserList   []*UserInfo `json:"userList"`
}

ListResponse is the use list response struct

type UserUpdatePasswordRequest added in v0.3.0

type UserUpdatePasswordRequest struct {
	ID            uint64 `json:"id"`
	Password      string `json:"password" binding:"required"`
	PasswordAgain string `json:"passwordAgain" binding:"required"`
}

UpdatePasswordRequest user for reset user's password during the profile page

type UserUpdateRequest added in v0.3.0

type UserUpdateRequest struct {
	ID       uint64 `json:"id"`
	Nickname string `json:"nickname"`
	Email    string `json:"email" binding:"required"`
	Role     string `json:"role" binding:"required"`
	Website  string `json:"website"`
}

UpdateRequest is the update user request params struct

type UserUpdateStatusRequest added in v0.3.0

type UserUpdateStatusRequest struct {
	ID     uint64 `json:"id"`
	Status int    `json:"status" binding:"required"`
}

UpdateStatusRequest only use for update user status

Jump to

Keyboard shortcuts

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