update logic check gigachat privilege and added update it in this controller
This commit is contained in:
parent
d2b54ef05c
commit
7ebc6a845d
2
go.mod
2
go.mod
@ -6,7 +6,7 @@ require (
|
||||
gitea.pena/PenaSide/common v0.0.0-20250421103113-7e4b3ae9e1e0
|
||||
gitea.pena/PenaSide/hlog v0.0.0-20241125221102-a54c29c002a9
|
||||
gitea.pena/PenaSide/trashlog v0.0.0-20250224122049-ddb4d72e9d07
|
||||
gitea.pena/SQuiz/common v0.0.0-20250606140534-fb272e7a1763
|
||||
gitea.pena/SQuiz/common v0.0.0-20250610100937-ce7096a3dd37
|
||||
github.com/caarlos0/env/v8 v8.0.0
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/gofiber/fiber/v2 v2.52.6
|
||||
|
4
go.sum
4
go.sum
@ -15,6 +15,10 @@ gitea.pena/SQuiz/common v0.0.0-20250605135518-be6361f19f4c h1:yCpGpEmugxNiIO0nNj
|
||||
gitea.pena/SQuiz/common v0.0.0-20250605135518-be6361f19f4c/go.mod h1:zCrUwDh0APpztKk6NUqTZv+zhjVbWpGBJiJ5z9dAH0U=
|
||||
gitea.pena/SQuiz/common v0.0.0-20250606140534-fb272e7a1763 h1:v0X5uSedghzFgu+ohU8ZnNaFIUm35hsZuaMoTqhNPJQ=
|
||||
gitea.pena/SQuiz/common v0.0.0-20250606140534-fb272e7a1763/go.mod h1:zCrUwDh0APpztKk6NUqTZv+zhjVbWpGBJiJ5z9dAH0U=
|
||||
gitea.pena/SQuiz/common v0.0.0-20250610095902-6f4789f42acd h1:ZQPOMUNq7ElkZnbhLNvvDRtUZ+OS4CAob4vtDwCXcdo=
|
||||
gitea.pena/SQuiz/common v0.0.0-20250610095902-6f4789f42acd/go.mod h1:zCrUwDh0APpztKk6NUqTZv+zhjVbWpGBJiJ5z9dAH0U=
|
||||
gitea.pena/SQuiz/common v0.0.0-20250610100937-ce7096a3dd37 h1:JD5YDqRrwvZ8AmxEZnek0O5vCTXFtfjw+7RGx/yKA8c=
|
||||
gitea.pena/SQuiz/common v0.0.0-20250610100937-ce7096a3dd37/go.mod h1:zCrUwDh0APpztKk6NUqTZv+zhjVbWpGBJiJ5z9dAH0U=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/ClickHouse/clickhouse-go v1.5.4 h1:cKjXeYLNWVJIx2J1K6H2CqyRmfwVJVY1OV1coaaFcI0=
|
||||
github.com/ClickHouse/clickhouse-go v1.5.4/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
|
||||
|
@ -554,15 +554,6 @@ func (r *Quiz) CreateQuizAuditory(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||
}
|
||||
|
||||
account, err := r.dal.AccountRepo.GetAccountByID(ctx.Context(), accountID)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("can`t get account by account id")
|
||||
}
|
||||
|
||||
if _, ok := account.Privileges["quizGigaChat"]; !ok {
|
||||
return ctx.Status(fiber.StatusPaymentRequired).SendString("payment required")
|
||||
}
|
||||
|
||||
var req struct {
|
||||
Sex int32 `json:"sex"` // 0 - female, 1 - male, 2 - not sex
|
||||
Age string `json:"age"`
|
||||
@ -582,6 +573,34 @@ func (r *Quiz) CreateQuizAuditory(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("Invalid request missing required fields")
|
||||
}
|
||||
|
||||
account, err := r.dal.AccountRepo.GetAccountByID(ctx.Context(), accountID)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("can`t get account by account id")
|
||||
}
|
||||
|
||||
quizAud, err := r.dal.QuizRepo.GetQuizById(ctx.Context(), accountID, uint64(quizID))
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
|
||||
}
|
||||
|
||||
if !quizAud.GigaChat {
|
||||
if _, ok := account.Privileges["quizGigaChat"]; !ok {
|
||||
return ctx.Status(fiber.StatusPaymentRequired).SendString("payment required")
|
||||
}
|
||||
err = r.dal.QuizRepo.UpdateGigaChatQuizFlag(ctx.Context(), quizID, accountID)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
|
||||
}
|
||||
|
||||
idPrivilege := account.Privileges["quizGigaChat"].ID
|
||||
newAmount := account.Privileges["quizGigaChat"].Amount - 1
|
||||
|
||||
err = r.dal.AccountRepo.UpdatePrivilegeAmount(ctx.Context(), idPrivilege, newAmount)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
result, err := r.dal.QuizRepo.CreateQuizAudience(ctx.Context(), quiz.DepsCreateQuizAudience{
|
||||
QuizID: quizID,
|
||||
Age: req.Age,
|
||||
|
Loading…
Reference in New Issue
Block a user