fix : fixing response adddress domain structure
This commit is contained in:
parent
58709f67c5
commit
80e5673bff
|
@ -16,6 +16,19 @@ type AddressInput struct {
|
||||||
Geography string `json:"geography" validate:"required"`
|
Geography string `json:"geography" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AddressResponse struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Province string `json:"province"`
|
||||||
|
District string `json:"district"`
|
||||||
|
Subdistrict string `json:"subdistrict"`
|
||||||
|
PostalCode int `json:"postalCode"`
|
||||||
|
Village string `json:"village"`
|
||||||
|
Detail string `json:"detail"`
|
||||||
|
Geography string `json:"geography"`
|
||||||
|
CreatedAt string `json:"createdAt"`
|
||||||
|
UpdatedAt string `json:"updatedAt"`
|
||||||
|
}
|
||||||
|
|
||||||
func (c *AddressInput) ValidatePost() error {
|
func (c *AddressInput) ValidatePost() error {
|
||||||
err := validate.Struct(c)
|
err := validate.Struct(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -18,7 +18,6 @@ func CreateAddress(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := input.ValidatePost(); err != nil {
|
if err := input.ValidatePost(); err != nil {
|
||||||
|
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusBadRequest).JSON(utils.FormatResponse(
|
||||||
fiber.StatusBadRequest,
|
fiber.StatusBadRequest,
|
||||||
err.Error(),
|
err.Error(),
|
||||||
|
@ -27,7 +26,6 @@ func CreateAddress(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
userID := c.Locals("userID").(string)
|
userID := c.Locals("userID").(string)
|
||||||
|
|
||||||
address, err := services.CreateAddress(userID, input)
|
address, err := services.CreateAddress(userID, input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusInternalServerError).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusInternalServerError).JSON(utils.FormatResponse(
|
||||||
|
@ -37,17 +35,20 @@ func CreateAddress(c *fiber.Ctx) error {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
addressResponse := map[string]interface{}{
|
createdAtFormatted := utils.FormatDateToIndonesianFormat(address.CreatedAt)
|
||||||
"id": address.ID,
|
updatedAtFormatted := utils.FormatDateToIndonesianFormat(address.UpdatedAt)
|
||||||
"province": address.Province,
|
|
||||||
"district": address.District,
|
addressResponse := dto.AddressResponse{
|
||||||
"subdistrict": address.Subdistrict,
|
ID: address.ID,
|
||||||
"postalCode": address.PostalCode,
|
Province: address.Province,
|
||||||
"village": address.Village,
|
District: address.District,
|
||||||
"detail": address.Detail,
|
Subdistrict: address.Subdistrict,
|
||||||
"geography": address.Geography,
|
PostalCode: address.PostalCode,
|
||||||
"createdAt": address.CreatedAt,
|
Village: address.Village,
|
||||||
"updatedAt": address.UpdatedAt,
|
Detail: address.Detail,
|
||||||
|
Geography: address.Geography,
|
||||||
|
CreatedAt: createdAtFormatted,
|
||||||
|
UpdatedAt: updatedAtFormatted,
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
||||||
|
@ -59,7 +60,6 @@ func CreateAddress(c *fiber.Ctx) error {
|
||||||
|
|
||||||
func GetListAddress(c *fiber.Ctx) error {
|
func GetListAddress(c *fiber.Ctx) error {
|
||||||
userID := c.Locals("userID").(string)
|
userID := c.Locals("userID").(string)
|
||||||
|
|
||||||
addresses, err := services.GetAllAddressesByUserID(userID)
|
addresses, err := services.GetAllAddressesByUserID(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(fiber.StatusNotFound).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusNotFound).JSON(utils.FormatResponse(
|
||||||
|
@ -69,20 +69,23 @@ func GetListAddress(c *fiber.Ctx) error {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
addressResponses := []map[string]interface{}{}
|
var addressResponses []dto.AddressResponse
|
||||||
|
|
||||||
for _, address := range addresses {
|
for _, address := range addresses {
|
||||||
addressResponse := map[string]interface{}{
|
|
||||||
"id": address.ID,
|
createdAtFormatted := utils.FormatDateToIndonesianFormat(address.CreatedAt)
|
||||||
"province": address.Province,
|
updatedAtFormatted := utils.FormatDateToIndonesianFormat(address.UpdatedAt)
|
||||||
"district": address.District,
|
|
||||||
"subdistrict": address.Subdistrict,
|
addressResponse := dto.AddressResponse{
|
||||||
"postalCode": address.PostalCode,
|
ID: address.ID,
|
||||||
"village": address.Village,
|
Province: address.Province,
|
||||||
"detail": address.Detail,
|
District: address.District,
|
||||||
"geography": address.Geography,
|
Subdistrict: address.Subdistrict,
|
||||||
"createdAt": address.CreatedAt,
|
PostalCode: address.PostalCode,
|
||||||
"updatedAt": address.UpdatedAt,
|
Village: address.Village,
|
||||||
|
Detail: address.Detail,
|
||||||
|
Geography: address.Geography,
|
||||||
|
CreatedAt: createdAtFormatted,
|
||||||
|
UpdatedAt: updatedAtFormatted,
|
||||||
}
|
}
|
||||||
addressResponses = append(addressResponses, addressResponse)
|
addressResponses = append(addressResponses, addressResponse)
|
||||||
}
|
}
|
||||||
|
@ -95,7 +98,6 @@ func GetListAddress(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAddressByID(c *fiber.Ctx) error {
|
func GetAddressByID(c *fiber.Ctx) error {
|
||||||
|
|
||||||
addressID := c.Params("id")
|
addressID := c.Params("id")
|
||||||
|
|
||||||
address, err := services.GetAddressByID(addressID)
|
address, err := services.GetAddressByID(addressID)
|
||||||
|
@ -107,17 +109,20 @@ func GetAddressByID(c *fiber.Ctx) error {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
addressResponse := map[string]interface{}{
|
createdAtFormatted := utils.FormatDateToIndonesianFormat(address.CreatedAt)
|
||||||
"id": address.ID,
|
updatedAtFormatted := utils.FormatDateToIndonesianFormat(address.UpdatedAt)
|
||||||
"province": address.Province,
|
|
||||||
"district": address.District,
|
addressResponse := dto.AddressResponse{
|
||||||
"subdistrict": address.Subdistrict,
|
ID: address.ID,
|
||||||
"postalCode": address.PostalCode,
|
Province: address.Province,
|
||||||
"village": address.Village,
|
District: address.District,
|
||||||
"detail": address.Detail,
|
Subdistrict: address.Subdistrict,
|
||||||
"geography": address.Geography,
|
PostalCode: address.PostalCode,
|
||||||
"createdAt": address.CreatedAt,
|
Village: address.Village,
|
||||||
"updatedAt": address.UpdatedAt,
|
Detail: address.Detail,
|
||||||
|
Geography: address.Geography,
|
||||||
|
CreatedAt: createdAtFormatted,
|
||||||
|
UpdatedAt: updatedAtFormatted,
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
||||||
|
@ -128,10 +133,10 @@ func GetAddressByID(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateAddress(c *fiber.Ctx) error {
|
func UpdateAddress(c *fiber.Ctx) error {
|
||||||
|
|
||||||
addressID := c.Params("id")
|
addressID := c.Params("id")
|
||||||
|
|
||||||
var input dto.AddressInput
|
var input dto.AddressInput
|
||||||
|
|
||||||
if err := c.BodyParser(&input); err != nil {
|
if err := c.BodyParser(&input); err != nil {
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusBadRequest).JSON(utils.FormatResponse(
|
||||||
fiber.StatusBadRequest,
|
fiber.StatusBadRequest,
|
||||||
|
@ -157,17 +162,20 @@ func UpdateAddress(c *fiber.Ctx) error {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
addressResponse := map[string]interface{}{
|
createdAtFormatted := utils.FormatDateToIndonesianFormat(address.CreatedAt)
|
||||||
"id": address.ID,
|
updatedAtFormatted := utils.FormatDateToIndonesianFormat(address.UpdatedAt)
|
||||||
"province": address.Province,
|
|
||||||
"district": address.District,
|
addressResponse := dto.AddressResponse{
|
||||||
"subdistrict": address.Subdistrict,
|
ID: address.ID,
|
||||||
"postalCode": address.PostalCode,
|
Province: address.Province,
|
||||||
"village": address.Village,
|
District: address.District,
|
||||||
"detail": address.Detail,
|
Subdistrict: address.Subdistrict,
|
||||||
"geography": address.Geography,
|
PostalCode: address.PostalCode,
|
||||||
"createdAt": address.CreatedAt,
|
Village: address.Village,
|
||||||
"updatedAt": address.UpdatedAt,
|
Detail: address.Detail,
|
||||||
|
Geography: address.Geography,
|
||||||
|
CreatedAt: createdAtFormatted,
|
||||||
|
UpdatedAt: updatedAtFormatted,
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
return c.Status(fiber.StatusOK).JSON(utils.FormatResponse(
|
||||||
|
@ -178,7 +186,6 @@ func UpdateAddress(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteAddress(c *fiber.Ctx) error {
|
func DeleteAddress(c *fiber.Ctx) error {
|
||||||
|
|
||||||
addressID := c.Params("id")
|
addressID := c.Params("id")
|
||||||
|
|
||||||
err := services.DeleteAddress(addressID)
|
err := services.DeleteAddress(addressID)
|
||||||
|
|
Loading…
Reference in New Issue