From a67316a88904a2e5987502a1339aa5251a03847a Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Mon, 3 Oct 2022 20:09:26 -0800 Subject: [PATCH] fix types --- backend/app/api/docs/docs.go | 14 +++++++------- backend/app/api/docs/swagger.json | 14 +++++++------- backend/app/api/docs/swagger.yaml | 20 ++++++++++---------- backend/app/api/v1/v1_ctrl_group.go | 14 +++++++------- frontend/lib/api/types/data-contracts.ts | 12 ++++++------ frontend/lib/api/types/non-generated.ts | 4 ++++ scripts/process-types.py | 1 + 7 files changed, 42 insertions(+), 37 deletions(-) diff --git a/backend/app/api/docs/docs.go b/backend/app/api/docs/docs.go index 7cd9965..156d845 100644 --- a/backend/app/api/docs/docs.go +++ b/backend/app/api/docs/docs.go @@ -42,7 +42,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/v1.GroupTokenPayload" + "$ref": "#/definitions/v1.GroupInvitationCreate" } } ], @@ -50,7 +50,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/v1.GroupTokenResponse" + "$ref": "#/definitions/v1.GroupInvitation" } } } @@ -1582,26 +1582,26 @@ const docTemplate = `{ } } }, - "v1.GroupTokenPayload": { + "v1.GroupInvitation": { "type": "object", "properties": { "expiresAt": { "type": "string" }, + "token": { + "type": "string" + }, "uses": { "type": "integer" } } }, - "v1.GroupTokenResponse": { + "v1.GroupInvitationCreate": { "type": "object", "properties": { "expiresAt": { "type": "string" }, - "token": { - "type": "string" - }, "uses": { "type": "integer" } diff --git a/backend/app/api/docs/swagger.json b/backend/app/api/docs/swagger.json index a6287ea..cec1d74 100644 --- a/backend/app/api/docs/swagger.json +++ b/backend/app/api/docs/swagger.json @@ -34,7 +34,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/v1.GroupTokenPayload" + "$ref": "#/definitions/v1.GroupInvitationCreate" } } ], @@ -42,7 +42,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/v1.GroupTokenResponse" + "$ref": "#/definitions/v1.GroupInvitation" } } } @@ -1574,26 +1574,26 @@ } } }, - "v1.GroupTokenPayload": { + "v1.GroupInvitation": { "type": "object", "properties": { "expiresAt": { "type": "string" }, + "token": { + "type": "string" + }, "uses": { "type": "integer" } } }, - "v1.GroupTokenResponse": { + "v1.GroupInvitationCreate": { "type": "object", "properties": { "expiresAt": { "type": "string" }, - "token": { - "type": "string" - }, "uses": { "type": "integer" } diff --git a/backend/app/api/docs/swagger.yaml b/backend/app/api/docs/swagger.yaml index a624a43..ea65a28 100644 --- a/backend/app/api/docs/swagger.yaml +++ b/backend/app/api/docs/swagger.yaml @@ -355,14 +355,7 @@ definitions: version: type: string type: object - v1.GroupTokenPayload: - properties: - expiresAt: - type: string - uses: - type: integer - type: object - v1.GroupTokenResponse: + v1.GroupInvitation: properties: expiresAt: type: string @@ -371,6 +364,13 @@ definitions: uses: type: integer type: object + v1.GroupInvitationCreate: + properties: + expiresAt: + type: string + uses: + type: integer + type: object v1.ItemAttachmentToken: properties: token: @@ -402,14 +402,14 @@ paths: name: payload required: true schema: - $ref: '#/definitions/v1.GroupTokenPayload' + $ref: '#/definitions/v1.GroupInvitationCreate' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/v1.GroupTokenResponse' + $ref: '#/definitions/v1.GroupInvitation' security: - Bearer: [] summary: Get the current user diff --git a/backend/app/api/v1/v1_ctrl_group.go b/backend/app/api/v1/v1_ctrl_group.go index 8e1cb6f..faa52a5 100644 --- a/backend/app/api/v1/v1_ctrl_group.go +++ b/backend/app/api/v1/v1_ctrl_group.go @@ -10,12 +10,12 @@ import ( ) type ( - GroupTokenPayload struct { + GroupInvitationCreate struct { Uses int `json:"uses"` ExpiresAt time.Time `json:"expiresAt"` } - GroupTokenResponse struct { + GroupInvitation struct { Token string `json:"token"` ExpiresAt time.Time `json:"expiresAt"` Uses int `json:"uses"` @@ -26,13 +26,13 @@ type ( // @Summary Get the current user // @Tags User // @Produce json -// @Param payload body GroupTokenPayload true "User Data" -// @Success 200 {object} GroupTokenResponse +// @Param payload body GroupInvitationCreate true "User Data" +// @Success 200 {object} GroupInvitation // @Router /v1/groups/invitations [Post] // @Security Bearer func (ctrl *V1Controller) HandleGroupInvitationsCreate() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - data := GroupTokenPayload{} + data := GroupInvitationCreate{} if err := server.Decode(r, &data); err != nil { log.Err(err).Msg("failed to decode user registration data") @@ -53,10 +53,10 @@ func (ctrl *V1Controller) HandleGroupInvitationsCreate() http.HandlerFunc { return } - server.Respond(w, http.StatusCreated, server.Wrap(GroupTokenResponse{ + server.Respond(w, http.StatusCreated, GroupInvitation{ Token: token, ExpiresAt: data.ExpiresAt, Uses: data.Uses, - })) + }) } } diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.ts index c2b09b9..daa08a0 100644 --- a/frontend/lib/api/types/data-contracts.ts +++ b/frontend/lib/api/types/data-contracts.ts @@ -239,14 +239,14 @@ export interface Build { version: string; } -export interface GroupTokenPayload { - expiresAt: string; +export interface GroupInvitation { + expiresAt: Date; + token: string; uses: number; } -export interface GroupTokenResponse { - expiresAt: string; - token: string; +export interface GroupInvitationCreate { + expiresAt: Date; uses: number; } @@ -255,6 +255,6 @@ export interface ItemAttachmentToken { } export interface TokenResponse { - expiresAt: string; + expiresAt: Date; token: string; } diff --git a/frontend/lib/api/types/non-generated.ts b/frontend/lib/api/types/non-generated.ts index 6928784..67b2a6d 100644 --- a/frontend/lib/api/types/non-generated.ts +++ b/frontend/lib/api/types/non-generated.ts @@ -4,3 +4,7 @@ export enum AttachmentTypes { Warranty = "warranty", Attachment = "attachment", } + +export type Result = { + item: T; +}; diff --git a/scripts/process-types.py b/scripts/process-types.py index 2b4cf5b..c2fcb88 100644 --- a/scripts/process-types.py +++ b/scripts/process-types.py @@ -32,6 +32,7 @@ regex_replace: dict[re.Pattern, str] = { "soldTime", "purchaseTime", "warrantyExpires", + "expiresAt", ), }