feat 错误包装
This commit is contained in:
@@ -15,8 +15,9 @@ type Server struct {
|
|||||||
func NewServer(ttl int64) *Server {
|
func NewServer(ttl int64) *Server {
|
||||||
s := &Server{
|
s := &Server{
|
||||||
Base: service.Base{
|
Base: service.Base{
|
||||||
Target: common.KeyDiscoverQgdzs,
|
Target: common.KeyDiscoverQgdzs,
|
||||||
EtcdTTL: ttl,
|
ServiceName: common.KeyDiscoverServiceNameQgdzs,
|
||||||
|
EtcdTTL: ttl,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
s.Base.OnInit = s.OnInit
|
s.Base.OnInit = s.OnInit
|
||||||
|
|||||||
10
internal/grpc_server/server_leaderboard.go
Normal file
10
internal/grpc_server/server_leaderboard.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package grpc_server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UpdateLeaderboard 更新排行榜
|
||||||
|
func (s *Server) UpdateLeaderboard(ctx context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -58,8 +58,7 @@ func (s *Server) GenerateQuestion(ctx context.Context, req *grpc_pb.GenerateQues
|
|||||||
categoryDao := repository.NewCategoryDao(ctx, redis.GetCacheClient())
|
categoryDao := repository.NewCategoryDao(ctx, redis.GetCacheClient())
|
||||||
category, err := categoryDao.FindAll()
|
category, err := categoryDao.FindAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("GenerateQuestion FindCategory error: %v", err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
question := make([]*Question, 0)
|
question := make([]*Question, 0)
|
||||||
err = ai.NewAIClient(false, "", 0.9).
|
err = ai.NewAIClient(false, "", 0.9).
|
||||||
@@ -77,17 +76,15 @@ func (s *Server) GenerateQuestion(ctx context.Context, req *grpc_pb.GenerateQues
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
step := make([]*Question, 0)
|
step := make([]*Question, 0)
|
||||||
if err := json.Unmarshal([]byte(content), &step); err != nil {
|
if err = json.Unmarshal([]byte(content), &step); err != nil {
|
||||||
log.Errorf("RequestAI json.Unmarshal error: %v, data: %v", err, content)
|
return utils.ErrorsWrapF(err, "data: %v", content)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
question = append(question, step...)
|
question = append(question, step...)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("RequestAI error: %v", err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
questionDao := repository.NewQuestionDao(ctx, redis.GetCacheClient())
|
questionDao := repository.NewQuestionDao(ctx, redis.GetCacheClient())
|
||||||
@@ -117,8 +114,7 @@ func (s *Server) GenerateQuestion(ctx context.Context, req *grpc_pb.GenerateQues
|
|||||||
CategorySn: categorySn,
|
CategorySn: categorySn,
|
||||||
Difficulty: q.Difficulty,
|
Difficulty: q.Difficulty,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Errorf("GenerateQuestion Create error: %v", err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@@ -128,13 +124,11 @@ func (s *Server) GenerateQuestion(ctx context.Context, req *grpc_pb.GenerateQues
|
|||||||
func (s *Server) GetQuestion(ctx context.Context, req *grpc_pb.GetQuestionReq) (*grpc_pb.GetQuestionResp, error) {
|
func (s *Server) GetQuestion(ctx context.Context, req *grpc_pb.GetQuestionReq) (*grpc_pb.GetQuestionResp, error) {
|
||||||
question, err := repository.NewQuestionDao(ctx).FindByRandom(req.CategorySn)
|
question, err := repository.NewQuestionDao(ctx).FindByRandom(req.CategorySn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("GetQuestion error: %v", err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
options := make([]string, 0)
|
options := make([]string, 0)
|
||||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||||
log.Errorf("GetQuestion json.Unmarshal error: %v, data: %v", err, question.Options)
|
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
category, _ := repository.NewCategoryDao(ctx).FindNameBySn(question.CategorySn)
|
category, _ := repository.NewCategoryDao(ctx).FindNameBySn(question.CategorySn)
|
||||||
return &grpc_pb.GetQuestionResp{
|
return &grpc_pb.GetQuestionResp{
|
||||||
@@ -150,13 +144,11 @@ func (s *Server) GetQuestion(ctx context.Context, req *grpc_pb.GetQuestionReq) (
|
|||||||
func (s *Server) GetQuestionInfo(ctx context.Context, req *grpc_pb.GetQuestionInfoReq) (*grpc_pb.GetQuestionInfoResp, error) {
|
func (s *Server) GetQuestionInfo(ctx context.Context, req *grpc_pb.GetQuestionInfoReq) (*grpc_pb.GetQuestionInfoResp, error) {
|
||||||
question, err := repository.NewQuestionDao(ctx).FindBySn(req.QuestionSn)
|
question, err := repository.NewQuestionDao(ctx).FindBySn(req.QuestionSn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("GetQuestionInfo error: %v", err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
options := make([]string, 0)
|
options := make([]string, 0)
|
||||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||||
log.Errorf("GetQuestionInfo json.Unmarshal error: %v, data: %v", err, question.Options)
|
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
category, _ := repository.NewCategoryDao(ctx).FindNameBySn(question.CategorySn)
|
category, _ := repository.NewCategoryDao(ctx).FindNameBySn(question.CategorySn)
|
||||||
return &grpc_pb.GetQuestionInfoResp{
|
return &grpc_pb.GetQuestionInfoResp{
|
||||||
@@ -172,13 +164,11 @@ func (s *Server) GetQuestionInfo(ctx context.Context, req *grpc_pb.GetQuestionIn
|
|||||||
func (s *Server) AnswerQuestion(ctx context.Context, req *grpc_pb.AnswerQuestionReq) (*grpc_pb.AnswerQuestionResp, error) {
|
func (s *Server) AnswerQuestion(ctx context.Context, req *grpc_pb.AnswerQuestionReq) (*grpc_pb.AnswerQuestionResp, error) {
|
||||||
question, err := repository.NewQuestionDao(ctx).FindBySn(req.Sn)
|
question, err := repository.NewQuestionDao(ctx).FindBySn(req.Sn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("AnswerQuestion error: %v", err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
options := make([]string, 0)
|
options := make([]string, 0)
|
||||||
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
|
||||||
log.Errorf("AnswerQuestion json.Unmarshal error: %v, data: %v", err, question.Options)
|
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
// 保存答题记录
|
// 保存答题记录
|
||||||
if utils.ShouldBindUsn(ctx, &req.USN) {
|
if utils.ShouldBindUsn(ctx, &req.USN) {
|
||||||
@@ -203,8 +193,7 @@ func (s *Server) AnswerQuestion(ctx context.Context, req *grpc_pb.AnswerQuestion
|
|||||||
func (s *Server) GetAllCategory(ctx context.Context, req *grpc_pb.GetAllCategoryReq) (*grpc_pb.GetAllCategoryResp, error) {
|
func (s *Server) GetAllCategory(ctx context.Context, req *grpc_pb.GetAllCategoryReq) (*grpc_pb.GetAllCategoryResp, error) {
|
||||||
categoryList, err := repository.NewCategoryDao(ctx).FindAll()
|
categoryList, err := repository.NewCategoryDao(ctx).FindAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("GetAllCategory error: %v", err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
categories := make([]*grpc_pb.GetAllCategoryItem, 0)
|
categories := make([]*grpc_pb.GetAllCategoryItem, 0)
|
||||||
for _, category := range categoryList {
|
for _, category := range categoryList {
|
||||||
@@ -225,8 +214,7 @@ func (s *Server) GetRecord(ctx context.Context, req *grpc_pb.GetRecordReq) (*grp
|
|||||||
}
|
}
|
||||||
records, count, err := repository.NewRecordDao(ctx).FindByUSN(req.USN, int(req.Page), int(req.PageSize))
|
records, count, err := repository.NewRecordDao(ctx).FindByUSN(req.USN, int(req.Page), int(req.PageSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("GetRecord error: %v", err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
resp := make([]*grpc_pb.GetRecordItem, 0)
|
resp := make([]*grpc_pb.GetRecordItem, 0)
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
|
|||||||
Reference in New Issue
Block a user