update events
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
version: "3.9"
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:13.3
|
||||
astra_events:
|
||||
image: postgres:14.8
|
||||
environment:
|
||||
POSTGRES_DB: "astra_events_db"
|
||||
POSTGRES_USER: "astra_events"
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
)
|
||||
|
||||
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"))
|
||||
@@ -33,15 +32,10 @@ func (h *Handler) CreateEvent(c echo.Context) (err error) {
|
||||
employee := usersMap[event.EmployeeId]
|
||||
author := usersMap[uint(authorId)]
|
||||
|
||||
newEvent.Start = event.Start
|
||||
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, err := utils.TypeConverter[model.Event](event)
|
||||
|
||||
newEvent.OrgId = uint(orgId)
|
||||
newEvent.AuthorId = uint(authorId)
|
||||
|
||||
tx := h.DB.Create(&newEvent)
|
||||
|
||||
|
||||
16
pkg/utils/type-coverter.go
Normal file
16
pkg/utils/type-coverter.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user