fix: fixing response and add cek status user pin
This commit is contained in:
parent
5d98599f05
commit
58709f67c5
|
@ -24,9 +24,11 @@ func AppRouter(app *fiber.App) {
|
|||
app.Put("/apirijikid/user/update-user", middleware.AuthMiddleware, controllers.UpdateUser)
|
||||
|
||||
// # user set pin
|
||||
app.Get("/apirijikid/user/get-pin", middleware.AuthMiddleware, controllers.GetPin)
|
||||
app.Get("/apirijikid/user/verif-pin", middleware.AuthMiddleware, controllers.GetPin)
|
||||
app.Get("/apirijikid/user/cek-pin-status", middleware.AuthMiddleware, controllers.GetPinStatus)
|
||||
app.Post("/apirijikid/user/set-pin", middleware.AuthMiddleware, controllers.CreatePin)
|
||||
app.Put("/apirijikid/user/update-pin", middleware.AuthMiddleware, controllers.UpdatePin)
|
||||
app.Put("/apirijikid/user/update-pin", middleware.AuthMiddleware, controllers.UpdatePin)
|
||||
|
||||
// # address routing
|
||||
app.Get("/apirijikid/addresses", middleware.AuthMiddleware, controllers.GetListAddress)
|
||||
|
|
|
@ -59,6 +59,32 @@ func CreatePin(c *fiber.Ctx) error {
|
|||
))
|
||||
}
|
||||
|
||||
func GetPinStatus(c *fiber.Ctx) error {
|
||||
userID := c.Locals("userID").(string)
|
||||
|
||||
pin, err := services.GetPinByUserID(userID)
|
||||
if err != nil {
|
||||
|
||||
return c.Status(fiber.StatusNotFound).JSON(utils.FormatResponse(
|
||||
fiber.StatusNotFound,
|
||||
"Anda belum membuat PIN",
|
||||
nil,
|
||||
))
|
||||
}
|
||||
|
||||
formattedCreatedAt := utils.FormatDateToIndonesianFormat(pin.CreatedAt)
|
||||
formattedUpdatedAt := utils.FormatDateToIndonesianFormat(pin.UpdatedAt)
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
||||
fiber.StatusOK,
|
||||
"PIN sudah dibuat",
|
||||
map[string]interface{}{
|
||||
"createdAt": formattedCreatedAt,
|
||||
"updatedAt": formattedUpdatedAt,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
func GetPin(c *fiber.Ctx) error {
|
||||
var input dto.PinInput
|
||||
if err := c.BodyParser(&input); err != nil {
|
||||
|
@ -74,7 +100,7 @@ func GetPin(c *fiber.Ctx) error {
|
|||
if err != nil {
|
||||
return c.Status(fiber.StatusNotFound).JSON(utils.FormatResponse(
|
||||
fiber.StatusNotFound,
|
||||
"PIN tidak ditemukan",
|
||||
"Sepertinya anda belum membuat pin",
|
||||
nil,
|
||||
))
|
||||
}
|
||||
|
@ -83,16 +109,10 @@ func GetPin(c *fiber.Ctx) error {
|
|||
|
||||
if isPinValid {
|
||||
|
||||
formattedCreatedAt := utils.FormatDateToIndonesianFormat(pin.CreatedAt)
|
||||
formattedUpdatedAt := utils.FormatDateToIndonesianFormat(pin.UpdatedAt)
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
||||
fiber.StatusOK,
|
||||
"PIN benar",
|
||||
map[string]interface{}{
|
||||
"createdAt": formattedCreatedAt,
|
||||
"updatedAt": formattedUpdatedAt,
|
||||
},
|
||||
true,
|
||||
))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue