完善功能

This commit is contained in:
2025-07-16 15:16:40 +08:00
parent b2871ec0d2
commit f68a5b360b
123 changed files with 4643 additions and 931 deletions

View File

@ -5,11 +5,19 @@ import (
"server/internal/dao"
"server/internal/model"
"server/internal/model/do"
"server/internal/service"
"server/utility/ecode"
)
type sUserFollowAuthor struct{}
func New() service.IUserFollowAuthor {
return &sUserFollowAuthor{}
}
func init() {
service.RegisterUserFollowAuthor(New())
}
// 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{}
@ -64,3 +72,27 @@ func (s *sUserFollowAuthor) Delete(ctx context.Context, in *model.UserFollowAuth
}
return &model.UserFollowAuthorCRUDOut{Success: true}, nil
}
// Unfollow removes a user follow author by userId and authorId
func (s *sUserFollowAuthor) Unfollow(ctx context.Context, userId int64, authorId int64) (out *model.UserFollowAuthorCRUDOut, err error) {
if userId == 0 || authorId == 0 {
return nil, ecode.Params.Sub("user_id_or_author_id_invalid")
}
// 查找关注记录
var record struct{ Id int64 }
err = dao.UserFollowAuthors.Ctx(ctx).
Where(dao.UserFollowAuthors.Columns().UserId, userId).
Where(dao.UserFollowAuthors.Columns().AuthorId, authorId).
Fields("id").Scan(&record)
if err != nil {
return nil, ecode.Fail.Sub("user_follow_author_query_failed")
}
if record.Id == 0 {
return nil, ecode.NotFound.Sub("user_follow_author_not_found")
}
_, err = dao.UserFollowAuthors.Ctx(ctx).WherePri(record.Id).Delete()
if err != nil {
return nil, ecode.Fail.Sub("user_follow_author_delete_failed")
}
return &model.UserFollowAuthorCRUDOut{Success: true}, nil
}