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)
|
app.Put("/apirijikid/user/update-user", middleware.AuthMiddleware, controllers.UpdateUser)
|
||||||
|
|
||||||
// # user set pin
|
// # 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.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)
|
||||||
|
app.Put("/apirijikid/user/update-pin", middleware.AuthMiddleware, controllers.UpdatePin)
|
||||||
|
|
||||||
// # address routing
|
// # address routing
|
||||||
app.Get("/apirijikid/addresses", middleware.AuthMiddleware, controllers.GetListAddress)
|
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 {
|
func GetPin(c *fiber.Ctx) error {
|
||||||
var input dto.PinInput
|
var input dto.PinInput
|
||||||
if err := c.BodyParser(&input); err != nil {
|
if err := c.BodyParser(&input); err != nil {
|
||||||
|
@ -74,7 +100,7 @@ func GetPin(c *fiber.Ctx) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusNotFound).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusNotFound).JSON(utils.FormatResponse(
|
||||||
fiber.StatusNotFound,
|
fiber.StatusNotFound,
|
||||||
"PIN tidak ditemukan",
|
"Sepertinya anda belum membuat pin",
|
||||||
nil,
|
nil,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -83,16 +109,10 @@ func GetPin(c *fiber.Ctx) error {
|
||||||
|
|
||||||
if isPinValid {
|
if isPinValid {
|
||||||
|
|
||||||
formattedCreatedAt := utils.FormatDateToIndonesianFormat(pin.CreatedAt)
|
|
||||||
formattedUpdatedAt := utils.FormatDateToIndonesianFormat(pin.UpdatedAt)
|
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
||||||
fiber.StatusOK,
|
fiber.StatusOK,
|
||||||
"PIN benar",
|
"PIN benar",
|
||||||
map[string]interface{}{
|
true,
|
||||||
"createdAt": formattedCreatedAt,
|
|
||||||
"updatedAt": formattedUpdatedAt,
|
|
||||||
},
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue