first commit
This commit is contained in:
62
services/doctor/doctor.routes.go
Normal file
62
services/doctor/doctor.routes.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package doctor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/gorilla/mux"
|
||||
"sismedika.com/sas/westone/services/auth"
|
||||
"sismedika.com/sas/westone/types"
|
||||
"sismedika.com/sas/westone/utils"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
store types.DoctorStore
|
||||
}
|
||||
|
||||
func NewHandler(store types.DoctorStore) *Handler {
|
||||
return &Handler{store: store}
|
||||
}
|
||||
|
||||
func (h *Handler) RegisterRoutes(router *mux.Router) {
|
||||
doctorroutes := router.PathPrefix("/mddoctor").Subrouter()
|
||||
doctorroutes.Use(auth.AuthMiddleware)
|
||||
|
||||
doctorroutes.HandleFunc("/searchdoctor", h.handlerSearchDoctor).Methods(http.MethodPost)
|
||||
}
|
||||
|
||||
// SearchDoctor searches doctor by name, NIK, Doctor Code, DOB, or phone number
|
||||
//
|
||||
// @Summary Search Doctors listing
|
||||
// @Description Search Doctors by name, NIK, Doctor Code, DOB, or phone number
|
||||
// @Tags Doctor
|
||||
// @Accept json
|
||||
// @Param authorization header string true "Authorization token"
|
||||
// @Param parameter body types.SearchDoctorPayload true "parameter"
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]any
|
||||
// @Failure 400 {object} map[string]any
|
||||
// @Failure 500 {object} map[string]any
|
||||
// @Router /westone/api/v1/mddoctor/searchdoctor [post]
|
||||
func (h *Handler) handlerSearchDoctor(w http.ResponseWriter, r *http.Request) {
|
||||
var payload types.SearchDoctorPayload
|
||||
if err := utils.ParseJSON(r, &payload); err != nil {
|
||||
utils.WriteError(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := utils.Validate.Struct(payload); err != nil {
|
||||
erros := err.(validator.ValidationErrors)
|
||||
utils.WriteError(w, http.StatusBadRequest, fmt.Errorf("invalid payload: %v", erros))
|
||||
return
|
||||
}
|
||||
|
||||
response, err := h.store.SearchDoctor(payload.Keyword, payload.Page, payload.Perpage)
|
||||
if err != nil {
|
||||
utils.WriteError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
utils.WriteJSON(w, http.StatusOK, response)
|
||||
}
|
||||
Reference in New Issue
Block a user