initiate base response
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user