update events

This commit is contained in:
andrusyakka
2023-07-17 14:12:32 +03:00
parent 454c9bc82e
commit 1aa6b6c87e
3 changed files with 21 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
version: "3.9" version: "3.9"
services: services:
postgres: astra_events:
image: postgres:13.3 image: postgres:14.8
environment: environment:
POSTGRES_DB: "astra_events_db" POSTGRES_DB: "astra_events_db"
POSTGRES_USER: "astra_events" POSTGRES_USER: "astra_events"

View File

@@ -11,7 +11,6 @@ import (
) )
func (h *Handler) CreateEvent(c echo.Context) (err error) { func (h *Handler) CreateEvent(c echo.Context) (err error) {
newEvent := new(model.Event)
event := new(model.CreateEvent) event := new(model.CreateEvent)
authorId, err := strconv.Atoi(c.Request().Header.Get("UserId")) authorId, err := strconv.Atoi(c.Request().Header.Get("UserId"))
orgId, err := strconv.Atoi(c.Request().Header.Get("UserOrganizationId")) orgId, err := strconv.Atoi(c.Request().Header.Get("UserOrganizationId"))
@@ -33,15 +32,10 @@ func (h *Handler) CreateEvent(c echo.Context) (err error) {
employee := usersMap[event.EmployeeId] employee := usersMap[event.EmployeeId]
author := usersMap[uint(authorId)] author := usersMap[uint(authorId)]
newEvent.Start = event.Start newEvent, err := utils.TypeConverter[model.Event](event)
newEvent.End = event.End
newEvent.AuthorId = uint(authorId)
newEvent.EmployeeId = event.EmployeeId
newEvent.MemberId = event.MemberId
newEvent.MedicalCardId = event.MedicalCardId
newEvent.Status = event.Status
newEvent.Services = event.Services
newEvent.OrgId = uint(orgId) newEvent.OrgId = uint(orgId)
newEvent.AuthorId = uint(authorId)
tx := h.DB.Create(&newEvent) tx := h.DB.Create(&newEvent)

View File

@@ -0,0 +1,16 @@
package utils
import "encoding/json"
func TypeConverter[R any](data any) (*R, error) {
var result R
b, err := json.Marshal(&data)
if err != nil {
return nil, err
}
err = json.Unmarshal(b, &result)
if err != nil {
return nil, err
}
return &result, err
}