书籍列表接口新增参数
This commit is contained in:
@ -31,7 +31,7 @@ func (s *sAuthor) List(ctx context.Context, in *model.AuthorListIn) (out *model.
|
||||
if in.Status != 0 {
|
||||
m = m.Where(dao.Authors.Columns().Status, in.Status)
|
||||
}
|
||||
if err = m.Page(in.Page, in.Size).ScanAndCount(&out.List, &out.Total, false); err != nil {
|
||||
if err = m.Page(in.Page, in.Size).WithAll().ScanAndCount(&out.List, &out.Total, false); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
@ -226,13 +226,8 @@ func (s *sAuthor) Delete(ctx context.Context, in *model.AuthorDelIn) (out *model
|
||||
|
||||
// Apply 允许用户申请成为作者
|
||||
func (s *sAuthor) Apply(ctx context.Context, in *model.AuthorApplyIn) (out *model.AuthorApplyOut, err error) {
|
||||
userIdVal := ctx.Value("id")
|
||||
userId, ok := userIdVal.(int64)
|
||||
if !ok || userId == 0 {
|
||||
return nil, ecode.Fail.Sub("user_id_invalid")
|
||||
}
|
||||
exist, err := dao.Authors.Ctx(ctx).
|
||||
Where(dao.Authors.Columns().UserId, userId).
|
||||
Where(dao.Authors.Columns().UserId, in.UserId).
|
||||
Exist()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("author_query_failed")
|
||||
@ -241,10 +236,10 @@ func (s *sAuthor) Apply(ctx context.Context, in *model.AuthorApplyIn) (out *mode
|
||||
return nil, ecode.Params.Sub("author_user_exists")
|
||||
}
|
||||
if _, err := dao.Authors.Ctx(ctx).Data(do.Authors{
|
||||
UserId: userId,
|
||||
UserId: in.UserId,
|
||||
PenName: in.PenName,
|
||||
Bio: in.Bio,
|
||||
Status: 1, // 默认正常
|
||||
Status: 2, // 默认禁用
|
||||
}).Insert(); err != nil {
|
||||
return nil, ecode.Fail.Sub("author_create_failed")
|
||||
}
|
||||
@ -252,17 +247,74 @@ func (s *sAuthor) Apply(ctx context.Context, in *model.AuthorApplyIn) (out *mode
|
||||
}
|
||||
func (s *sAuthor) Detail(ctx context.Context, in *model.AuthorDetailIn) (out *model.AuthorDetailOut, err error) {
|
||||
out = &model.AuthorDetailOut{}
|
||||
exist, err := dao.Authors.Ctx(ctx).
|
||||
WherePri(in.AuthorId).
|
||||
Exist()
|
||||
err = dao.Authors.Ctx(ctx).WherePri(in.AuthorId).WithAll().Scan(&out)
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("author_query_failed")
|
||||
}
|
||||
if out == nil {
|
||||
return nil, ecode.NotFound.Sub("author_not_found")
|
||||
}
|
||||
userId := ctx.Value("id")
|
||||
if userId != nil {
|
||||
exist, err := dao.UserFollowAuthors.Ctx(ctx).
|
||||
Where(dao.UserFollowAuthors.Columns().UserId, userId).
|
||||
Where(dao.UserFollowAuthors.Columns().AuthorId, in.AuthorId).
|
||||
Exist()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("user_follow_author_query_failed")
|
||||
}
|
||||
out.IsFollowed = exist
|
||||
}
|
||||
// 查询作者作品数量
|
||||
out.WorksCount, err = dao.Books.Ctx(ctx).
|
||||
Where(dao.Books.Columns().AuthorId, in.AuthorId).
|
||||
Count()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("author_book_count_failed")
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// AuthorInfo 获取作者信息
|
||||
func (s *sAuthor) AuthorInfo(ctx context.Context, in *model.AuthorInfoIn) (out *model.AuthorInfoOut, err error) {
|
||||
exist, err := dao.Authors.Ctx(ctx).Where(dao.Authors.Columns().UserId, in.UserId).Exist()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("author_query_failed")
|
||||
}
|
||||
if !exist {
|
||||
return nil, ecode.NotFound.Sub("author_not_found")
|
||||
}
|
||||
if err = dao.Authors.Ctx(ctx).WherePri(in.AuthorId).WithAll().Scan(&out); err != nil {
|
||||
|
||||
var author struct {
|
||||
Id int64 `json:"id"`
|
||||
PenName string `json:"penName"`
|
||||
}
|
||||
err = dao.Authors.Ctx(ctx).Where(dao.Authors.Columns().UserId, in.UserId).Fields("id, pen_name").Scan(&author)
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("author_query_failed")
|
||||
}
|
||||
return out, nil
|
||||
|
||||
return &model.AuthorInfoOut{
|
||||
Id: author.Id,
|
||||
PenName: author.PenName,
|
||||
Role: "author",
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 审核作者申请(通过/拒绝)
|
||||
func (s *sAuthor) Review(ctx context.Context, in *model.AuthorReviewIn) (out *model.AuthorReviewOut, err error) {
|
||||
exist, err := dao.Authors.Ctx(ctx).WherePri(in.AuthorId).Exist()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("author_query_failed")
|
||||
}
|
||||
if !exist {
|
||||
return nil, ecode.NotFound.Sub("author_not_found")
|
||||
}
|
||||
_, err = dao.Authors.Ctx(ctx).WherePri(in.AuthorId).Data(do.Authors{
|
||||
Status: in.Status,
|
||||
}).Update()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("author_review_failed")
|
||||
}
|
||||
return &model.AuthorReviewOut{Success: true}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user