完善功能
This commit is contained in:
@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user