-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2c3dbb
commit 402c995
Showing
18 changed files
with
640 additions
and
609 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/GenerateNU/sac/backend/src/services" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type CategoryTagController struct { | ||
categoryTagService services.CategoryTagServiceInterface | ||
} | ||
|
||
func NewCategoryTagController(categoryTagService services.CategoryTagServiceInterface) *CategoryTagController { | ||
return &CategoryTagController{categoryTagService: categoryTagService} | ||
} | ||
|
||
func (t *CategoryTagController) GetTagByCategory(c *fiber.Ctx) error { | ||
tag, err := t.categoryTagService.GetTagByCategory(c.Params("categoryID"), c.Params("tagID")) | ||
if err != nil { | ||
return err.FiberError(c) | ||
} | ||
|
||
return c.Status(fiber.StatusOK).JSON(&tag) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/GenerateNU/sac/backend/src/errors" | ||
"github.com/GenerateNU/sac/backend/src/models" | ||
"github.com/GenerateNU/sac/backend/src/services" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
type UserTagController struct { | ||
userTagService services.UserTagServiceInterface | ||
} | ||
|
||
func NewUserTagController(userTagService services.UserTagServiceInterface) *UserTagController { | ||
return &UserTagController{userTagService: userTagService} | ||
} | ||
|
||
func (u *UserTagController) GetUserTags(c *fiber.Ctx) error { | ||
tags, err := u.userTagService.GetUserTags(c.Params("userID")) | ||
if err != nil { | ||
return err.FiberError(c) | ||
} | ||
return c.Status(fiber.StatusOK).JSON(&tags) | ||
} | ||
|
||
func (u *UserTagController) CreateUserTags(c *fiber.Ctx) error { | ||
var requestBody models.CreateUserTagsBody | ||
if err := c.BodyParser(&requestBody); err != nil { | ||
return errors.FailedToParseRequestBody.FiberError(c) | ||
} | ||
|
||
tags, err := u.userTagService.CreateUserTags(c.Params("userID"), requestBody) | ||
if err != nil { | ||
return err.FiberError(c) | ||
} | ||
|
||
return c.Status(fiber.StatusCreated).JSON(&tags) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package services | ||
|
||
import ( | ||
"github.com/GenerateNU/sac/backend/src/errors" | ||
"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" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type CategoryTagServiceInterface interface { | ||
GetTagByCategory(categoryID string, tagID string) (*models.Tag, *errors.Error) | ||
} | ||
|
||
type CategoryTagService struct { | ||
DB *gorm.DB | ||
Validate *validator.Validate | ||
} | ||
|
||
func NewCategoryTagService(db *gorm.DB, validate *validator.Validate) *CategoryTagService { | ||
return &CategoryTagService{DB: db, Validate: validate} | ||
} | ||
|
||
func (t *CategoryTagService) GetTagByCategory(categoryID string, tagID string) (*models.Tag, *errors.Error) { | ||
categoryIDAsUUID, idErr := utilities.ValidateID(categoryID) | ||
|
||
if idErr != nil { | ||
return nil, idErr | ||
} | ||
|
||
tagIDAsUUID, idErr := utilities.ValidateID(tagID) | ||
|
||
if idErr != nil { | ||
return nil, idErr | ||
} | ||
|
||
return transactions.GetTagByCategory(t.DB, *categoryIDAsUUID, *tagIDAsUUID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.