fix: api descript
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/player/rpc/internal/svc"
|
||||
"juwan-backend/app/player/rpc/pb"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddPlayerServicesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddPlayerServicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddPlayerServicesLogic {
|
||||
return &AddPlayerServicesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------playerServices-----------------------
|
||||
func (l *AddPlayerServicesLogic) AddPlayerServices(in *pb.AddPlayerServicesReq) (*pb.AddPlayerServicesResp, error) {
|
||||
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||
if err != nil {
|
||||
logx.Errorf("addPlayerServices err:%v", err)
|
||||
return nil, errors.New("create player service id failed")
|
||||
}
|
||||
_, err = l.svcCtx.PlayerModelRW.PlayerServices.Create().
|
||||
SetID(idResp.Id).
|
||||
SetPlayerID(in.PlayerId).
|
||||
SetGameID(in.GameId).
|
||||
SetTitle(in.Title).
|
||||
SetDescription(in.Description).
|
||||
SetPrice(decimal.NewFromFloat(in.Price)).
|
||||
SetUnit(in.Unit).
|
||||
SetRankRange(in.RankRange).
|
||||
SetAvailability(in.Availability).
|
||||
SetRating(decimal.NewFromFloat(in.Rating)).
|
||||
SetIsActive(in.IsActive).
|
||||
Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("addPlayerServices err:%v", err)
|
||||
return nil, errors.New("add player service failed")
|
||||
}
|
||||
|
||||
return &pb.AddPlayerServicesResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
|
||||
"juwan-backend/app/player/rpc/internal/svc"
|
||||
"juwan-backend/app/player/rpc/pb"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AddPlayersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewAddPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddPlayersLogic {
|
||||
return &AddPlayersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------players-----------------------
|
||||
func (l *AddPlayersLogic) AddPlayers(in *pb.AddPlayersReq) (*pb.AddPlayersResp, error) {
|
||||
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
||||
if err != nil {
|
||||
logx.Errorf("addPlayerServices err:%v", err)
|
||||
return nil, errors.New("create player service id failed")
|
||||
}
|
||||
gender := 0
|
||||
if in.Gender != 0 {
|
||||
gender = 1
|
||||
}
|
||||
_, err = l.svcCtx.PlayerModelRW.Players.Create().
|
||||
SetID(idResp.Id).
|
||||
SetUserID(in.UserId).
|
||||
SetStatus(in.Status).
|
||||
SetRating(decimal.NewFromFloat(in.Rating)).
|
||||
SetTotalOrders(int(in.TotalOrders)).
|
||||
SetCompletedOrders(int(in.CompletedOrders)).
|
||||
SetShopID(in.ShopId).
|
||||
SetTags(in.Tags).
|
||||
SetGender(gender).
|
||||
SetGames(in.Games).
|
||||
Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("addPlayerServices err:%v", err)
|
||||
return nil, errors.New("add player service failed")
|
||||
}
|
||||
return &pb.AddPlayersResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/player/rpc/internal/svc"
|
||||
"juwan-backend/app/player/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DelPlayerServicesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDelPlayerServicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelPlayerServicesLogic {
|
||||
return &DelPlayerServicesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DelPlayerServicesLogic) DelPlayerServices(in *pb.DelPlayerServicesReq) (*pb.DelPlayerServicesResp, error) {
|
||||
err := l.svcCtx.PlayerModelRW.PlayerServices.DeleteOneID(in.Id).Exec(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("delete player services failed, %s", err.Error())
|
||||
return nil, errors.New("delete failed")
|
||||
}
|
||||
|
||||
return &pb.DelPlayerServicesResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"juwan-backend/app/player/rpc/internal/svc"
|
||||
"juwan-backend/app/player/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DelPlayersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDelPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelPlayersLogic {
|
||||
return &DelPlayersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DelPlayersLogic) DelPlayers(in *pb.DelPlayersReq) (*pb.DelPlayersResp, error) {
|
||||
err := l.svcCtx.PlayerModelRW.Players.DeleteOneID(in.Id).Exec(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("delete player services failed, %s", err.Error())
|
||||
return nil, errors.New("delete failed")
|
||||
}
|
||||
|
||||
return &pb.DelPlayersResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/player/rpc/internal/models/playerservices"
|
||||
|
||||
"juwan-backend/app/player/rpc/internal/svc"
|
||||
"juwan-backend/app/player/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetPlayerServicesByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetPlayerServicesByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPlayerServicesByIdLogic {
|
||||
return &GetPlayerServicesByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetPlayerServicesByIdLogic) GetPlayerServicesById(in *pb.GetPlayerServicesByIdReq) (*pb.GetPlayerServicesByIdResp, error) {
|
||||
playerService, err := l.svcCtx.PlayerModelRO.PlayerServices.Query().Where(playerservices.IDEQ(in.Id)).First(l.ctx)
|
||||
if err != nil {
|
||||
logx.WithContext(l.ctx).Errorf("GetPlayerServicesByIdLogic err: %v", err)
|
||||
return nil, errors.New("get player services by id failed")
|
||||
}
|
||||
|
||||
pbPlayerService := pb.PlayerServices{
|
||||
Id: playerService.ID,
|
||||
PlayerId: playerService.PlayerID,
|
||||
GameId: playerService.GameID,
|
||||
Title: playerService.Title,
|
||||
Price: playerService.Price.InexactFloat64(),
|
||||
Unit: playerService.Unit,
|
||||
Availability: playerService.Availability,
|
||||
Rating: playerService.Rating.InexactFloat64(),
|
||||
IsActive: playerService.IsActive,
|
||||
CreatedAt: playerService.CreatedAt.Unix(),
|
||||
UpdatedAt: playerService.UpdatedAt.Unix(),
|
||||
}
|
||||
if playerService.Description != nil {
|
||||
pbPlayerService.Description = *playerService.Description
|
||||
}
|
||||
if playerService.RankRange != nil {
|
||||
pbPlayerService.RankRange = *playerService.RankRange
|
||||
}
|
||||
|
||||
return &pb.GetPlayerServicesByIdResp{PlayerServices: &pbPlayerService}, nil
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/player/rpc/internal/models/players"
|
||||
|
||||
"juwan-backend/app/player/rpc/internal/svc"
|
||||
"juwan-backend/app/player/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetPlayersByIdLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetPlayersByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPlayersByIdLogic {
|
||||
return &GetPlayersByIdLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetPlayersByIdLogic) GetPlayersById(in *pb.GetPlayersByIdReq) (*pb.GetPlayersByIdResp, error) {
|
||||
player, err := l.svcCtx.PlayerModelRO.Players.Query().Where(players.IDEQ(in.Id)).First(l.ctx)
|
||||
if err != nil {
|
||||
logx.WithContext(l.ctx).Errorf("GetPlayersByIdLogic err: %v", err)
|
||||
return nil, errors.New("get players by id failed")
|
||||
}
|
||||
|
||||
pbPlayer := pb.Players{
|
||||
Id: player.ID,
|
||||
UserId: player.UserID,
|
||||
Status: player.Status,
|
||||
Rating: player.Rating.InexactFloat64(),
|
||||
TotalOrders: int64(player.TotalOrders),
|
||||
CompletedOrders: int64(player.CompletedOrders),
|
||||
Tags: player.Tags,
|
||||
Games: []int64(player.Games),
|
||||
CreatedAt: player.CreatedAt.Unix(),
|
||||
UpdatedAt: player.UpdatedAt.Unix(),
|
||||
}
|
||||
if player.ShopID != nil {
|
||||
pbPlayer.ShopId = *player.ShopID
|
||||
}
|
||||
|
||||
return &pb.GetPlayersByIdResp{Players: &pbPlayer}, nil
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/player/rpc/internal/models/playerservices"
|
||||
"juwan-backend/app/player/rpc/internal/svc"
|
||||
"juwan-backend/app/player/rpc/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchPlayerServicesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchPlayerServicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchPlayerServicesLogic {
|
||||
return &SearchPlayerServicesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchPlayerServicesLogic) SearchPlayerServices(in *pb.SearchPlayerServicesReq) (*pb.SearchPlayerServicesResp, error) {
|
||||
if in.Limit > 1000 {
|
||||
return nil, errors.New("limit too large")
|
||||
}
|
||||
|
||||
update := l.svcCtx.PlayerModelRO.PlayerServices.Query()
|
||||
if in.PlayerId != 0 {
|
||||
update.Where(playerservices.PlayerIDEQ(in.PlayerId))
|
||||
}
|
||||
|
||||
all, err := update.
|
||||
Limit(int(in.Limit)).
|
||||
Offset(int(in.Limit * in.Page)).
|
||||
All(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.New("query all player services err")
|
||||
}
|
||||
|
||||
list := make([]*pb.PlayerServices, 0, len(all))
|
||||
for _, v := range all {
|
||||
temp := &pb.PlayerServices{
|
||||
Id: v.ID,
|
||||
PlayerId: v.PlayerID,
|
||||
GameId: v.GameID,
|
||||
Title: v.Title,
|
||||
Price: v.Price.InexactFloat64(),
|
||||
Unit: v.Unit,
|
||||
Availability: v.Availability,
|
||||
Rating: v.Rating.InexactFloat64(),
|
||||
IsActive: v.IsActive,
|
||||
CreatedAt: v.CreatedAt.Unix(),
|
||||
UpdatedAt: v.UpdatedAt.Unix(),
|
||||
}
|
||||
if v.Description != nil {
|
||||
temp.Description = *v.Description
|
||||
}
|
||||
if v.RankRange != nil {
|
||||
temp.RankRange = *v.RankRange
|
||||
}
|
||||
list = append(list, temp)
|
||||
}
|
||||
|
||||
return &pb.SearchPlayerServicesResp{PlayerServices: list}, nil
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/player/rpc/internal/models/players"
|
||||
|
||||
"juwan-backend/app/player/rpc/internal/svc"
|
||||
"juwan-backend/app/player/rpc/pb"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type SearchPlayersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewSearchPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchPlayersLogic {
|
||||
return &SearchPlayersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SearchPlayersLogic) SearchPlayers(in *pb.SearchPlayersReq) (*pb.SearchPlayersResp, error) {
|
||||
gender := 0
|
||||
if in.Gender > 0 {
|
||||
gender = 1
|
||||
}
|
||||
searcher := l.svcCtx.PlayerModelRO.Players.Query()
|
||||
if in.Gender >= 0 {
|
||||
searcher.Where(players.GenderEQ(gender))
|
||||
}
|
||||
|
||||
all, err := searcher.Limit(int(in.Limit)).Offset(int(in.Page * in.Limit)).All(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("SearchPlayers err: %v", err)
|
||||
return nil, errors.New("search players")
|
||||
}
|
||||
list := make([]*pb.Players, 0, len(all))
|
||||
for _, v := range all {
|
||||
temp := &pb.Players{}
|
||||
err := copier.Copy(temp, v)
|
||||
if err != nil {
|
||||
logx.Errorf("SearchPlayers copier.Copy err: %v", err)
|
||||
continue
|
||||
}
|
||||
list = append(list, temp)
|
||||
}
|
||||
|
||||
return &pb.SearchPlayersResp{Players: list}, nil
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"juwan-backend/app/player/rpc/internal/svc"
|
||||
"juwan-backend/app/player/rpc/pb"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdatePlayerServicesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdatePlayerServicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePlayerServicesLogic {
|
||||
return &UpdatePlayerServicesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdatePlayerServicesLogic) UpdatePlayerServices(in *pb.UpdatePlayerServicesReq) (*pb.UpdatePlayerServicesResp, error) {
|
||||
update := l.svcCtx.PlayerModelRW.PlayerServices.UpdateOneID(in.Id).
|
||||
SetNillablePlayerID(in.PlayerId).
|
||||
SetNillableDescription(in.Description).
|
||||
SetNillableGameID(in.GameId).
|
||||
SetNillableIsActive(in.IsActive).
|
||||
SetNillableRankRange(in.RankRange).
|
||||
SetNillableTitle(in.Title).
|
||||
SetNillableUnit(in.Unit).
|
||||
SetAvailability(in.Availability)
|
||||
if in.Price != nil {
|
||||
price := decimal.NewFromFloat(*in.Price)
|
||||
update.SetNillablePrice(&price)
|
||||
}
|
||||
if in.Rating != nil {
|
||||
rating := decimal.NewFromFloat(*in.Rating)
|
||||
update.SetNillableRating(&rating)
|
||||
}
|
||||
|
||||
_, err := update.Save(l.ctx)
|
||||
if err != nil {
|
||||
logx.Errorf("failed to update player services: " + err.Error())
|
||||
return nil, errors.New("failed to update player services")
|
||||
}
|
||||
return &pb.UpdatePlayerServicesResp{}, nil
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"juwan-backend/app/player/rpc/internal/svc"
|
||||
"juwan-backend/app/player/rpc/pb"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdatePlayersLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdatePlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePlayersLogic {
|
||||
return &UpdatePlayersLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdatePlayersLogic) UpdatePlayers(in *pb.UpdatePlayersReq) (*pb.UpdatePlayersResp, error) {
|
||||
update := l.svcCtx.PlayerModelRW.Players.UpdateOneID(in.Id).
|
||||
SetNillableStatus(in.Status).
|
||||
SetNillableUserID(in.UserId).
|
||||
SetNillableShopID(in.ShopId)
|
||||
if in.Rating != nil {
|
||||
rating := decimal.NewFromFloat(*in.Rating)
|
||||
update.SetRating(rating)
|
||||
}
|
||||
|
||||
return &pb.UpdatePlayersResp{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user