controller

package
v0.0.0-...-bef4ad1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MErrNoLogin      = mo2errors.Init(mo2errors.Mo2NoLogin, "权限不足,请先登录")
	MErrUnauthorized = mo2errors.Init(mo2errors.Mo2Unauthorized, "没有权限修改文章")
)

Functions

func JudgeAuthorize

func JudgeAuthorize(ctx *gin.Context, blog *model.Blog) (mErr mo2errors.Mo2Errors)

JudgeAuthorize only for user of same ID 只有本人id与blog的authorID一致可以继续

func SetupHandlers

func SetupHandlers(c *Controller)

SetupHandlers set up

Types

type Controller

type Controller struct {
}

Controller example

func NewController

func NewController() *Controller

NewController example

func (*Controller) AddAccount

func (c *Controller) AddAccount(ctx *gin.Context)

AddAccount godoc @Summary Add an account @Description add by json account @Tags accounts @Accept json @Produce json @Param account body model.AddAccount true "add new account info" @Success 200 {object} dto.UserInfo @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Router /api/accounts [post]

func (*Controller) AddAccountRole

func (c *Controller) AddAccountRole(ctx *gin.Context)

AddAccountRole godoc @Summary Add role for an account @Description add by json account @Tags admin @Accept json @Produce json @Param account body model.AddAccountRole true "add new account info" @Success 200 {object} dto.UserInfo @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/accounts/role [post]

func (*Controller) AddActiveAccounts

func (c *Controller) AddActiveAccounts(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) DeleteAccount

func (c *Controller) DeleteAccount(ctx *gin.Context)

DeleteAccount godoc @Summary delete Blog @Description delete by path @Tags accounts @Accept json @Produce json @Param info body model.DeleteAccount true "delete account info" @Success 202 @Success 204 @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/accounts [delete]

func (*Controller) DeleteBlog

func (c *Controller) DeleteBlog(ctx *gin.Context)

DeleteBlog godoc @Summary 彻底删除blog @Description delete by id path(draft/blog) @Tags blogs @Accept json @Produce json @Param draft query bool true "bool true" true @Param id path string false "string xxxxxxxx" "xxxxxxx" @Success 202 @Success 204 @Failure 304 @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/blogs/{id} [delete]

func (*Controller) DeleteCategory

func (c *Controller) DeleteCategory(ctx *gin.Context)

DeleteCategory godoc @Summary delete category @Description 根据id删除,并解除与之相关实体的所有关联 @Tags category @Accept json @Produce json @Param ids body []primitive.ObjectID true "category id to delete" @Success 200 {object} model.Directory @Router /api/directories/category [delete]

func (*Controller) DeleteGroup

func (c *Controller) DeleteGroup(ctx *gin.Context)

DeleteGroup godoc @Summary delete group @Description delete by id in path @Tags group @Accept json @Produce json @Param id path primitive.ObjectID true "group id to delete" @Success 202 @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Router /api/group/{id} [delete]

func (*Controller) DeleteProject

func (c *Controller) DeleteProject(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) FindAllCategories

func (c *Controller) FindAllCategories(ctx *gin.Context)

FindAllCategories godoc @Summary find categories @Description 若id为空,返回所有categories(debug mode);若id不为空,返回该id的category @Tags category @Produce json @Param id query string false "string ObjectID" "" @Success 200 {object} []model.Directory @Router /api/blogs/category [get]

func (*Controller) FindBlogById

func (c *Controller) FindBlogById(ctx *gin.Context)

FindBlogById godoc @Summary find Blog by id @Description @Tags blogs @Accept json @Produce json @Param draft query bool false "bool true" true @Param id query string false "string xxxxxxxx" "xxxxxxx" @Success 200 {object} model.Blog @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/blogs/find/id [get]

func (*Controller) FindBlogsByID

func (c *Controller) FindBlogsByID(ctx *gin.Context)

FindBlogsByUserId godoc @Summary find Blog by userid @Description @Tags blogs @Accept json @Produce json @Param draft query bool false "bool true" true @Param deleted query bool false "bool default false" false @Param id query string false "string xxxxxxxx" "xxxxxxx" @Param page query int false "int 0" 0 @Param pageSize query int false "int 5" 5 @Success 200 {object} []model.Blog @Success 204 @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/blogs/find/userId [get]

func (*Controller) FindBlogsByType

func (c *Controller) FindBlogsByType(ctx *gin.Context)

FindBlogsByType godoc @Summary find blogs by given type @Description 根据type返回不同结果:[category] 所有category包含的blog @Tags relation @Accept json @Produce json @Param type path string true "find by category" @Param ID path string true "ID" @Success 200 {object} []model.Blog @Failure 400 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/relation/blogs/{type}/{ID} [get]

func (*Controller) FindBlogsByUser

func (c *Controller) FindBlogsByUser(ctx *gin.Context)

FindBlogsByUser godoc @Summary find Blog @Description @Tags blogs @Accept json @Produce json @Param draft query bool false "bool true" true @Param deleted query bool false "bool default false" false @Param page query int false "int 0" 0 @Param pageSize query int false "int 5" 5 @Success 200 {object} []model.Blog @Success 204 {object} []model.Blog @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/blogs/find/own [get]

func (*Controller) FindCategoriesByType

func (c *Controller) FindCategoriesByType(ctx *gin.Context)

FindCategoriesByType godoc @Summary find categories by given type @Description 根据type返回不同结果:[user] 个人的所有category|[sub] 所有子category @Tags relation @Accept json @Produce json @Param type path string true "find by user/sub" @Param ID path string true "ID" @Success 200 {object} []model.Directory @Failure 400 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/relation/category/{type}/{ID} [get]

func (*Controller) FindGroup

func (c *Controller) FindGroup(ctx *gin.Context)

FindGroup godoc @Summary get group @Description delete by id in path @Tags group @Accept json @Produce json @Param id path primitive.ObjectID true "group id to find" @Success 200 {object} model.Group @Success 202 @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Router /api/group/{id} [get]

func (*Controller) GenUploadToken

func (c *Controller) GenUploadToken(ctx *gin.Context) (status int, json interface{}, err error)

GenUploadToken generate img upload token GenUploadToken godoc @Summary Gen img token @Description add by json @Tags img @Produce json @Param filename path string true "file name" @Success 200 {object} dto.ImgUploadToken @Router /api/img/{filename} [get]

func (*Controller) GetAccountIDs

func (c *Controller) GetAccountIDs(
	ctx *gin.Context,
	u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) GetComment

func (c *Controller) GetComment(ctx *gin.Context)

GetComment get comments @Summary get comments @Description get json comments @Tags comments @Accept json @Produce json @Param id path string true "article id" @Param page query int false "int 0" 0 @Param pagesize query int false "int 5" 5 @Success 200 {object} []model.Comment @Failure 422 {object} badresponse.ResponseError @Router /api/comment/{id} [get]

func (*Controller) GetCommentNum

func (c *Controller) GetCommentNum(ctx *gin.Context)

GetCommentNum godoc @Summary count comments @Description get article comment num @Tags comments @Produce json @Param id path string true "article id" @Success 200 {object} map[string]int64 @Failure 422 {object} badresponse.ResponseError @Router /api/commentcount/{id} [get]

func (*Controller) GetNotificationNum

func (c *Controller) GetNotificationNum(ctx *gin.Context)

GetNotificationNum godoc @Summary get notification num @Description get notification num @Tags notification @Produce json @Success 200 @Router /api/notification/num [get]

func (*Controller) GetNotifications

func (c *Controller) GetNotifications(ctx *gin.Context)

GetNotifications godoc @Summary get notifications @Description get notifications @Tags notification @Param page query int false "int 0" 0 @Param pagesize query int false "int 5" 5 @Produce json @Success 200 @Router /api/notification [get]

func (*Controller) GetProject

func (c *Controller) GetProject(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) GithubOauth

func (c *Controller) GithubOauth(ctx *gin.Context)

func (*Controller) IndexAll

func (c *Controller) IndexAll(ctx *gin.Context)

IndexAllBlogs godoc @Summary index all blogs @Description none @Tags admin @Success 200 @Router /api/admin/indexblogs [post]

func (*Controller) InsertGroup

func (c *Controller) InsertGroup(ctx *gin.Context)

InsertGroup godoc @Summary insert group @Description add by json @Tags group @Accept json @Produce json @Param group body model.Group true "Add group" @Success 201 {object} model.Group @Success 204 @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Router /api/group [post]

func (*Controller) IsScored

func (c *Controller) IsScored(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) JoinProject

func (c *Controller) JoinProject(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) Like

func (c *Controller) Like(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) LikeNum

func (c *Controller) LikeNum(ctx *gin.Context) (status int, body interface{}, err error)

func (*Controller) Liked

func (c *Controller) Liked(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) ListAccountsInfo

func (c *Controller) ListAccountsInfo(ctx *gin.Context)

ListAccountsInfo godoc @Summary List accounts brief info @Description from a list of user ids [usage]:/api/accounts/listBrief?id=60223d4042d6febff9f276f0&id=60236866d2a68483adaccc38 @Tags accounts @Accept json @Produce json @Param id query array true "user IDs list" @Success 200 {object} []dto.UserInfoBrief @Router /api/accounts/listBrief [get]

func (*Controller) ListDirectoriesInfo

func (c *Controller) ListDirectoriesInfo(ctx *gin.Context)

ListAccountsInfo godoc @Summary List directories brief info @Description from a list of directory ids [usage]:/api/directories/{collection}?id=60223d4042d6febff9f276f0&id=60236866d2a68483adaccc38 @Tags directory @Accept json @Produce json @Param collection path string true "category/..." @Param id query array true "directory IDs list" @Success 200 {object} []model.Directory @Router /api/directories/{collection} [get]

func (*Controller) ListProject

func (c *Controller) ListProject(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) Log

func (c *Controller) Log(ctx *gin.Context)

Log godoc @Summary get user info @Description get by check cookies @Tags logs @Accept json @Produce json @Success 200 {object} dto.UserInfo @Router /api/logs [get]

func (*Controller) LoginAccount

func (c *Controller) LoginAccount(ctx *gin.Context)

LoginAccount godoc @Summary login an account @Description login by json model.LoginAccount and set cookies @Tags accounts @Accept json @Produce json @Param account body model.LoginAccount true "login account" @Success 200 {object} dto.UserInfo @Failure 400 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/accounts/login [post]

func (*Controller) LogoutAccount

func (c *Controller) LogoutAccount(ctx *gin.Context)

LogoutAccount godoc @Summary logout @Description logout and delete cookies @Tags accounts @Produce json @Success 200 @Router /api/accounts/logout [post]

func (*Controller) PostComment

func (c *Controller) PostComment(ctx *gin.Context)

PostComment godoc @Summary upsert comments @Description upsert json comments @Tags comments @Accept json @Produce json @Param comment body model.Comment true "comment" @Success 200 {object} model.Comment @Failure 422 {object} badresponse.ResponseError @Router /api/comment [post]

func (*Controller) PostSubComment

func (c *Controller) PostSubComment(ctx *gin.Context)

PostSubComment post subcomments @Summary upsert subcomments @Description upsert json comments @Tags comments @Accept json @Produce json @Param id path string true "comment id" @Param comment body model.Subcomment true "subcomment" @Success 200 {object} model.Subcomment @Failure 422 {object} badresponse.ResponseError @Router /api/comment/{id} [post]

func (*Controller) ProcessBlog

func (c *Controller) ProcessBlog(ctx *gin.Context)

ProcessBlog godoc @Summary restore Blog @Description restore by path @Tags blogs @Accept json @Produce json @Param draft query bool true "bool true" true @Param operation path string false "recycle/restore" "different type operation" @Param id path string false "Blog id" "objectID" @Success 202 @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/blogs/{operation}/{id} [put]

func (*Controller) QueryBlogs

func (c *Controller) QueryBlogs(ctx *gin.Context)

QueryBlogs godoc @Summary find all Blogs @Description find @Tags blogs @Produce json @Param draft query bool false "bool default false" false @Param deleted query bool false "bool default false" false @Param page query int false "int 0" 0 @Param pageSize query int false "int 5" 5 @Param search query string false "aaaa" "aaa" @Success 200 {object} []model.Blog @Success 204 {object} []model.Blog @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/blogs/query [get]

func (*Controller) RelateCategories2Entity

func (c *Controller) RelateCategories2Entity(ctx *gin.Context)

RelateCategories2Entity godoc @Summary 将列表内的子categories关联到单个实体上 @Description (根据path中提供的关联类型选择对应方法)目前有:父category @Tags relation @Accept json @Produce json @Param type path string true "types to relate" @Param id body dto.RelateEntitySet2Entity true "sub category id and parent id" @Success 200 {object} model.Directory @Router /api/relation/categories/{type} [post]

func (*Controller) RelateCategory2Entity

func (c *Controller) RelateCategory2Entity(ctx *gin.Context)

RelateCategory2Entity godoc @Summary relate category to given type @Description @Tags relation @Accept json @Produce json @Param type path string true "relatedTo user/blog/category/userMain" @Param e2e body dto.RelateEntity2Entity true "category id to be related" @Success 200 {object} dto.RelateEntity2Entity @Router /api/relation/category/{type} [post]

func (*Controller) Score

func (c *Controller) Score(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) SearchAccount

func (c *Controller) SearchAccount(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) SearchProject

func (c *Controller) SearchProject(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) SetDocType

func (c *Controller) SetDocType(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) ShowAccount

func (c *Controller) ShowAccount(ctx *gin.Context)

ShowAccount godoc @Summary Show account's info @Description get string by ID;若id为空,返回所有用户信息 @Tags accounts @ID get-string-by-int @Accept json @Produce json @Param id path string false "Account ID" @Success 200 {object} []dto.UserInfo @Failure 400 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/accounts/detail/{id} [get]

func (*Controller) UpdateAccount

func (c *Controller) UpdateAccount(ctx *gin.Context)

UpdateAccount godoc @Summary 修改名称(唯一用于登录)/偏好设置 @Description 通过id获取已有用户,验证身份。并将name的修改与setting的修改应用 @Tags accounts @Accept json @Produce json @Param account body dto.UserInfoBrief true "id必须,可修改name/settings" @Success 200 {object} dto.UserInfo @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/accounts [put]

func (*Controller) UpdateGroup

func (c *Controller) UpdateGroup(ctx *gin.Context)

UpdateGroup godoc @Summary update group @Description add by json @Tags group @Accept json @Produce json @Param group body model.Group true "update group" @Success 201 {object} model.Group @Success 204 @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Router /api/group [put]

func (*Controller) Upload

func (c *Controller) Upload(ctx *gin.Context)

Upload godoc @Summary simple test @Description say something @Accept multipart/form-data @Produce json @Param form body string true "file" @Success 200 {object} model.Blog @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Failure 404 {object} badresponse.ResponseError @Router /api/file [post]

func (*Controller) UpsertBlog

func (c *Controller) UpsertBlog(ctx *gin.Context)

UpsertBlog godoc @Summary Publish Blog @Description add by json @Tags blogs @Accept json @Produce json @Param draft query bool false "bool true" true @Param account body model.Blog true "Add blog" @Success 201 {object} model.Blog @Success 204 @Failure 400 {object} badresponse.ResponseError @Failure 401 {object} badresponse.ResponseError @Router /api/blogs/publish [post]

func (*Controller) UpsertCategory

func (c *Controller) UpsertCategory(ctx *gin.Context)

UpsertCategory godoc @Summary upsert category @Description add by json @Tags category @Accept json @Produce json @Param account body model.Directory true "Add category" @Success 200 {object} model.Directory @Router /api/blogs/category [post]

func (*Controller) UpsertProject

func (c *Controller) UpsertProject(ctx *gin.Context, u dto.LoginUserInfo) (status int, body interface{}, err error)

func (*Controller) VerifyEmail

func (c *Controller) VerifyEmail(ctx *gin.Context)

VerifyEmail godoc @Summary verify an account's email @Description add by json account @Tags accounts @Accept json @Produce json @Param email query string true "email@mo2.com" @Param token query string true "xxxx==sf" @Success 308 @Failure 401 {object} badresponse.ResponseError @Router /api/accounts/verify [get]

type GithubUser

type GithubUser struct {
	Login      string `json:"login,omitempty"`
	ID         int    `json:"id,omitempty"`
	AvatarUrl  string `json:"avatar_url,omitempty"`
	Location   string `json:"location,omitempty"`
	Bio        string `json:"bio,omitempty"`
	GithubHome string `json:"html_url,omitempty"`
}

type Message

type Message struct {
	Message string `json:"message" example:"message"`
}

Message example

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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