Skip to content

Commit

Permalink
add get my pets path
Browse files Browse the repository at this point in the history
  • Loading branch information
cjtim committed Sep 17, 2022
1 parent f18b9d5 commit 56ade89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions handlers/pet/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pet
import (
"strconv"

"github.com/cjtim/be-friends-api/internal/auth"
"github.com/cjtim/be-friends-api/repository"
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
Expand Down Expand Up @@ -30,13 +31,27 @@ func PetList(c *fiber.Ctx) error {
}
return c.JSON(pets)
}

// ALL
pets, err := repository.PetRepo.List()
if err != nil {
return err
}
return c.JSON(pets)
}

func PetMy(c *fiber.Ctx) error {
claims, err := auth.GetUserExtendedFromFiberCtx(c)
if err != nil {
return err
}
pets, err := repository.PetRepo.ListByUserId(claims.ID)
if err != nil {
return err
}
return c.JSON(pets)
}

func PetDetails(c *fiber.Ctx) error {
idStr := c.Params("pet_id", "")
if idStr == "" {
Expand Down
1 change: 1 addition & 0 deletions handlers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func Route(r *fiber.App) {
petRoute := v1.Group("/pet")
{
petRoute.Get("", pet.PetList) // list pet
petRoute.Get("/my", middlewares.JWTMiddleware, pet.PetMy) // My pet
petRoute.Get("/:pet_id", middlewares.JWTMiddleware, pet.PetDetails) // get pet by :pet_id
petRoute.Post("", middlewares.JWTMiddleware, pet.PetCreate) // create pet
petRoute.Put("", middlewares.JWTMiddleware, pet.PetCreate) // create pet
Expand Down

0 comments on commit 56ade89

Please sign in to comment.