Files
api-antrian-operasi/internal/domain/reference/dokter/handler.go
2026-02-03 12:31:41 +07:00

72 lines
1.6 KiB
Go

package dokter
import (
"log"
"net/http"
baseResponse "antrian-operasi/internal/shared"
"github.com/gin-gonic/gin"
)
type DokterHandler struct {
repo IDokterRepository
}
func NewDokterHandler(repo IDokterRepository) DokterHandler {
return DokterHandler{repo}
}
// GetListDokter godoc
// @Summary Get List Dokter
// @Tags Dokter
// @Param search query string false "Search keyword"
// @Param limit query string false "Limit" default(10)
// @Param offset query string false "Offset" default(0)
// @Success 200 {object} []DokterResponse
// @Failure 500 {object} shared.BaseErrorResponse
// @Router /reference/dokter/ [get]
func (h DokterHandler) ListDokter(c *gin.Context) {
result, err := h.repo.SearchableListDokter(c)
if err != nil {
errorResponse := baseResponse.BaseErrorResponse{
Success: false,
Code: 500,
Message: err.Error(),
}
c.JSON(http.StatusInternalServerError, errorResponse)
return
}
response := baseResponse.ToBaseResponsePaginate(
result.Data.ToResponseList(),
result.Paging,
true,
200,
"success get doctor's list")
c.JSON(http.StatusOK, response)
}
// Test repository GetDokterById, soon to be deleted
func (h DokterHandler) GetDokterById(c *gin.Context) {
var result DokterModel
idDokter := c.Param("id")
result, err := h.repo.GetDokterById(c, idDokter)
if err != nil {
log.Printf("something went wrong : %s", err)
c.JSON(http.StatusInternalServerError, err)
return
}
response := baseResponse.ToBaseResponse(
result.ToResponse(),
true,
200,
"success get doctor's list")
c.JSON(http.StatusOK, response)
}