完善功能
This commit is contained in:
@ -1,17 +0,0 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"server/api/admin/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) AdminEditPass(ctx context.Context, req *v1.AdminEditPassReq) (res *v1.AdminEditPassRes, err error) {
|
||||
out, err := service.Admin().EditPass(ctx, &model.AdminEditPassIn{NewPass: req.NewPass, OldPass: req.OldPass})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.AdminEditPassRes{Success: out.Success}, nil
|
||||
}
|
||||
14
internal/controller/admin/admin_v1_edit_pass.go
Normal file
14
internal/controller/admin/admin_v1_edit_pass.go
Normal file
@ -0,0 +1,14 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
|
||||
"server/api/admin/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) EditPass(ctx context.Context, req *v1.EditPassReq) (res *v1.EditPassRes, err error) {
|
||||
return nil, gerror.NewCode(gcode.CodeNotImplemented)
|
||||
}
|
||||
@ -9,13 +9,14 @@ import (
|
||||
"server/api/admin/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) AdminInfo(ctx context.Context, req *v1.AdminInfoReq) (res *v1.AdminInfoRes, err error) {
|
||||
func (c *ControllerV1) Info(ctx context.Context, req *v1.InfoReq) (res *v1.InfoRes, err error) {
|
||||
adminId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
out, err := service.Admin().Info(ctx, &model.AdminInfoIn{AdminId: adminId})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.AdminInfoRes{
|
||||
return &v1.InfoRes{
|
||||
AdminId: out.AdminId,
|
||||
Username: out.Username,
|
||||
}, nil
|
||||
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
|
||||
}
|
||||
@ -2,25 +2,27 @@ package book
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/book/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"server/api/book/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) BookAdd(ctx context.Context, req *v1.BookAddReq) (res *v1.BookAddRes, err error) {
|
||||
func (c *ControllerV1) Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) {
|
||||
out, err := service.Book().Create(ctx, &model.BookAddIn{
|
||||
AuthorId: req.AuthorId,
|
||||
CategoryId: req.CategoryId,
|
||||
Title: req.Title,
|
||||
CoverUrl: req.CoverUrl,
|
||||
Description: req.Description,
|
||||
IsRecommended: req.IsRecommended,
|
||||
Status: req.Status,
|
||||
Tags: req.Tags,
|
||||
Title: req.Title,
|
||||
IsRecommended: req.IsRecommended,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.BookAddRes{Success: out.Success}, nil
|
||||
|
||||
return &v1.AddRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
44
internal/controller/book/book_v1_app_detail.go
Normal file
44
internal/controller/book/book_v1_app_detail.go
Normal file
@ -0,0 +1,44 @@
|
||||
package book
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/book/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) AppDetail(ctx context.Context, req *v1.AppDetailReq) (res *v1.AppDetailRes, err error) {
|
||||
// 从 ctx 获取用户ID
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
|
||||
out, err := service.Book().AppDetail(ctx, &model.BookAppDetailIn{
|
||||
Id: req.Id,
|
||||
UserId: userId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.AppDetailRes{
|
||||
Id: out.Id,
|
||||
AuthorId: out.AuthorId,
|
||||
CategoryId: out.CategoryId,
|
||||
Title: out.Title,
|
||||
CoverUrl: out.CoverUrl,
|
||||
Description: out.Description,
|
||||
Status: out.Status,
|
||||
Tags: out.Tags,
|
||||
IsRecommended: out.IsRecommended,
|
||||
Rating: out.Rating,
|
||||
CurrentReaders: out.CurrentReaders,
|
||||
CreatedAt: out.CreatedAt.String(),
|
||||
UpdatedAt: out.UpdatedAt.String(),
|
||||
// 添加阅读进度信息
|
||||
HasRead: out.HasRead,
|
||||
ReadProgress: out.ReadProgress,
|
||||
LastChapterId: out.LastChapterId,
|
||||
LastReadAt: out.LastReadAt,
|
||||
}, nil
|
||||
}
|
||||
35
internal/controller/book/book_v1_app_list.go
Normal file
35
internal/controller/book/book_v1_app_list.go
Normal file
@ -0,0 +1,35 @@
|
||||
package book
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/book/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) AppList(ctx context.Context, req *v1.AppListReq) (res *v1.AppListRes, err error) {
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
out, err := service.Book().AppList(ctx, &model.BookAppListIn{
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
IsRecommended: req.IsRecommended,
|
||||
IsFeatured: req.IsFeatured,
|
||||
IsLatest: req.IsLatest,
|
||||
CategoryId: req.CategoryId,
|
||||
Title: req.Title,
|
||||
AuthorId: req.AuthorId,
|
||||
UserId: userId,
|
||||
Language: req.Language,
|
||||
Sort: req.Sort,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.AppListRes{
|
||||
Total: out.Total,
|
||||
List: out.List,
|
||||
}, nil
|
||||
}
|
||||
26
internal/controller/book/book_v1_app_rate.go
Normal file
26
internal/controller/book/book_v1_app_rate.go
Normal file
@ -0,0 +1,26 @@
|
||||
package book
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/book/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) AppRate(ctx context.Context, req *v1.AppRateReq) (res *v1.AppRateRes, err error) {
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
out, err := service.Book().AppRate(ctx, &model.BookAppRateIn{
|
||||
BookId: req.BookId,
|
||||
Rating: req.Rating,
|
||||
UserId: userId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.AppRateRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
14
internal/controller/book/book_v1_book_set_featured.go
Normal file
14
internal/controller/book/book_v1_book_set_featured.go
Normal file
@ -0,0 +1,14 @@
|
||||
package book
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
|
||||
"server/api/book/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) BookSetFeatured(ctx context.Context, req *v1.BookSetFeaturedReq) (res *v1.BookSetFeaturedRes, err error) {
|
||||
return nil, gerror.NewCode(gcode.CodeNotImplemented)
|
||||
}
|
||||
14
internal/controller/book/book_v1_book_set_recommended.go
Normal file
14
internal/controller/book/book_v1_book_set_recommended.go
Normal file
@ -0,0 +1,14 @@
|
||||
package book
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
|
||||
"server/api/book/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) BookSetRecommended(ctx context.Context, req *v1.BookSetRecommendedReq) (res *v1.BookSetRecommendedRes, err error) {
|
||||
return nil, gerror.NewCode(gcode.CodeNotImplemented)
|
||||
}
|
||||
@ -2,18 +2,20 @@ package book
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/book/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"server/api/book/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) BookDel(ctx context.Context, req *v1.BookDelReq) (res *v1.BookDelRes, err error) {
|
||||
func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) {
|
||||
out, err := service.Book().Delete(ctx, &model.BookDelIn{
|
||||
Id: req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.BookDelRes{Success: out.Success}, nil
|
||||
|
||||
return &v1.DelRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
@ -2,26 +2,28 @@ package book
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/book/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"server/api/book/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) BookEdit(ctx context.Context, req *v1.BookEditReq) (res *v1.BookEditRes, err error) {
|
||||
func (c *ControllerV1) Edit(ctx context.Context, req *v1.EditReq) (res *v1.EditRes, err error) {
|
||||
out, err := service.Book().Update(ctx, &model.BookEditIn{
|
||||
Id: req.Id,
|
||||
AuthorId: req.AuthorId,
|
||||
CategoryId: req.CategoryId,
|
||||
Title: req.Title,
|
||||
CoverUrl: req.CoverUrl,
|
||||
Description: req.Description,
|
||||
Id: req.Id,
|
||||
IsRecommended: req.IsRecommended,
|
||||
Status: req.Status,
|
||||
Tags: req.Tags,
|
||||
Title: req.Title,
|
||||
IsRecommended: req.IsRecommended,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.BookEditRes{Success: out.Success}, nil
|
||||
|
||||
return &v1.EditRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
@ -2,27 +2,28 @@ package book
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/book/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"server/api/book/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) BookList(ctx context.Context, req *v1.BookListReq) (res *v1.BookListRes, err error) {
|
||||
func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) {
|
||||
out, err := service.Book().List(ctx, &model.BookListIn{
|
||||
AuthorId: req.AuthorId,
|
||||
CategoryId: req.CategoryId,
|
||||
IsRecommended: req.IsRecommended,
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
Status: req.Status,
|
||||
Title: req.Title,
|
||||
CategoryId: req.CategoryId,
|
||||
AuthorId: req.AuthorId,
|
||||
Status: req.Status,
|
||||
IsRecommended: req.IsRecommended,
|
||||
Sort: req.Sort,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.BookListRes{
|
||||
List: out.List,
|
||||
|
||||
return &v1.ListRes{
|
||||
Total: out.Total,
|
||||
List: out.List,
|
||||
}, nil
|
||||
}
|
||||
32
internal/controller/book/book_v1_my_list.go
Normal file
32
internal/controller/book/book_v1_my_list.go
Normal file
@ -0,0 +1,32 @@
|
||||
package book
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v1 "server/api/book/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) MyList(ctx context.Context, req *v1.MyListReq) (res *v1.MyListRes, err error) {
|
||||
// 从ctx获取userId
|
||||
userId := ghttp.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
in := &model.MyBookListIn{
|
||||
Type: req.Type,
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
UserId: userId,
|
||||
Sort: req.Sort,
|
||||
}
|
||||
result, err := service.Book().MyList(ctx, in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res = &v1.MyListRes{
|
||||
Total: result.Total,
|
||||
List: result.List,
|
||||
}
|
||||
return
|
||||
}
|
||||
31
internal/controller/book/book_v1_shelf_add.go
Normal file
31
internal/controller/book/book_v1_shelf_add.go
Normal file
@ -0,0 +1,31 @@
|
||||
package book
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/book/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
"server/utility/ecode"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) ShelfAdd(ctx context.Context, req *v1.ShelfAddReq) (res *v1.ShelfAddRes, err error) {
|
||||
// 从 ctx 获取用户ID
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
if userId == 0 {
|
||||
return nil, ecode.Logout
|
||||
}
|
||||
|
||||
out, err := service.Bookshelve().Add(ctx, &model.BookshelveAddIn{
|
||||
UserId: userId,
|
||||
BookId: req.BookId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.ShelfAddRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
31
internal/controller/book/book_v1_shelf_remove.go
Normal file
31
internal/controller/book/book_v1_shelf_remove.go
Normal file
@ -0,0 +1,31 @@
|
||||
package book
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/book/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
"server/utility/ecode"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) ShelfRemove(ctx context.Context, req *v1.ShelfRemoveReq) (res *v1.ShelfRemoveRes, err error) {
|
||||
// 从 ctx 获取用户ID
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
if userId == 0 {
|
||||
return nil, ecode.Logout
|
||||
}
|
||||
|
||||
out, err := service.Bookshelve().Delete(ctx, &model.BookshelveDelIn{
|
||||
UserId: userId,
|
||||
BookIds: req.BookIds,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.ShelfRemoveRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
@ -5,18 +5,18 @@ import (
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"server/api/category/v1"
|
||||
v1 "server/api/category/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) CategoryAdd(ctx context.Context, req *v1.CategoryAddReq) (res *v1.CategoryAddRes, err error) {
|
||||
func (c *ControllerV1) Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) {
|
||||
out, err := service.Category().Create(ctx, &model.CategoryAddIn{
|
||||
Name: req.Name,
|
||||
Type: req.Type,
|
||||
Name: req.Name,
|
||||
Channel: req.Channel,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.CategoryAddRes{
|
||||
return &v1.AddRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"context"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"server/api/category/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) CategoryList(ctx context.Context, req *v1.CategoryListReq) (res *v1.CategoryListRes, err error) {
|
||||
out, err := service.Category().List(ctx, &model.CategoryListIn{
|
||||
Name: req.Name,
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
Type: req.Type,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.CategoryListRes{
|
||||
List: out.List,
|
||||
Total: out.Total,
|
||||
}, nil
|
||||
}
|
||||
@ -8,14 +8,14 @@ import (
|
||||
"server/api/category/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) CategoryDel(ctx context.Context, req *v1.CategoryDelReq) (res *v1.CategoryDelRes, err error) {
|
||||
func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) {
|
||||
out, err := service.Category().Delete(ctx, &model.CategoryDelIn{
|
||||
Id: req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.CategoryDelRes{
|
||||
return &v1.DelRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
@ -5,19 +5,19 @@ import (
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"server/api/category/v1"
|
||||
v1 "server/api/category/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) CategoryEdit(ctx context.Context, req *v1.CategoryEditReq) (res *v1.CategoryEditRes, err error) {
|
||||
func (c *ControllerV1) Edit(ctx context.Context, req *v1.EditReq) (res *v1.EditRes, err error) {
|
||||
out, err := service.Category().Update(ctx, &model.CategoryEditIn{
|
||||
Id: req.Id,
|
||||
Name: req.Name,
|
||||
Type: req.Type,
|
||||
Id: req.Id,
|
||||
Name: req.Name,
|
||||
Channel: req.Channel,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.CategoryEditRes{
|
||||
return &v1.EditRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
30
internal/controller/category/category_v1_list.go
Normal file
30
internal/controller/category/category_v1_list.go
Normal file
@ -0,0 +1,30 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
v1 "server/api/category/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) {
|
||||
// 调用service层获取分类列表
|
||||
result, err := service.Category().List(ctx, &model.CategoryListIn{
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
Name: req.Name,
|
||||
Channel: req.Channel,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 构造响应
|
||||
res = &v1.ListRes{
|
||||
Total: result.Total,
|
||||
List: result.List,
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"server/api/chapter/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) ChapterAdd(ctx context.Context, req *v1.ChapterAddReq) (res *v1.ChapterAddRes, err error) {
|
||||
func (c *ControllerV1) Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) {
|
||||
out, err := service.Chapter().Create(ctx, &model.ChapterAddIn{
|
||||
BookId: req.BookId,
|
||||
Content: req.Content,
|
||||
@ -21,7 +21,7 @@ func (c *ControllerV1) ChapterAdd(ctx context.Context, req *v1.ChapterAddReq) (r
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.ChapterAddRes{
|
||||
return &v1.AddRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
29
internal/controller/chapter/chapter_v1_app_detail.go
Normal file
29
internal/controller/chapter/chapter_v1_app_detail.go
Normal file
@ -0,0 +1,29 @@
|
||||
package chapter
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/chapter/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) AppDetail(ctx context.Context, req *v1.AppDetailReq) (res *v1.AppDetailRes, err error) {
|
||||
out, err := service.Chapter().AppDetail(ctx, &model.ChapterAppDetailIn{
|
||||
Id: req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.AppDetailRes{
|
||||
Id: out.Id,
|
||||
BookId: out.BookId,
|
||||
Title: out.Title,
|
||||
Content: out.Content,
|
||||
WordCount: out.WordCount,
|
||||
Sort: out.Sort,
|
||||
IsLocked: out.IsLocked,
|
||||
RequiredScore: out.RequiredScore,
|
||||
UpdatedAt: out.UpdatedAt.String(),
|
||||
}, nil
|
||||
}
|
||||
29
internal/controller/chapter/chapter_v1_app_list.go
Normal file
29
internal/controller/chapter/chapter_v1_app_list.go
Normal file
@ -0,0 +1,29 @@
|
||||
package chapter
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/chapter/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) AppList(ctx context.Context, req *v1.AppListReq) (res *v1.AppListRes, err error) {
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
out, err := service.Chapter().AppList(ctx, &model.ChapterAppListIn{
|
||||
BookId: req.BookId,
|
||||
IsDesc: req.IsDesc,
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
UserId: userId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.AppListRes{
|
||||
Total: out.Total,
|
||||
List: out.List,
|
||||
}, nil
|
||||
}
|
||||
27
internal/controller/chapter/chapter_v1_app_progress.go
Normal file
27
internal/controller/chapter/chapter_v1_app_progress.go
Normal file
@ -0,0 +1,27 @@
|
||||
package chapter
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/chapter/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) AppProgress(ctx context.Context, req *v1.AppProgressReq) (res *v1.AppProgressRes, err error) {
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
out, err := service.Chapter().AppProgress(ctx, &model.ChapterAppProgressIn{
|
||||
BookId: req.BookId,
|
||||
ChapterId: req.ChapterId,
|
||||
Progress: req.Progress,
|
||||
UserId: userId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.AppProgressRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
25
internal/controller/chapter/chapter_v1_app_purchase.go
Normal file
25
internal/controller/chapter/chapter_v1_app_purchase.go
Normal file
@ -0,0 +1,25 @@
|
||||
package chapter
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/chapter/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) AppPurchase(ctx context.Context, req *v1.AppPurchaseReq) (res *v1.AppPurchaseRes, err error) {
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
out, err := service.Chapter().AppPurchase(ctx, &model.ChapterAppPurchaseIn{
|
||||
Id: req.Id,
|
||||
UserId: userId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.AppPurchaseRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
@ -8,12 +8,12 @@ import (
|
||||
"server/api/chapter/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) ChapterDel(ctx context.Context, req *v1.ChapterDelReq) (res *v1.ChapterDelRes, err error) {
|
||||
func (c *ControllerV1) Del(ctx context.Context, req *v1.DelReq) (res *v1.DelRes, err error) {
|
||||
out, err := service.Chapter().Delete(ctx, &model.ChapterDelIn{
|
||||
Id: req.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.ChapterDelRes{Success: out.Success}, nil
|
||||
return &v1.DelRes{Success: out.Success}, nil
|
||||
}
|
||||
@ -8,21 +8,21 @@ import (
|
||||
"server/api/chapter/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) ChapterEdit(ctx context.Context, req *v1.ChapterEditReq) (res *v1.ChapterEditRes, err error) {
|
||||
func (c *ControllerV1) Edit(ctx context.Context, req *v1.EditReq) (res *v1.EditRes, err error) {
|
||||
out, err := service.Chapter().Update(ctx, &model.ChapterEditIn{
|
||||
BookId: req.BookId,
|
||||
Content: req.Content,
|
||||
Id: req.Id,
|
||||
IsLocked: req.IsLocked,
|
||||
RequiredScore: req.RequiredScore,
|
||||
Sort: req.Sort,
|
||||
BookId: req.BookId,
|
||||
Title: req.Title,
|
||||
Sort: req.Sort,
|
||||
IsLocked: req.IsLocked,
|
||||
Content: req.Content,
|
||||
WordCount: req.WordCount,
|
||||
RequiredScore: req.RequiredScore,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.ChapterEditRes{
|
||||
return &v1.EditRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
}
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"server/api/chapter/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) ChapterList(ctx context.Context, req *v1.ChapterListReq) (res *v1.ChapterListRes, err error) {
|
||||
func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) {
|
||||
out, err := service.Chapter().List(ctx, &model.ChapterListIn{
|
||||
BookId: req.BookId,
|
||||
IsLocked: req.IsLocked,
|
||||
@ -19,7 +19,7 @@ func (c *ControllerV1) ChapterList(ctx context.Context, req *v1.ChapterListReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.ChapterListRes{
|
||||
return &v1.ListRes{
|
||||
List: out.List,
|
||||
Total: out.Total,
|
||||
}, nil
|
||||
@ -9,7 +9,7 @@ import (
|
||||
"server/api/feedback/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) FeedbackAdd(ctx context.Context, req *v1.FeedbackAddReq) (res *v1.FeedbackAddRes, err error) {
|
||||
func (c *ControllerV1) Add(ctx context.Context, req *v1.AddReq) (res *v1.AddRes, err error) {
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
out, err := service.Feedback().Create(ctx, &model.FeedbackAddIn{
|
||||
Content: req.Content,
|
||||
@ -18,7 +18,5 @@ func (c *ControllerV1) FeedbackAdd(ctx context.Context, req *v1.FeedbackAddReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.FeedbackAddRes{
|
||||
Success: out.Success,
|
||||
}, nil
|
||||
return &v1.AddRes{Success: out.Success}, nil
|
||||
}
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"server/api/feedback/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) FeedbackList(ctx context.Context, req *v1.FeedbackListReq) (res *v1.FeedbackListRes, err error) {
|
||||
func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) {
|
||||
out, err := service.Feedback().List(ctx, &model.FeedbackListIn{
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
@ -18,8 +18,8 @@ func (c *ControllerV1) FeedbackList(ctx context.Context, req *v1.FeedbackListReq
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.FeedbackListRes{
|
||||
List: out.List,
|
||||
return &v1.ListRes{
|
||||
Total: out.Total,
|
||||
List: out.List,
|
||||
}, nil
|
||||
}
|
||||
32
internal/controller/user/user_v1_info.go
Normal file
32
internal/controller/user/user_v1_info.go
Normal file
@ -0,0 +1,32 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "server/api/user/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
"server/utility/ecode"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) Info(ctx context.Context, req *v1.InfoReq) (res *v1.InfoRes, err error) {
|
||||
// 从ctx获取userId
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
if userId == 0 {
|
||||
return nil, ecode.Logout
|
||||
}
|
||||
|
||||
out, err := service.User().Info(ctx, &model.UserInfoIn{UserId: userId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &v1.InfoRes{
|
||||
UserId: out.UserId,
|
||||
Username: out.Username,
|
||||
Avatar: out.Avatar,
|
||||
Email: out.Email,
|
||||
Points: out.Points,
|
||||
}, nil
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
|
||||
"server/api/user/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) UserInfo(ctx context.Context, req *v1.UserInfoReq) (res *v1.UserInfoRes, err error) {
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
info, err := service.User().Info(ctx, &model.UserInfoIn{UserId: userId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &v1.UserInfoRes{
|
||||
Username: info.Username,
|
||||
Avatar: info.Avatar,
|
||||
Email: info.Email,
|
||||
Points: info.Points,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user