You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"healthapi/internal/model"
|
|
"healthapi/internal/svc"
|
|
"healthapi/internal/types"
|
|
"healthapi/pkg/errorx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetAssessmentHistoryLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetAssessmentHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAssessmentHistoryLogic {
|
|
return &GetAssessmentHistoryLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetAssessmentHistoryLogic) GetAssessmentHistory() (resp *types.AssessmentHistoryResp, err error) {
|
|
userID, err := GetUserIDFromCtx(l.ctx)
|
|
if err != nil {
|
|
return nil, errorx.ErrUnauthorized
|
|
}
|
|
|
|
var assessments []model.ConstitutionAssessment
|
|
l.svcCtx.DB.Where("user_id = ?", userID).Order("assessed_at DESC").Limit(10).Find(&assessments)
|
|
|
|
resp = &types.AssessmentHistoryResp{
|
|
History: make([]types.AssessmentResult, 0, len(assessments)),
|
|
}
|
|
|
|
for _, a := range assessments {
|
|
resp.History = append(resp.History, *parseAssessment(&a))
|
|
}
|
|
|
|
return resp, nil
|
|
}
|
|
|