完善功能
This commit is contained in:
5
internal/controller/author/author.go
Normal file
5
internal/controller/author/author.go
Normal file
@ -0,0 +1,5 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package author
|
||||
15
internal/controller/author/author_new.go
Normal file
15
internal/controller/author/author_new.go
Normal file
@ -0,0 +1,15 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package author
|
||||
|
||||
import (
|
||||
"server/api/author"
|
||||
)
|
||||
|
||||
type ControllerV1 struct{}
|
||||
|
||||
func NewV1() author.IAuthorV1 {
|
||||
return &ControllerV1{}
|
||||
}
|
||||
24
internal/controller/author/author_v1_add.go
Normal file
24
internal/controller/author/author_v1_add.go
Normal file
@ -0,0 +1,24 @@
|
||||
package author
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/author/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) {
|
||||
out, err := service.Author().Create(ctx, &model.AuthorAddIn{
|
||||
UserId: req.UserId,
|
||||
PenName: req.PenName,
|
||||
Bio: req.Bio,
|
||||
Status: req.Status,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.AddRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
21
internal/controller/author/author_v1_del.go
Normal file
21
internal/controller/author/author_v1_del.go
Normal file
@ -0,0 +1,21 @@
|
||||
package author
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/author/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) {
|
||||
out, err := service.Author().Delete(ctx, &model.AuthorDelIn{
|
||||
Id: req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.DelRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
17
internal/controller/author/author_v1_detail.go
Normal file
17
internal/controller/author/author_v1_detail.go
Normal file
@ -0,0 +1,17 @@
|
||||
package author
|
||||
|
||||
import (
|
||||
"context"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"server/api/author/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) Detail(ctx context.Context, req *v1.DetailReq) (res *v1.DetailRes, err error) {
|
||||
out, err := service.Author().Detail(ctx, &model.AuthorDetailIn{AuthorId: req.AuthorId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.DetailRes{Author: out}, nil
|
||||
}
|
||||
24
internal/controller/author/author_v1_edit.go
Normal file
24
internal/controller/author/author_v1_edit.go
Normal file
@ -0,0 +1,24 @@
|
||||
package author
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/author/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) Edit(ctx context.Context, req *v1.EditReq) (res *v1.EditRes, err error) {
|
||||
out, err := service.Author().Update(ctx, &model.AuthorEditIn{
|
||||
Id: req.Id,
|
||||
PenName: req.PenName,
|
||||
Bio: req.Bio,
|
||||
Status: req.Status,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.EditRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
31
internal/controller/author/author_v1_follow.go
Normal file
31
internal/controller/author/author_v1_follow.go
Normal file
@ -0,0 +1,31 @@
|
||||
package author
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/author/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
"server/utility/ecode"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) Follow(ctx context.Context, req *v1.FollowReq) (res *v1.FollowRes, err error) {
|
||||
// 从 ctx 获取用户ID
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
if userId == 0 {
|
||||
return nil, ecode.Logout
|
||||
}
|
||||
|
||||
out, err := service.UserFollowAuthor().Create(ctx, &model.UserFollowAuthorAddIn{
|
||||
UserId: userId,
|
||||
AuthorId: req.AuthorId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.FollowRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
25
internal/controller/author/author_v1_list.go
Normal file
25
internal/controller/author/author_v1_list.go
Normal file
@ -0,0 +1,25 @@
|
||||
package author
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/author/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) {
|
||||
out, err := service.Author().List(ctx, &model.AuthorListIn{
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
PenName: req.PenName,
|
||||
Status: req.Status,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.ListRes{
|
||||
Total: out.Total,
|
||||
List: out.List,
|
||||
}, nil
|
||||
}
|
||||
27
internal/controller/author/author_v1_unfollow.go
Normal file
27
internal/controller/author/author_v1_unfollow.go
Normal file
@ -0,0 +1,27 @@
|
||||
package author
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/author/v1"
|
||||
"server/internal/service"
|
||||
"server/utility/ecode"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) Unfollow(ctx context.Context, req *v1.UnfollowReq) (res *v1.UnfollowRes, err error) {
|
||||
// 从 ctx 获取用户ID
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
if userId == 0 {
|
||||
return nil, ecode.Logout
|
||||
}
|
||||
|
||||
out, err := service.UserFollowAuthor().Unfollow(ctx, userId, req.AuthorId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.UnfollowRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user