add swagger
This commit is contained in:
@@ -11,6 +11,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 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) {
|
||||||
var person *model.PersonalInformation
|
var person *model.PersonalInformation
|
||||||
event := new(model.CreateEvent)
|
event := new(model.CreateEvent)
|
||||||
@@ -80,6 +85,11 @@ func (h *Handler) CreateEvent(c echo.Context) (err error) {
|
|||||||
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
|
var events []model.Event
|
||||||
query := c.Request().URL.Query()
|
query := c.Request().URL.Query()
|
||||||
@@ -118,6 +128,11 @@ func (h *Handler) GetEvents(c echo.Context) (err error) {
|
|||||||
return c.JSON(http.StatusOK, events)
|
return c.JSON(http.StatusOK, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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")
|
||||||
@@ -148,6 +163,11 @@ func (h *Handler) GetEvent(c echo.Context) error {
|
|||||||
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 := uuid.Parse(c.Request().Header.Get("UserOrganizationId"))
|
orgId, err := uuid.Parse(c.Request().Header.Get("UserOrganizationId"))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// swagger:model Event
|
||||||
type Event struct {
|
type Event struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();primarykey"`
|
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();primarykey"`
|
||||||
@@ -20,9 +21,27 @@ type Event struct {
|
|||||||
OrgId uuid.UUID `json:"-"`
|
OrgId uuid.UUID `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swagger:model CreateEvent
|
||||||
type CreateEvent struct {
|
type CreateEvent struct {
|
||||||
|
// The event start time
|
||||||
|
// example: 2023-08-02T19:21:23.617Z
|
||||||
|
// required: true
|
||||||
Start time.Time `json:"start" validate:"required,gt"`
|
Start time.Time `json:"start" validate:"required,gt"`
|
||||||
|
// The event end time
|
||||||
|
// example: 2023-08-02T19:21:23.617Z
|
||||||
|
// required: true
|
||||||
End time.Time `json:"end" validate:"required,gtfield=Start"`
|
End time.Time `json:"end" validate:"required,gtfield=Start"`
|
||||||
|
// The person information
|
||||||
|
// required: true
|
||||||
Person *PersonalInformation `json:"person" validate:"required,dive"`
|
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"`
|
MedicId uuid.UUID `json:"medic_id" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swagger:parameters CreateEvent
|
||||||
|
type CreateEventArg struct {
|
||||||
|
//in: body
|
||||||
|
CreateEvent *CreateEvent
|
||||||
|
}
|
||||||
|
|||||||
11
model/pd.go
11
model/pd.go
@@ -2,11 +2,22 @@ package model
|
|||||||
|
|
||||||
import "github.com/google/uuid"
|
import "github.com/google/uuid"
|
||||||
|
|
||||||
|
// swagger:model PersonalInformation
|
||||||
type PersonalInformation struct {
|
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"`
|
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"`
|
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"`
|
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"`
|
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"`
|
Phone string `json:"phone,omitempty" validate:"required_without=ID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
260
swagger/swagger.json
Normal file
260
swagger/swagger.json
Normal file
@@ -0,0 +1,260 @@
|
|||||||
|
{
|
||||||
|
"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/{uuid}": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"Events"
|
||||||
|
],
|
||||||
|
"operationId": "GetEvent",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Event",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/Event"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"tags": [
|
||||||
|
"Events"
|
||||||
|
],
|
||||||
|
"operationId": "DeleteEvent",
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"CreateEvent": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"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": "string",
|
||||||
|
"format": "uuid"
|
||||||
|
},
|
||||||
|
"UpdatedAt": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"author": {
|
||||||
|
"$ref": "#/definitions/User"
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time",
|
||||||
|
"x-go-name": "End"
|
||||||
|
},
|
||||||
|
"medic": {
|
||||||
|
"$ref": "#/definitions/User"
|
||||||
|
},
|
||||||
|
"person": {
|
||||||
|
"$ref": "#/definitions/PersonalInformation"
|
||||||
|
},
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"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