初始化项目框架,完成部分接口开发
This commit is contained in:
66
internal/logic/user_follow_author/user_follow_author.go
Normal file
66
internal/logic/user_follow_author/user_follow_author.go
Normal file
@ -0,0 +1,66 @@
|
||||
package user_follow_author
|
||||
|
||||
import (
|
||||
"context"
|
||||
"server/internal/dao"
|
||||
"server/internal/model"
|
||||
"server/internal/model/do"
|
||||
"server/utility/ecode"
|
||||
)
|
||||
|
||||
type sUserFollowAuthor struct{}
|
||||
|
||||
// List retrieves a paginated list of user follow authors
|
||||
func (s *sUserFollowAuthor) List(ctx context.Context, in *model.UserFollowAuthorListIn) (out *model.UserFollowAuthorListOut, err error) {
|
||||
out = &model.UserFollowAuthorListOut{}
|
||||
m := dao.UserFollowAuthors.Ctx(ctx)
|
||||
if in.UserId != 0 {
|
||||
m = m.Where(dao.UserFollowAuthors.Columns().UserId, in.UserId)
|
||||
}
|
||||
if in.AuthorId != 0 {
|
||||
m = m.Where(dao.UserFollowAuthors.Columns().AuthorId, in.AuthorId)
|
||||
}
|
||||
if err = m.Page(in.Page, in.Size).ScanAndCount(&out.List, &out.Total, false); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Create adds a new user follow author
|
||||
func (s *sUserFollowAuthor) Create(ctx context.Context, in *model.UserFollowAuthorAddIn) (out *model.UserFollowAuthorCRUDOut, err error) {
|
||||
exist, err := dao.UserFollowAuthors.Ctx(ctx).
|
||||
Where(dao.UserFollowAuthors.Columns().UserId, in.UserId).
|
||||
Where(dao.UserFollowAuthors.Columns().AuthorId, in.AuthorId).
|
||||
Exist()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("user_follow_author_query_failed")
|
||||
}
|
||||
if exist {
|
||||
return nil, ecode.Params.Sub("user_follow_author_exists")
|
||||
}
|
||||
if _, err := dao.UserFollowAuthors.Ctx(ctx).Data(do.UserFollowAuthors{
|
||||
UserId: in.UserId,
|
||||
AuthorId: in.AuthorId,
|
||||
}).Insert(); err != nil {
|
||||
return nil, ecode.Fail.Sub("user_follow_author_create_failed")
|
||||
}
|
||||
return &model.UserFollowAuthorCRUDOut{Success: true}, nil
|
||||
}
|
||||
|
||||
// Delete removes a user follow author by id
|
||||
func (s *sUserFollowAuthor) Delete(ctx context.Context, in *model.UserFollowAuthorDelIn) (out *model.UserFollowAuthorCRUDOut, err error) {
|
||||
exist, err := dao.UserFollowAuthors.Ctx(ctx).
|
||||
WherePri(in.Id).
|
||||
Exist()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("user_follow_author_query_failed")
|
||||
}
|
||||
if !exist {
|
||||
return nil, ecode.NotFound.Sub("user_follow_author_not_found")
|
||||
}
|
||||
_, err = dao.UserFollowAuthors.Ctx(ctx).WherePri(in.Id).Delete()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("user_follow_author_delete_failed")
|
||||
}
|
||||
return &model.UserFollowAuthorCRUDOut{Success: true}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user