Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
492505cda5 | ||
|
|
75c32da189 | ||
|
|
f8df2b95b0 | ||
|
|
dc7e3d195e | ||
|
|
703e4f2ac1 | ||
|
|
48d7206356 | ||
|
|
20f69b4378 | ||
|
|
3edd2f8d93 | ||
|
|
7d3c4a26fe | ||
|
|
02ae90eb52 | ||
|
|
569d5ff7ed | ||
|
|
f3d2ab9919 | ||
|
|
075fbf89b0 | ||
|
|
1fb8c903dc | ||
|
|
9f72a3f8a2 | ||
|
|
7dba549faa | ||
|
|
81106a2599 | ||
|
|
11c0d1b989 | ||
|
|
2054c44aa2 | ||
|
|
5be30ff30f | ||
|
|
c5df48f0fb | ||
|
|
07efee246e | ||
|
|
ccba5f3844 | ||
|
|
aeccf956f7 | ||
|
|
d4ccd4d11b | ||
|
|
0364ad2d7d | ||
|
|
15f51516af | ||
|
|
95a66c2c16 | ||
|
|
fe09a32bbc | ||
|
|
a1705758df | ||
|
|
481bd0b788 | ||
|
|
3a514800e6 | ||
|
|
c55df47ada | ||
|
|
46afe2e794 | ||
|
|
03cb8c3e38 | ||
|
|
b74291f449 | ||
|
|
1aa6b6c87e |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
.idea
|
.idea
|
||||||
build
|
build
|
||||||
.env
|
.env
|
||||||
|
test
|
||||||
46
Dockerfile
46
Dockerfile
@@ -1,24 +1,24 @@
|
|||||||
FROM kandrusyak/go-build as build
|
FROM docker.io/kandrusyak/go-build as build
|
||||||
LABEL authors="andrusyakka@dopcore.com"
|
LABEL authors="andrusyakka@dopcore.com"
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ENV CGO_ENABLED 1
|
ENV CGO_ENABLED 1
|
||||||
|
|
||||||
COPY go.mod ./
|
COPY go.mod ./
|
||||||
|
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
COPY . ./
|
COPY . ./
|
||||||
|
|
||||||
RUN go build -o ./app
|
RUN go build -o ./app
|
||||||
|
|
||||||
FROM alpine:edge
|
FROM docker.io/alpine:edge
|
||||||
|
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
|
|
||||||
COPY --from=build /app /app
|
COPY --from=build /app /app
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
CMD ["/app/app"]
|
CMD ["/app/app"]
|
||||||
@@ -10,7 +10,8 @@ type ServerConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MSHosts struct {
|
type MSHosts struct {
|
||||||
UsersHost string
|
UsersHost string
|
||||||
|
PersonsHost string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -25,7 +26,8 @@ func New() *Config {
|
|||||||
ConnectionString: getEnv("CONNECTION_STRING", "host=localhost user=astra_events password=password dbname=astra_events_db port=5432 sslmode=disable TimeZone=Europe/Moscow"),
|
ConnectionString: getEnv("CONNECTION_STRING", "host=localhost user=astra_events password=password dbname=astra_events_db port=5432 sslmode=disable TimeZone=Europe/Moscow"),
|
||||||
},
|
},
|
||||||
MSHosts: MSHosts{
|
MSHosts: MSHosts{
|
||||||
UsersHost: getEnv("ASTRA-USERS", "http://localhost:8081"),
|
UsersHost: getEnv("ASTRA-USERS", "http://localhost:8083"),
|
||||||
|
PersonsHost: getEnv("ASTRA-PERSONAL-INFORMATION", "http://localhost:8082"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
SERVICE_REPLICAS=3
|
SERVICE_REPLICAS=1
|
||||||
SERVICE_PORT=8080
|
SERVICE_PORT=8080
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ apiVersion: v1
|
|||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
name: {{ .Values.app.fullName }}
|
name: {{ .Values.app.fullName }}
|
||||||
namespace: default
|
|
||||||
spec:
|
spec:
|
||||||
ports:
|
ports:
|
||||||
- port: {{ .Values.app.server.port }}
|
- port: {{ .Values.app.server.port }}
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
20
go.mod
20
go.mod
@@ -3,19 +3,28 @@ module astra-events
|
|||||||
go 1.21rc1
|
go 1.21rc1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/go-playground/validator/v10 v10.14.1
|
||||||
|
github.com/google/uuid v1.3.0
|
||||||
|
github.com/hashicorp/go-set v0.1.13
|
||||||
|
github.com/labstack/echo/v4 v4.10.2
|
||||||
|
gorm.io/driver/postgres v1.5.2
|
||||||
|
gorm.io/gorm v1.25.2
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||||
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
||||||
github.com/hashicorp/go-set v0.1.13 // indirect
|
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
|
||||||
github.com/jackc/pgx/v5 v5.3.1 // indirect
|
github.com/jackc/pgx/v5 v5.3.1 // indirect
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
github.com/labstack/echo/v4 v4.10.2 // indirect
|
|
||||||
github.com/labstack/gommon v0.4.0 // indirect
|
github.com/labstack/gommon v0.4.0 // indirect
|
||||||
github.com/lib/pq v1.10.9 // indirect
|
github.com/leodido/go-urn v1.2.4 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||||
github.com/mattn/go-sqlite3 v1.14.17 // indirect
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||||
golang.org/x/crypto v0.8.0 // indirect
|
golang.org/x/crypto v0.8.0 // indirect
|
||||||
@@ -23,7 +32,4 @@ require (
|
|||||||
golang.org/x/sys v0.7.0 // indirect
|
golang.org/x/sys v0.7.0 // indirect
|
||||||
golang.org/x/text v0.9.0 // indirect
|
golang.org/x/text v0.9.0 // indirect
|
||||||
golang.org/x/time v0.3.0 // indirect
|
golang.org/x/time v0.3.0 // indirect
|
||||||
gorm.io/driver/postgres v1.5.2 // indirect
|
|
||||||
gorm.io/driver/sqlite v1.5.2 // indirect
|
|
||||||
gorm.io/gorm v1.25.2 // indirect
|
|
||||||
)
|
)
|
||||||
|
|||||||
43
go.sum
43
go.sum
@@ -1,7 +1,22 @@
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
||||||
|
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||||
|
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||||
|
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||||
|
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||||
|
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||||
|
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||||
|
github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k=
|
||||||
|
github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
||||||
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
||||||
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||||
|
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/hashicorp/go-set v0.1.13 h1:k1B5goY3c7OKEzpK+gwAhJexxzAJwDN8kId8YvWrihA=
|
github.com/hashicorp/go-set v0.1.13 h1:k1B5goY3c7OKEzpK+gwAhJexxzAJwDN8kId8YvWrihA=
|
||||||
github.com/hashicorp/go-set v0.1.13/go.mod h1:0/D+R4MFUzJ6XmvjU7liXtznF1eQDxh84GJlhXw+lvo=
|
github.com/hashicorp/go-set v0.1.13/go.mod h1:0/D+R4MFUzJ6XmvjU7liXtznF1eQDxh84GJlhXw+lvo=
|
||||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||||
@@ -18,8 +33,8 @@ github.com/labstack/echo/v4 v4.10.2 h1:n1jAhnq/elIFTHr1EYpiYtyKgx4RW9ccVgkqByZaN
|
|||||||
github.com/labstack/echo/v4 v4.10.2/go.mod h1:OEyqf2//K1DFdE57vw2DRgWY0M7s65IVQO2FzvI4J5k=
|
github.com/labstack/echo/v4 v4.10.2/go.mod h1:OEyqf2//K1DFdE57vw2DRgWY0M7s65IVQO2FzvI4J5k=
|
||||||
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
|
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
|
||||||
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
|
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
|
||||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
|
||||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
||||||
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||||
@@ -27,35 +42,34 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
|
|||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
||||||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU=
|
||||||
|
github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||||
|
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||||
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
|
|
||||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
|
||||||
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
|
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
|
||||||
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
|
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
|
||||||
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
|
|
||||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
|
||||||
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
|
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
|
||||||
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
|
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
|
||||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
|
||||||
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
||||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
||||||
@@ -63,10 +77,9 @@ golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
|||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gorm.io/driver/postgres v1.5.2 h1:ytTDxxEv+MplXOfFe3Lzm7SjG09fcdb3Z/c056DTBx0=
|
gorm.io/driver/postgres v1.5.2 h1:ytTDxxEv+MplXOfFe3Lzm7SjG09fcdb3Z/c056DTBx0=
|
||||||
gorm.io/driver/postgres v1.5.2/go.mod h1:fmpX0m2I1PKuR7mKZiEluwrP3hbs+ps7JIGMUBpCgl8=
|
gorm.io/driver/postgres v1.5.2/go.mod h1:fmpX0m2I1PKuR7mKZiEluwrP3hbs+ps7JIGMUBpCgl8=
|
||||||
gorm.io/driver/sqlite v1.5.2 h1:TpQ+/dqCY4uCigCFyrfnrJnrW9zjpelWVoEVNy5qJkc=
|
|
||||||
gorm.io/driver/sqlite v1.5.2/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4=
|
|
||||||
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
|
|
||||||
gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho=
|
gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho=
|
||||||
gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
|
gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
|
||||||
|
|||||||
258
handler/event.go
258
handler/event.go
@@ -4,138 +4,278 @@ import (
|
|||||||
"astra-events/model"
|
"astra-events/model"
|
||||||
"astra-events/pkg/utils"
|
"astra-events/pkg/utils"
|
||||||
"astra-events/services"
|
"astra-events/services"
|
||||||
|
"errors"
|
||||||
|
"github.com/go-playground/validator/v10"
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/hashicorp/go-set"
|
"github.com/hashicorp/go-set"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"gorm.io/gorm"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// swagger:route POST /events/ Events CreateEvent
|
||||||
|
//
|
||||||
|
// responses:
|
||||||
|
// 200: Event
|
||||||
|
|
||||||
func (h *Handler) CreateEvent(c echo.Context) (err error) {
|
func (h *Handler) CreateEvent(c echo.Context) (err error) {
|
||||||
newEvent := new(model.Event)
|
var person *model.PersonalInformationApi
|
||||||
event := new(model.CreateEvent)
|
event := new(model.CreateEvent)
|
||||||
authorId, err := strconv.Atoi(c.Request().Header.Get("UserId"))
|
authorId, err := uuid.Parse(c.Request().Header.Get("X-User-Id"))
|
||||||
orgId, err := strconv.Atoi(c.Request().Header.Get("UserOrganizationId"))
|
orgId, err := uuid.Parse(c.Request().Header.Get("X-User-Organization-Id"))
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusUnauthorized, &utils.Error{
|
||||||
|
Type: "internal_error",
|
||||||
|
Message: "User in not authorized",
|
||||||
|
Code: "0002",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
err = c.Bind(&event)
|
||||||
|
err = h.Validator.Struct(event)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.NoContent(http.StatusUnauthorized)
|
var validationErrors validator.ValidationErrors
|
||||||
|
errors.As(err, &validationErrors)
|
||||||
|
Fields := make(map[string]string)
|
||||||
|
for _, validationError := range validationErrors {
|
||||||
|
Fields[validationError.Field()] = validationError.Tag()
|
||||||
|
}
|
||||||
|
return c.JSON(http.StatusBadRequest, &utils.ValidationError{
|
||||||
|
Type: "validation_error",
|
||||||
|
Message: err.Error(),
|
||||||
|
Code: "0001",
|
||||||
|
Fields: Fields,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = c.Bind(event); err != nil {
|
if event.Person.ID.ID() != 0 {
|
||||||
return c.NoContent(http.StatusBadRequest)
|
person, err = services.GetPerson(event.Person.ID, c.Request().Header, c)
|
||||||
|
if err != nil || person.ID != event.Person.ID {
|
||||||
|
return c.JSON(http.StatusBadGateway, &utils.Error{
|
||||||
|
Type: "internal_error",
|
||||||
|
Message: "Can't send request to persons service",
|
||||||
|
Code: "0003",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newPerson := model.PersonalInformationApi{
|
||||||
|
FirstName: event.Person.FirstName,
|
||||||
|
LastName: event.Person.LastName,
|
||||||
|
Patronymic: event.Person.Patronymic,
|
||||||
|
Contacts: []model.Contact{
|
||||||
|
{
|
||||||
|
Category: "PHONE",
|
||||||
|
Value: event.Person.Phone,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
person, err = services.CreatePerson(newPerson, c.Request().Header, c)
|
||||||
|
if err != nil || person.ID.ID() == 0 {
|
||||||
|
return c.JSON(http.StatusBadGateway, &utils.Error{
|
||||||
|
Type: "internal_error",
|
||||||
|
Message: "Can't send request to persons service",
|
||||||
|
Code: "0004",
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
usersMap, err := services.GetUsers([]uint{event.EmployeeId, uint(authorId)}, c.Request().Header)
|
usersMap, err := services.GetUsers([]uuid.UUID{event.MedicId, authorId}, c.Request().Header, c)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil || len(usersMap) == 0 {
|
||||||
return c.HTML(http.StatusBadGateway, err.Error())
|
return c.JSON(http.StatusBadGateway, &utils.Error{
|
||||||
|
Type: "internal_error",
|
||||||
|
Message: "Can't send request to users service",
|
||||||
|
Code: "0005",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
employee := usersMap[event.EmployeeId]
|
medic := usersMap[event.MedicId]
|
||||||
author := usersMap[uint(authorId)]
|
author := usersMap[authorId]
|
||||||
|
|
||||||
newEvent.Start = event.Start
|
newEvent, err := utils.TypeConverter[model.Event](event)
|
||||||
newEvent.End = event.End
|
|
||||||
newEvent.AuthorId = uint(authorId)
|
newEvent.OrgId = orgId
|
||||||
newEvent.EmployeeId = event.EmployeeId
|
newEvent.MedicId = event.MedicId
|
||||||
newEvent.MemberId = event.MemberId
|
newEvent.AuthorId = authorId
|
||||||
newEvent.MedicalCardId = event.MedicalCardId
|
newEvent.PersonId = person.ID
|
||||||
newEvent.Status = event.Status
|
newEvent.Person = *person
|
||||||
newEvent.Services = event.Services
|
|
||||||
newEvent.OrgId = uint(orgId)
|
|
||||||
|
|
||||||
tx := h.DB.Create(&newEvent)
|
tx := h.DB.Create(&newEvent)
|
||||||
|
|
||||||
if tx.RowsAffected == 0 {
|
if tx.RowsAffected == 0 {
|
||||||
return c.NoContent(http.StatusBadGateway)
|
return c.JSON(http.StatusBadGateway, &utils.Error{
|
||||||
|
Type: "internal_error",
|
||||||
|
Message: "Database error",
|
||||||
|
Code: "0006",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
newEvent.Author = author
|
newEvent.Author = author
|
||||||
newEvent.Employee = employee
|
newEvent.Medic = medic
|
||||||
|
|
||||||
return c.JSON(http.StatusCreated, newEvent)
|
return c.JSON(http.StatusCreated, newEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swagger:route GET /events/ Events GetEvents
|
||||||
|
//
|
||||||
|
// responses:
|
||||||
|
// 200: []Event
|
||||||
|
|
||||||
func (h *Handler) GetEvents(c echo.Context) (err error) {
|
func (h *Handler) GetEvents(c echo.Context) (err error) {
|
||||||
var events []model.Event
|
|
||||||
query := c.Request().URL.Query()
|
query := c.Request().URL.Query()
|
||||||
_, _, filterMap := utils.GetFilterParams(query)
|
orgId, err := uuid.Parse(c.Request().Header.Get("X-User-Organization-Id"))
|
||||||
orgId, err := strconv.Atoi(c.Request().Header.Get("UserOrganizationId"))
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.NoContent(http.StatusUnauthorized)
|
return c.JSON(http.StatusUnauthorized, &utils.Error{
|
||||||
|
Type: "internal_error",
|
||||||
|
Message: "User in not authorized",
|
||||||
|
Code: "0002",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
tx := h.DB.Where("org_id = ?", orgId)
|
tx := h.DB.Where("org_id = ?", orgId)
|
||||||
|
|
||||||
if len(filterMap) > 0 {
|
if query.Has("start") && query.Has("end") {
|
||||||
tx = tx.Where("start >= ?", filterMap["start"]).Where("\"end\" <= ?", filterMap["end"])
|
tx = tx.Where("start >= ?", query.Get("start")).Where("\"end\" <= ?", query.Get("end"))
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.Find(&events)
|
return h.queryEvents(tx, c)
|
||||||
|
|
||||||
ids := set.New[uint](len(events) * 2)
|
|
||||||
|
|
||||||
for _, event := range events {
|
|
||||||
ids.Insert(event.EmployeeId)
|
|
||||||
ids.Insert(event.AuthorId)
|
|
||||||
}
|
|
||||||
|
|
||||||
usersMap, err := services.GetUsers(ids.Slice(), c.Request().Header)
|
|
||||||
if err != nil {
|
|
||||||
return c.HTML(http.StatusBadGateway, err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, event := range events {
|
|
||||||
events[i].Author = usersMap[event.AuthorId]
|
|
||||||
events[i].Employee = usersMap[event.EmployeeId]
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, events)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swagger:route GET /events/today Events GetEventsToday
|
||||||
|
//
|
||||||
|
// responses:
|
||||||
|
// 200: []Event
|
||||||
|
|
||||||
|
func (h *Handler) GetEventsToday(c echo.Context) (err error) {
|
||||||
|
orgId, err := uuid.Parse(c.Request().Header.Get("X-User-Organization-Id"))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusUnauthorized, &utils.Error{
|
||||||
|
Type: "internal_error",
|
||||||
|
Message: "User in not authorized",
|
||||||
|
Code: "0002",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
tx := h.DB.Where("org_id = ?", orgId)
|
||||||
|
|
||||||
|
currentDate := time.Now().Format(time.DateOnly)
|
||||||
|
nextDate := time.Now().Add(24 * time.Hour).Format(time.DateOnly)
|
||||||
|
|
||||||
|
tx = tx.Where("start >= ?", currentDate).Where("\"end\" < ?", nextDate)
|
||||||
|
|
||||||
|
return h.queryEvents(tx, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:route GET /events/{uuid} Events GetEvent
|
||||||
|
//
|
||||||
|
// responses:
|
||||||
|
// 200: Event
|
||||||
|
|
||||||
func (h *Handler) GetEvent(c echo.Context) error {
|
func (h *Handler) GetEvent(c echo.Context) error {
|
||||||
var event model.Event
|
var event model.Event
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
orgId, err := strconv.Atoi(c.Request().Header.Get("UserOrganizationId"))
|
orgId, err := uuid.Parse(c.Request().Header.Get("X-User-Organization-Id"))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.NoContent(http.StatusUnauthorized)
|
return c.JSON(http.StatusUnauthorized, &utils.Error{
|
||||||
|
Type: "internal_error",
|
||||||
|
Message: "User in not authorized",
|
||||||
|
Code: "0002",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
tx := h.DB.Where("org_id = ?", orgId).First(&event, id)
|
tx := h.DB.Where("org_id = ?", orgId).First(&event, id)
|
||||||
|
|
||||||
if tx.RowsAffected == 0 {
|
if tx.RowsAffected == 0 {
|
||||||
return c.NoContent(http.StatusNotFound)
|
return c.JSON(http.StatusNotFound, &utils.Error{
|
||||||
|
Type: "not_found_error",
|
||||||
|
Message: "Event not found",
|
||||||
|
Code: "0007",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
usersMap, err := services.GetUsers([]uint{event.EmployeeId, event.AuthorId}, c.Request().Header)
|
usersMap, err := services.GetUsers([]uuid.UUID{event.MedicId, event.AuthorId}, c.Request().Header, c)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.HTML(http.StatusBadGateway, err.Error())
|
return c.JSON(http.StatusBadGateway, &utils.Error{
|
||||||
|
Type: "internal_error",
|
||||||
|
Message: "Can't send request to persons or users service",
|
||||||
|
Code: "0005",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
employee := usersMap[event.EmployeeId]
|
medic := usersMap[event.MedicId]
|
||||||
author := usersMap[event.AuthorId]
|
author := usersMap[event.AuthorId]
|
||||||
|
|
||||||
event.Employee = employee
|
event.Medic = medic
|
||||||
event.Author = author
|
event.Author = author
|
||||||
|
|
||||||
return c.JSON(http.StatusOK, event)
|
return c.JSON(http.StatusOK, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swagger:route DELETE /events/{uuid} Events DeleteEvent
|
||||||
|
//
|
||||||
|
// responses:
|
||||||
|
// 200
|
||||||
|
|
||||||
func (h *Handler) DeleteEvent(c echo.Context) error {
|
func (h *Handler) DeleteEvent(c echo.Context) error {
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
orgId, err := strconv.Atoi(c.Request().Header.Get("UserOrganizationId"))
|
orgId, err := uuid.Parse(c.Request().Header.Get("X-User-Organization-Id"))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.NoContent(http.StatusUnauthorized)
|
return c.JSON(http.StatusUnauthorized, &utils.Error{
|
||||||
|
Type: "internal_error",
|
||||||
|
Message: "User in not authorized",
|
||||||
|
Code: "0002",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
tx := h.DB.Where("org_id = ?", orgId).Delete(&model.Event{}, id)
|
tx := h.DB.Where("org_id = ?", orgId).Delete(&model.Event{}, id)
|
||||||
|
|
||||||
if tx.RowsAffected == 0 {
|
if tx.RowsAffected == 0 {
|
||||||
return c.NoContent(http.StatusNotFound)
|
return c.JSON(http.StatusNotFound, &utils.Error{
|
||||||
|
Type: "not_found_error",
|
||||||
|
Message: "Event not found",
|
||||||
|
Code: "0007",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.NoContent(http.StatusOK)
|
return c.NoContent(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) queryEvents(tx *gorm.DB, c echo.Context) error {
|
||||||
|
var events []model.Event
|
||||||
|
tx.Find(&events)
|
||||||
|
|
||||||
|
userIds := set.New[uuid.UUID](len(events) * 2)
|
||||||
|
personIds := set.New[uuid.UUID](len(events))
|
||||||
|
|
||||||
|
for _, event := range events {
|
||||||
|
userIds.Insert(event.MedicId)
|
||||||
|
userIds.Insert(event.AuthorId)
|
||||||
|
personIds.Insert(event.PersonId)
|
||||||
|
}
|
||||||
|
|
||||||
|
usersMap, err := services.GetUsers(userIds.Slice(), c.Request().Header, c)
|
||||||
|
personsMap, err := services.GetPersons(personIds.Slice(), c.Request().Header, c)
|
||||||
|
if err != nil {
|
||||||
|
return c.JSON(http.StatusBadGateway, &utils.Error{
|
||||||
|
Type: "internal_error",
|
||||||
|
Message: "Can't send request to persons or users service",
|
||||||
|
Code: "0005",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, event := range events {
|
||||||
|
events[i].Author = usersMap[event.AuthorId]
|
||||||
|
events[i].Medic = usersMap[event.MedicId]
|
||||||
|
events[i].Person = personsMap[event.PersonId]
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(http.StatusOK, events)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import (
|
||||||
|
"github.com/go-playground/validator/v10"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
DB *gorm.DB
|
DB *gorm.DB
|
||||||
|
Validator *validator.Validate
|
||||||
}
|
}
|
||||||
|
|||||||
19
main.go
19
main.go
@@ -4,13 +4,17 @@ import (
|
|||||||
"astra-events/config"
|
"astra-events/config"
|
||||||
"astra-events/handler"
|
"astra-events/handler"
|
||||||
"astra-events/model"
|
"astra-events/model"
|
||||||
|
"github.com/go-playground/validator/v10"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
|
log2 "github.com/labstack/gommon/log"
|
||||||
"gorm.io/driver/postgres"
|
"gorm.io/driver/postgres"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"gorm.io/gorm/logger"
|
"gorm.io/gorm/logger"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,14 +42,27 @@ func main() {
|
|||||||
|
|
||||||
db.AutoMigrate(&model.Event{})
|
db.AutoMigrate(&model.Event{})
|
||||||
|
|
||||||
var h = &handler.Handler{DB: db}
|
validate := validator.New()
|
||||||
|
validate.RegisterTagNameFunc(func(fld reflect.StructField) string {
|
||||||
|
name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]
|
||||||
|
if name == "-" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
})
|
||||||
|
|
||||||
|
var h = &handler.Handler{DB: db, Validator: validate}
|
||||||
|
|
||||||
e.POST("/", h.CreateEvent)
|
e.POST("/", h.CreateEvent)
|
||||||
e.GET("/:id", h.GetEvent)
|
e.GET("/:id", h.GetEvent)
|
||||||
e.GET("/", h.GetEvents)
|
e.GET("/", h.GetEvents)
|
||||||
|
e.GET("/today", h.GetEventsToday)
|
||||||
e.DELETE("/", h.DeleteEvent)
|
e.DELETE("/", h.DeleteEvent)
|
||||||
|
|
||||||
e.GET("/health", handler.Health)
|
e.GET("/health", handler.Health)
|
||||||
|
|
||||||
|
e.Debug = true
|
||||||
|
e.Logger.SetLevel(log2.DEBUG)
|
||||||
|
|
||||||
e.Logger.Fatal(e.Start(":" + config.Env.Server.Port))
|
e.Logger.Fatal(e.Start(":" + config.Env.Server.Port))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,47 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/lib/pq"
|
"github.com/google/uuid"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// swagger:model Event
|
||||||
type Event struct {
|
type Event struct {
|
||||||
gorm.Model
|
gorm.Model `json:"meta"`
|
||||||
Start time.Time `json:"start"`
|
ID uuid.UUID `json:"id" gorm:"type:uuid;default:gen_random_uuid();primarykey"`
|
||||||
End time.Time `json:"end"`
|
Start time.Time `json:"start"`
|
||||||
Author User `json:"author" gorm:"-"`
|
End time.Time `json:"end"`
|
||||||
AuthorId uint `json:"-"`
|
Author User `json:"author" gorm:"-"`
|
||||||
Employee User `json:"employee" gorm:"-"`
|
AuthorId uuid.UUID `json:"-"`
|
||||||
EmployeeId uint `json:"-"`
|
Medic User `json:"medic" gorm:"-"`
|
||||||
Member PD `json:"member" gorm:"-"`
|
MedicId uuid.UUID `json:"-"`
|
||||||
MemberId uint `json:"-"`
|
Person PersonalInformationApi `json:"person" gorm:"-"`
|
||||||
Status string `json:"status"`
|
PersonId uuid.UUID `json:"-"`
|
||||||
MedicalCard Card `json:"medicalCard" gorm:"-"`
|
OrgId uuid.UUID `json:"-"`
|
||||||
MedicalCardId uint `json:"-"`
|
|
||||||
Services pq.Int32Array `json:"services" gorm:"type:integer[]"`
|
|
||||||
OrgId uint `json:"-"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swagger:model CreateEvent
|
||||||
type CreateEvent struct {
|
type CreateEvent struct {
|
||||||
Start time.Time `json:"start"`
|
// The event start time
|
||||||
End time.Time `json:"end"`
|
// example: 2023-08-02T19:21:23.617Z
|
||||||
EmployeeId uint `json:"employee_id"`
|
// required: true
|
||||||
MemberId uint `json:"member_id"`
|
Start time.Time `json:"start" validate:"required,gt"`
|
||||||
Status string `json:"status"`
|
// The event end time
|
||||||
MedicalCardId uint `json:"medical_card_id"`
|
// example: 2023-08-02T19:21:23.617Z
|
||||||
Services []int32 `json:"services"`
|
// required: true
|
||||||
|
End time.Time `json:"end" validate:"required,gtfield=Start"`
|
||||||
|
// The person information
|
||||||
|
// required: true
|
||||||
|
Person *PersonalInformation `json:"person" validate:"required,dive"`
|
||||||
|
// The UUID of a medic
|
||||||
|
// example: 6204037c-30e6-408b-8aaa-dd8219860b4b
|
||||||
|
// required: true
|
||||||
|
MedicId uuid.UUID `json:"medic_id" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:parameters CreateEvent
|
||||||
|
type CreateEventArg struct {
|
||||||
|
//in: body
|
||||||
|
CreateEvent *CreateEvent
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
|
||||||
|
|
||||||
type PD struct {
|
|
||||||
gorm.Model
|
|
||||||
}
|
|
||||||
36
model/personal-information.go
Normal file
36
model/personal-information.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "github.com/google/uuid"
|
||||||
|
|
||||||
|
// swagger:model PersonalInformation
|
||||||
|
type PersonalInformation struct {
|
||||||
|
// The UUID of a person
|
||||||
|
// example: 6204037c-30e6-408b-8aaa-dd8219860b4b
|
||||||
|
ID uuid.UUID `json:"id,omitempty" validate:"required_without_all=FirstName LastName Patronymic Phone"`
|
||||||
|
// The first name of a person
|
||||||
|
// example: Иван
|
||||||
|
FirstName string `json:"first_name,omitempty" validate:"required_without=ID"`
|
||||||
|
// The last name of a person
|
||||||
|
// example: Иванов
|
||||||
|
LastName string `json:"last_name,omitempty" validate:"required_without=ID"`
|
||||||
|
// The patronymic of a person
|
||||||
|
// example: Иванович
|
||||||
|
Patronymic string `json:"patronymic,omitempty" validate:"required_without=ID"`
|
||||||
|
// The first name of a person
|
||||||
|
// example: 79206321370
|
||||||
|
Phone string `json:"phone,omitempty" validate:"required_without=ID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PersonalInformationApi struct {
|
||||||
|
ID uuid.UUID `json:"id,omitempty"`
|
||||||
|
FirstName string `json:"first_name,omitempty"`
|
||||||
|
LastName string `json:"last_name,omitempty"`
|
||||||
|
Patronymic string `json:"patronymic,omitempty"`
|
||||||
|
BirthDate string `json:"birth_date,omitempty"`
|
||||||
|
Contacts []Contact `json:"contacts"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Contact struct {
|
||||||
|
Category string `json:"category"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
}
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "gorm.io/gorm"
|
import (
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
User struct {
|
User struct {
|
||||||
|
ID uuid.UUID
|
||||||
gorm.Model
|
gorm.Model
|
||||||
UserName string `json:"user_name" gorm:"unique"`
|
UserName string `json:"user_name" gorm:"unique"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
|
|||||||
@@ -3,15 +3,16 @@ package api
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PostRequest(url string, model any, header http.Header) ([]byte, error) {
|
func PostRequest(url string, model any, header http.Header, c echo.Context) ([]byte, error, *http.Response) {
|
||||||
uJson, err := json.Marshal(model)
|
uJson, err := json.Marshal(model)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
@@ -19,22 +20,28 @@ func PostRequest(url string, model any, header http.Header) ([]byte, error) {
|
|||||||
req.Header = header
|
req.Header = header
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
c.Logger().Debug("Request---")
|
||||||
|
c.Logger().Debug(string(uJson))
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := io.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return data, nil
|
c.Logger().Debug("Response---")
|
||||||
|
c.Logger().Debug(string(data))
|
||||||
|
|
||||||
|
return data, nil, resp
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRequest(url string, header http.Header, args ...string) ([]byte, error, *http.Response) {
|
func GetRequest(url string, header http.Header, c echo.Context, args ...string) ([]byte, error, *http.Response) {
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
@@ -42,6 +49,10 @@ func GetRequest(url string, header http.Header, args ...string) ([]byte, error,
|
|||||||
}
|
}
|
||||||
req.Header = header
|
req.Header = header
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
c.Logger().Debug("Request---")
|
||||||
|
c.Logger().Debug(req.URL.String())
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -54,6 +65,9 @@ func GetRequest(url string, header http.Header, args ...string) ([]byte, error,
|
|||||||
return nil, err, nil
|
return nil, err, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.Logger().Debug("Response---")
|
||||||
|
c.Logger().Debug(string(data))
|
||||||
|
|
||||||
return data, nil, resp
|
return data, nil, resp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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
|
||||||
|
}
|
||||||
14
pkg/utils/validation.go
Normal file
14
pkg/utils/validation.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
type Error struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ValidationError struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
Fields map[string]string `json:"fields"`
|
||||||
|
}
|
||||||
82
services/personal-information.go
Normal file
82
services/personal-information.go
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"astra-events/config"
|
||||||
|
"astra-events/model"
|
||||||
|
"astra-events/pkg/api"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetPerson(id uuid.UUID, header http.Header, c echo.Context) (*model.PersonalInformationApi, error) {
|
||||||
|
data, err, _ := api.GetRequest(
|
||||||
|
config.Env.MSHosts.PersonsHost+"/persons/"+id.String(),
|
||||||
|
header, c)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("error Request to Personal Information Service")
|
||||||
|
}
|
||||||
|
|
||||||
|
pi := new(model.PersonalInformationApi)
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &pi)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("bad Response from Personal Information Service")
|
||||||
|
}
|
||||||
|
|
||||||
|
return pi, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreatePerson(person model.PersonalInformationApi, header http.Header, c echo.Context) (*model.PersonalInformationApi, error) {
|
||||||
|
data, err, _ := api.PostRequest(
|
||||||
|
config.Env.MSHosts.PersonsHost+"/persons/",
|
||||||
|
person,
|
||||||
|
header,
|
||||||
|
c,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("error Request to Personal Information Service")
|
||||||
|
}
|
||||||
|
|
||||||
|
pi := new(model.PersonalInformationApi)
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &pi)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("bad Response from Personal Information Service")
|
||||||
|
}
|
||||||
|
|
||||||
|
return pi, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPersons(ids []uuid.UUID, header http.Header, c echo.Context) (map[uuid.UUID]model.PersonalInformationApi, error) {
|
||||||
|
var persons []model.PersonalInformationApi
|
||||||
|
personsMap := make(map[uuid.UUID]model.PersonalInformationApi)
|
||||||
|
|
||||||
|
data, err, req := api.PostRequest(
|
||||||
|
config.Env.MSHosts.PersonsHost+"/persons/batch/",
|
||||||
|
&map[string][]uuid.UUID{
|
||||||
|
"ids": ids,
|
||||||
|
},
|
||||||
|
header, c)
|
||||||
|
|
||||||
|
if err != nil || req.StatusCode != 200 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &persons)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, person := range persons {
|
||||||
|
personsMap[person.ID] = person
|
||||||
|
}
|
||||||
|
|
||||||
|
return personsMap, nil
|
||||||
|
}
|
||||||
@@ -6,17 +6,19 @@ import (
|
|||||||
"astra-events/pkg/api"
|
"astra-events/pkg/api"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetUser(ID uint, header http.Header) (*model.User, error) {
|
func GetUser(ID uint, header http.Header, c echo.Context) (*model.User, error) {
|
||||||
id := strconv.Itoa(int(ID))
|
id := strconv.Itoa(int(ID))
|
||||||
|
|
||||||
data, err, _ := api.GetRequest(
|
data, err, _ := api.GetRequest(
|
||||||
config.Env.MSHosts.UsersHost+"/"+id,
|
config.Env.MSHosts.UsersHost+"/"+id,
|
||||||
header)
|
header, c)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("error Request to Users Service")
|
return nil, errors.New("error Request to Users Service")
|
||||||
@@ -33,9 +35,9 @@ func GetUser(ID uint, header http.Header) (*model.User, error) {
|
|||||||
return u, nil
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUsers(ids []uint, header http.Header) (map[uint]model.User, error) {
|
func GetUsers(ids []uuid.UUID, header http.Header, c echo.Context) (map[uuid.UUID]model.User, error) {
|
||||||
var users []model.User
|
var users []model.User
|
||||||
var usersMap = make(map[uint]model.User)
|
var usersMap = make(map[uuid.UUID]model.User)
|
||||||
Url, err := url.Parse(config.Env.MSHosts.UsersHost)
|
Url, err := url.Parse(config.Env.MSHosts.UsersHost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -47,7 +49,7 @@ func GetUsers(ids []uint, header http.Header) (map[uint]model.User, error) {
|
|||||||
|
|
||||||
data, err, req := api.GetRequest(
|
data, err, req := api.GetRequest(
|
||||||
Url.String(),
|
Url.String(),
|
||||||
header)
|
header, c)
|
||||||
|
|
||||||
if err != nil || req.StatusCode != 200 {
|
if err != nil || req.StatusCode != 200 {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
335
swagger/swagger.json
Normal file
335
swagger/swagger.json
Normal file
@@ -0,0 +1,335 @@
|
|||||||
|
{
|
||||||
|
"swagger": "2.0",
|
||||||
|
"paths": {
|
||||||
|
"/events/": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"Events"
|
||||||
|
],
|
||||||
|
"operationId": "GetEvents",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Event",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Event"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"tags": [
|
||||||
|
"Events"
|
||||||
|
],
|
||||||
|
"operationId": "CreateEvent",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "CreateEvent",
|
||||||
|
"in": "body",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/CreateEvent"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Event",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/Event"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/events/today": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"Events"
|
||||||
|
],
|
||||||
|
"operationId": "GetEvents",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Event",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Event"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/events/{uuid}": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"Events"
|
||||||
|
],
|
||||||
|
"operationId": "GetEvent",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Event",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/Event"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"tags": [
|
||||||
|
"Events"
|
||||||
|
],
|
||||||
|
"operationId": "DeleteEvent",
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"Contact": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"category": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "Category"
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "Value"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-go-package": "astra-events/model"
|
||||||
|
},
|
||||||
|
"CreateEvent": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"start",
|
||||||
|
"end",
|
||||||
|
"person",
|
||||||
|
"medic_id"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"end": {
|
||||||
|
"description": "The event end time",
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time",
|
||||||
|
"x-go-name": "End",
|
||||||
|
"example": "2023-08-02T19:21:23.617Z"
|
||||||
|
},
|
||||||
|
"medic_id": {
|
||||||
|
"description": "The UUID of a medic",
|
||||||
|
"type": "string",
|
||||||
|
"format": "uuid",
|
||||||
|
"x-go-name": "MedicId",
|
||||||
|
"example": "6204037c-30e6-408b-8aaa-dd8219860b4b"
|
||||||
|
},
|
||||||
|
"person": {
|
||||||
|
"$ref": "#/definitions/PersonalInformation"
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"description": "The event start time",
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time",
|
||||||
|
"x-go-name": "Start",
|
||||||
|
"example": "2023-08-02T19:21:23.617Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-go-package": "astra-events/model"
|
||||||
|
},
|
||||||
|
"DeletedAt": {
|
||||||
|
"$ref": "#/definitions/NullTime"
|
||||||
|
},
|
||||||
|
"Event": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"CreatedAt": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"DeletedAt": {
|
||||||
|
"$ref": "#/definitions/DeletedAt"
|
||||||
|
},
|
||||||
|
"ID": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "uint64"
|
||||||
|
},
|
||||||
|
"UpdatedAt": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"author": {
|
||||||
|
"$ref": "#/definitions/User"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time",
|
||||||
|
"x-go-name": "End"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uuid",
|
||||||
|
"x-go-name": "ID"
|
||||||
|
},
|
||||||
|
"medic": {
|
||||||
|
"$ref": "#/definitions/User"
|
||||||
|
},
|
||||||
|
"person": {
|
||||||
|
"$ref": "#/definitions/PersonalInformationApi"
|
||||||
|
},
|
||||||
|
"start": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time",
|
||||||
|
"x-go-name": "Start"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-go-package": "astra-events/model"
|
||||||
|
},
|
||||||
|
"Model": {
|
||||||
|
"description": "type User struct {\ngorm.Model\n}",
|
||||||
|
"type": "object",
|
||||||
|
"title": "Model a basic GoLang struct which includes the following fields: ID, CreatedAt, UpdatedAt, DeletedAt\nIt may be embedded into your model or you may build your own model without it",
|
||||||
|
"properties": {
|
||||||
|
"CreatedAt": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"DeletedAt": {
|
||||||
|
"$ref": "#/definitions/DeletedAt"
|
||||||
|
},
|
||||||
|
"ID": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "uint64"
|
||||||
|
},
|
||||||
|
"UpdatedAt": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-go-package": "gorm.io/gorm"
|
||||||
|
},
|
||||||
|
"NullTime": {
|
||||||
|
"description": "NullTime implements the Scanner interface so\nit can be used as a scan destination, similar to NullString.",
|
||||||
|
"type": "object",
|
||||||
|
"title": "NullTime represents a time.Time that may be null.",
|
||||||
|
"properties": {
|
||||||
|
"Time": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"Valid": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-go-package": "database/sql"
|
||||||
|
},
|
||||||
|
"PersonalInformation": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"first_name": {
|
||||||
|
"description": "The first name of a person",
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "FirstName",
|
||||||
|
"example": "Иван"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"description": "The UUID of a person",
|
||||||
|
"type": "string",
|
||||||
|
"format": "uuid",
|
||||||
|
"x-go-name": "ID",
|
||||||
|
"example": "6204037c-30e6-408b-8aaa-dd8219860b4b"
|
||||||
|
},
|
||||||
|
"last_name": {
|
||||||
|
"description": "The last name of a person",
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "LastName",
|
||||||
|
"example": "Иванов"
|
||||||
|
},
|
||||||
|
"patronymic": {
|
||||||
|
"description": "The patronymic of a person",
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "Patronymic",
|
||||||
|
"example": "Иванович"
|
||||||
|
},
|
||||||
|
"phone": {
|
||||||
|
"description": "The first name of a person",
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "Phone",
|
||||||
|
"example": "79206321370"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-go-package": "astra-events/model"
|
||||||
|
},
|
||||||
|
"PersonalInformationApi": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"birth_date": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "BirthDate"
|
||||||
|
},
|
||||||
|
"contacts": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Contact"
|
||||||
|
},
|
||||||
|
"x-go-name": "Contacts"
|
||||||
|
},
|
||||||
|
"first_name": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "FirstName"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uuid",
|
||||||
|
"x-go-name": "ID"
|
||||||
|
},
|
||||||
|
"last_name": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "LastName"
|
||||||
|
},
|
||||||
|
"patronymic": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "Patronymic"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-go-package": "astra-events/model"
|
||||||
|
},
|
||||||
|
"User": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"CreatedAt": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"DeletedAt": {
|
||||||
|
"$ref": "#/definitions/DeletedAt"
|
||||||
|
},
|
||||||
|
"ID": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uuid"
|
||||||
|
},
|
||||||
|
"UpdatedAt": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"first_name": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "FirstName"
|
||||||
|
},
|
||||||
|
"last_name": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "LastName"
|
||||||
|
},
|
||||||
|
"password": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "Password"
|
||||||
|
},
|
||||||
|
"user_name": {
|
||||||
|
"type": "string",
|
||||||
|
"x-go-name": "UserName"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"x-go-package": "astra-events/model"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user