first commit
This commit is contained in:
57
services/person/person.routes.go
Normal file
57
services/person/person.routes.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package person
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"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.PersonStore
|
||||
terminology types.TerminologyStore
|
||||
}
|
||||
|
||||
func NewHandler(store types.PersonStore, terminology types.TerminologyStore) *Handler {
|
||||
return &Handler{store: store, terminology: terminology}
|
||||
}
|
||||
|
||||
func (h *Handler) RegisterRoutes(router *mux.Router) {
|
||||
personroute := router.PathPrefix("/mdperson").Subrouter()
|
||||
personroute.Use(auth.AuthMiddleware)
|
||||
|
||||
personroute.HandleFunc("/get/{personID}", h.handleGetPersonByID).Methods(http.MethodGet)
|
||||
}
|
||||
|
||||
func (h *Handler) handleGetPersonByID(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
param, ok := vars["personID"]
|
||||
if !ok {
|
||||
utils.WriteError(w, http.StatusBadRequest, fmt.Errorf("missing params person id"))
|
||||
return
|
||||
}
|
||||
|
||||
personID, err := strconv.Atoi(param)
|
||||
if err != nil {
|
||||
utils.WriteError(w, http.StatusBadRequest, fmt.Errorf("invalid params person id"))
|
||||
return
|
||||
}
|
||||
|
||||
person, err := h.store.GetPersonByID(personID)
|
||||
if err != nil {
|
||||
utils.WriteError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := h.getDisplayTerminology(*person)
|
||||
if err != nil {
|
||||
utils.WriteError(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
utils.WriteJSON(w, http.StatusOK, json)
|
||||
}
|
||||
Reference in New Issue
Block a user