diff --git a/internal/domain/reference/dokter/handler.go b/internal/domain/reference/dokter/handler.go index a551ff2..cfc4772 100644 --- a/internal/domain/reference/dokter/handler.go +++ b/internal/domain/reference/dokter/handler.go @@ -3,6 +3,8 @@ package dokter import ( "net/http" + baseResponse "antrian-operasi/internal/shared" + "github.com/gin-gonic/gin" ) @@ -22,5 +24,11 @@ func (h DokterHandler) ListDokter(c *gin.Context) { c.JSON(http.StatusInternalServerError, err) } - c.JSON(http.StatusOK, list.ToResponseList()) + response := baseResponse.ToBaseResponse( + list.ToResponseList(), + true, + 200, + "success get doctor's list") + + c.JSON(http.StatusOK, response) } diff --git a/internal/domain/reference/kategori/handler.go b/internal/domain/reference/kategori/handler.go index ebccf84..dab266d 100644 --- a/internal/domain/reference/kategori/handler.go +++ b/internal/domain/reference/kategori/handler.go @@ -3,6 +3,8 @@ package kategori import ( "net/http" + baseResponse "antrian-operasi/internal/shared" + "github.com/gin-gonic/gin" ) @@ -20,5 +22,7 @@ func (h KategoriHandler) ListKategoriOperasi(c *gin.Context) { c.JSON(http.StatusInternalServerError, err) } - c.JSON(http.StatusOK, list) + response := baseResponse.ToBaseResponse(list, true, 200, "success get kategori operasi") + + c.JSON(http.StatusOK, response) } diff --git a/internal/domain/reference/spesialis/handler.go b/internal/domain/reference/spesialis/handler.go index b191d5a..f413881 100644 --- a/internal/domain/reference/spesialis/handler.go +++ b/internal/domain/reference/spesialis/handler.go @@ -3,6 +3,8 @@ package spesialis import ( "net/http" + baseResponse "antrian-operasi/internal/shared" + "github.com/gin-gonic/gin" ) @@ -20,7 +22,9 @@ func (h SpesialisHandler) ListSpesialis(c *gin.Context) { c.JSON(http.StatusInternalServerError, err) } - c.JSON(http.StatusOK, list) + response := baseResponse.ToBaseResponse(list, true, 200, "success get list spesialis") + + c.JSON(http.StatusOK, response) } func (h SpesialisHandler) ListSubSpesialis(c *gin.Context) { @@ -29,5 +33,7 @@ func (h SpesialisHandler) ListSubSpesialis(c *gin.Context) { c.JSON(http.StatusInternalServerError, err) } - c.JSON(http.StatusOK, list) + response := baseResponse.ToBaseResponse(list, true, 200, "success get list spesialis") + + c.JSON(http.StatusOK, response) } diff --git a/internal/shared/baseResponse.go b/internal/shared/baseResponse.go new file mode 100644 index 0000000..6624249 --- /dev/null +++ b/internal/shared/baseResponse.go @@ -0,0 +1,17 @@ +package shared + +type BaseResponse[T any] struct { + Success bool `json:"success"` + Code int `json:"code"` + Message string `json:"message"` + Data T `json:"data"` +} + +func ToBaseResponse[T any](data T, isSuccess bool, code int, message string) BaseResponse[T] { + return BaseResponse[T]{ + Success: true, + Code: 200, + Message: message, + Data: data, + } +}