package dokter import ( "antrian-operasi/internal/shared" baseResponse "antrian-operasi/internal/shared" "log" "net/http" "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 Reference // @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) { limit := shared.ParseQueryLimit(c) offset := shared.ParseQueryOffset(c) search := c.Query("search") result, err := h.repo.SearchableListDokter(c, search, limit, offset) 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) }