add org_id and health endpoint
This commit is contained in:
@@ -14,6 +14,7 @@ func (h *Handler) CreateEvent(c echo.Context) (err error) {
|
||||
newEvent := new(model.Event)
|
||||
event := new(model.CreateEvent)
|
||||
authorId, err := strconv.Atoi(c.Request().Header.Get("UserId"))
|
||||
orgId, err := strconv.Atoi(c.Request().Header.Get("UserOrganizationId"))
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusUnauthorized)
|
||||
@@ -40,6 +41,7 @@ func (h *Handler) CreateEvent(c echo.Context) (err error) {
|
||||
newEvent.MedicalCardId = event.MedicalCardId
|
||||
newEvent.Status = event.Status
|
||||
newEvent.Services = event.Services
|
||||
newEvent.OrgId = uint(orgId)
|
||||
|
||||
tx := h.DB.Create(&newEvent)
|
||||
|
||||
@@ -57,8 +59,13 @@ func (h *Handler) GetEvents(c echo.Context) (err error) {
|
||||
var events []model.Event
|
||||
query := c.Request().URL.Query()
|
||||
_, _, filterMap := utils.GetFilterParams(query)
|
||||
orgId, err := strconv.Atoi(c.Request().Header.Get("UserOrganizationId"))
|
||||
|
||||
tx := h.DB
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
tx := h.DB.Where("org_id = ?", orgId)
|
||||
|
||||
if len(filterMap) > 0 {
|
||||
tx = tx.Where("start >= ?", filterMap["start"]).Where("\"end\" <= ?", filterMap["end"])
|
||||
@@ -89,20 +96,42 @@ func (h *Handler) GetEvents(c echo.Context) (err error) {
|
||||
func (h *Handler) GetEvent(c echo.Context) error {
|
||||
var event model.Event
|
||||
id := c.Param("id")
|
||||
orgId, err := strconv.Atoi(c.Request().Header.Get("UserOrganizationId"))
|
||||
|
||||
tx := h.DB.First(&event, id)
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
tx := h.DB.Where("org_id = ?", orgId).First(&event, id)
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return c.NoContent(http.StatusNotFound)
|
||||
}
|
||||
|
||||
usersMap, err := services.GetUsers([]uint{event.EmployeeId, event.AuthorId}, c.Request().Header)
|
||||
|
||||
if err != nil {
|
||||
return c.HTML(http.StatusBadGateway, err.Error())
|
||||
}
|
||||
|
||||
employee := usersMap[event.EmployeeId]
|
||||
author := usersMap[event.AuthorId]
|
||||
|
||||
event.Employee = employee
|
||||
event.Author = author
|
||||
|
||||
return c.JSON(http.StatusOK, event)
|
||||
}
|
||||
|
||||
func (h *Handler) DeleteEvent(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
orgId, err := strconv.Atoi(c.Request().Header.Get("UserOrganizationId"))
|
||||
|
||||
tx := h.DB.Delete(&model.Event{}, id)
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
tx := h.DB.Where("org_id = ?", orgId).Delete(&model.Event{}, id)
|
||||
|
||||
if tx.RowsAffected == 0 {
|
||||
return c.NoContent(http.StatusNotFound)
|
||||
|
||||
14
handler/health.go
Normal file
14
handler/health.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo/v4"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Health(c echo.Context) error {
|
||||
type Resp struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, Resp{Status: "OK"})
|
||||
}
|
||||
Reference in New Issue
Block a user