initiate base response

This commit is contained in:
renaldybrada
2026-01-28 09:45:45 +07:00
parent 43fa498b54
commit 8e272b5c48
4 changed files with 39 additions and 4 deletions
+9 -1
View File
@@ -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)
}
+17
View File
@@ -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,
}
}