134 lines
3.8 KiB
Go
134 lines
3.8 KiB
Go
package antrianoperasi
|
|
|
|
import (
|
|
"log"
|
|
|
|
dokter "antrian-operasi/internal/domain/reference/dokter"
|
|
kategori "antrian-operasi/internal/domain/reference/kategori"
|
|
spesialis "antrian-operasi/internal/domain/reference/spesialis"
|
|
"antrian-operasi/internal/shared"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type AntrianOperasiHandler struct {
|
|
repo IAntrianOperasiRepository
|
|
repoKategori kategori.IKategoriRepository
|
|
repoSpesialis spesialis.ISpesialisRepository
|
|
repoDokter dokter.IDokterRepository
|
|
}
|
|
|
|
func NewAntrianOperasiHandler(
|
|
repo IAntrianOperasiRepository,
|
|
repoKategori kategori.IKategoriRepository,
|
|
repoSpesialis spesialis.ISpesialisRepository,
|
|
repoDokter dokter.IDokterRepository) AntrianOperasiHandler {
|
|
return AntrianOperasiHandler{
|
|
repo, repoKategori, repoSpesialis, repoDokter,
|
|
}
|
|
}
|
|
|
|
// CreateAntrianOperasi godoc
|
|
// @Summary Create Antrian Operasi
|
|
// @Tags Antrian Operasi
|
|
// @Param body body CreatePasienOperasiRequest true "Create Pasien Operasi"
|
|
// @Success 200 {object} shared.BaseResponse
|
|
// @Failure 500 {object} shared.BaseErrorResponse
|
|
// @Router /antrian-operasi/ [post]
|
|
func (h AntrianOperasiHandler) CreateAntrianOperasi(c *gin.Context) {
|
|
var req CreatePasienOperasiRequest
|
|
// Binding format JSON
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(500, shared.BaseErrorResponse{
|
|
Success: false,
|
|
Code: 500,
|
|
Message: "error bind json",
|
|
Errors: shared.ValidationError(err),
|
|
})
|
|
return
|
|
}
|
|
|
|
// Request data master validation
|
|
isValid, errValidation := req.DataValidation(c, h)
|
|
if isValid == false {
|
|
log.Printf("validation error : %s", errValidation)
|
|
c.JSON(500, shared.BaseErrorResponse{
|
|
Success: false,
|
|
Code: 500,
|
|
Message: "validation error",
|
|
Errors: errValidation,
|
|
})
|
|
return
|
|
}
|
|
|
|
// Start insert database
|
|
res, err := h.repo.CreateAntrianOperasi(c, req)
|
|
if err != nil {
|
|
log.Printf("insert error : %s", err)
|
|
errMessage := []string{err.Error()}
|
|
c.JSON(500, shared.BaseErrorResponse{
|
|
Success: false,
|
|
Code: 500,
|
|
Message: "insert error",
|
|
Errors: errMessage,
|
|
})
|
|
return
|
|
}
|
|
|
|
c.JSON(201, shared.ToBaseResponse(res, true, 201, "success insert antrian operasi"))
|
|
}
|
|
|
|
// ListAntrianOperasi godoc
|
|
// @Summary Get List Antrian Operasi
|
|
// @Tags Antrian Operasi
|
|
// @Param search query string false "Search Keyword"
|
|
// @Param type query string false "Type antrian : all, kategori, spesialis, sub-spesialis"
|
|
// @Param type_id query string false "Type id :id kategori, id spesialis, id sub-spesialis"
|
|
// @Param status query string false "Status : 1, 2, 3, 4"
|
|
// @Param limit query string false "Limit" default(10)
|
|
// @Param offset query string false "Offset" default(0)
|
|
// @Success 200 {object} []PasienOperasi
|
|
// @Failure 500 {object} shared.BaseErrorResponse
|
|
// @Router /antrian-operasi/ [get]
|
|
func (h AntrianOperasiHandler) GetListAntrianOperasi(c *gin.Context) {
|
|
res, err := h.repo.SearchableListAntrianOperasi(c)
|
|
if err != nil {
|
|
c.JSON(500, shared.BaseErrorResponse{
|
|
Success: false,
|
|
Code: 500,
|
|
Message: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
c.JSON(200,
|
|
shared.ToBaseResponsePaginate(
|
|
res.Data, res.Paging, true, 200, "success get list antrian operasi",
|
|
))
|
|
}
|
|
|
|
// DetailAntrianOperasi godoc
|
|
// @Summary Detail List Antrian Operasi
|
|
// @Tags Antrian Operasi
|
|
// @Param id path string true "id antrian"
|
|
// @Success 200 {object} DetailPasienOperasiResponse
|
|
// @Failure 500 {object} shared.BaseErrorResponse
|
|
// @Router /antrian-operasi/{id} [get]
|
|
func (h AntrianOperasiHandler) GetDetailAntrianOperasi(c *gin.Context) {
|
|
id := c.Param("id")
|
|
res, err := h.repo.GetAntrianOperasiById(c, id)
|
|
if err != nil {
|
|
c.JSON(500, shared.BaseErrorResponse{
|
|
Success: false,
|
|
Code: 500,
|
|
Message: err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
c.JSON(200,
|
|
shared.ToBaseResponse(
|
|
res.MapToResponse(), true, 200, "success get antrian operasi",
|
|
))
|
|
}
|