Skip to content

Commit

Permalink
feat(controllers/reward.SetComment)!: match api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince213 committed May 12, 2024
1 parent 74e8f66 commit c8df9e7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/controllers/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import (
func RewardRoutes(r fiber.Router) {
route := r.Group("/reward")
route.Get("/ranklist", reward.Ranklist)
route.Post("/set/:id", reward.SetComment)
route.Post("/set", reward.SetComment)
}
10 changes: 2 additions & 8 deletions internal/controllers/reward/setcomment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"coursebench-backend/pkg/errors"
"coursebench-backend/pkg/models"
"coursebench-backend/pkg/queries"
"strconv"

"github.com/gofiber/fiber/v2"
"gorm.io/gorm"
)

type SetCommentRequest struct {
ID int `json:"id"`
Reward int `json:"reward"`
}

Expand All @@ -23,12 +23,6 @@ func SetComment(c *fiber.Ctx) error {
return errors.Wrap(err, errors.InvalidArgument)
}

idRaw := c.Params("id", "GG")
id, err := strconv.Atoi(idRaw)
if err != nil {
return errors.New(errors.InvalidArgument)
}

uid, err := session.GetUserID(c)
if err != nil {
uid = 0
Expand All @@ -44,7 +38,7 @@ func SetComment(c *fiber.Ctx) error {
}

comment := &models.Comment{}
result := db.First(&comment, id)
result := db.First(&comment, request.ID)
if result.Error != nil {
return errors.Wrap(result.Error, errors.DatabaseError)
}
Expand Down

0 comments on commit c8df9e7

Please sign in to comment.