Skip to content

Commit

Permalink
fix: Update services to use passed in validator over utilities.Valida…
Browse files Browse the repository at this point in the history
…teData
  • Loading branch information
michael-brennan2005 committed Jan 22, 2024
1 parent faac444 commit 5631e1a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions backend/src/services/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package services
import (
"github.com/GenerateNU/sac/backend/src/models"
"github.com/GenerateNU/sac/backend/src/transactions"
"github.com/GenerateNU/sac/backend/src/utilities"
"github.com/go-playground/validator/v10"

"github.com/gofiber/fiber/v2"
Expand All @@ -22,7 +21,7 @@ type CategoryService struct {
}

func (c *CategoryService) CreateCategory(category models.Category) (*models.Category, error) {
if err := utilities.ValidateData(category); err != nil {
if err := c.Validate.Struct(category); err != nil {
return nil, fiber.NewError(fiber.StatusBadRequest, "failed to validate the data")
}

Expand Down
4 changes: 2 additions & 2 deletions backend/src/services/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (t *TagService) CreateTag(tagBody models.CreateTagRequestBody) (*models.Tag
CategoryID: tagBody.CategoryID,
}

if err := utilities.ValidateData(tag); err != nil {
if err := t.Validate.Struct(tag); err != nil {
return nil, fiber.NewError(fiber.StatusBadRequest, "failed to validate the data")
}

Expand Down Expand Up @@ -56,7 +56,7 @@ func (t *TagService) UpdateTag(id string, tagBody models.UpdateTagRequestBody) (
CategoryID: tagBody.CategoryID,
}

if err := utilities.ValidateData(tag); err != nil {
if err := t.Validate.Struct(tag); err != nil {
return nil, fiber.NewError(fiber.StatusBadRequest, "failed to validate the data")
}

Expand Down

0 comments on commit 5631e1a

Please sign in to comment.