diff --git a/docs/docs.go b/docs/docs.go index a9b40c8..c195403 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -19,13 +19,51 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { - "/api/images": { + "/api/alias-update": { "get": { + "description": "get update notification using websocket", + "summary": "Get notification when alias update", + "responses": {} + } + }, + "/api/alias/{id}": { + "delete": { + "description": "delete alias along with the links", + "summary": "Delete alias", + "parameters": [ + { + "type": "integer", + "description": "Alias Id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "Not Found" + } + } + } + }, + "/api/aliases": { + "get": { + "description": "get alias ids and names", + "summary": "Get aliases", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/api.getImagesOutputImage" + "type": "array", + "items": { + "$ref": "#/definitions/api.getAliasesOutputAlias" + } } }, "400": { @@ -36,9 +74,177 @@ const docTemplate = `{ } } } + }, + "/api/image": { + "post": { + "consumes": [ + "image/png", + "image/jpeg", + "image/gif" + ], + "parameters": [ + { + "type": "string", + "description": "userinfo from /auth/gen-login-url", + "name": "userinfo", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized" + } + } + } + }, + "/api/image/{id}": { + "delete": { + "description": "delete image along with the links", + "summary": "Delete image", + "parameters": [ + { + "type": "integer", + "description": "Image Id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "Not Found" + } + } + } + }, + "/api/image/{id}/aliases": { + "put": { + "parameters": [ + { + "type": "integer", + "description": "Image Id", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "Not Found" + } + } + } + }, + "/api/images": { + "get": { + "parameters": [ + { + "type": "array", + "items": { + "type": "integer" + }, + "collectionFormat": "csv", + "description": "Image Ids", + "name": "images", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "integer" + }, + "collectionFormat": "csv", + "description": "Alias Ids", + "name": "aliases", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/api.getImagesOutputImage" + } + } + }, + "400": { + "description": "Bad Request" + }, + "401": { + "description": "Unauthorized" + } + } + } + }, + "/auth/gen-login-url": { + "post": { + "parameters": [ + { + "description": "Payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/auth.postGenLoginUrlInput" + } + } + ], + "responses": { + "200": { + "description": "Payload", + "schema": { + "$ref": "#/definitions/auth.postGenLoginUrlOutput" + } + }, + "400": { + "description": "Bad Request" + } + } + } } }, "definitions": { + "api.getAliasesOutputAlias": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "api.getImagesOutputImage": { "type": "object", "properties": { @@ -51,10 +257,26 @@ const docTemplate = `{ "id": { "type": "integer" }, - "uploaded_at": { + "uploadedAt": { "type": "integer" }, - "uploaded_user_id": { + "uploadedUserId": { + "type": "string" + } + } + }, + "auth.postGenLoginUrlInput": { + "type": "object", + "properties": { + "userId": { + "type": "string" + } + } + }, + "auth.postGenLoginUrlOutput": { + "type": "object", + "properties": { + "loginUrl": { "type": "string" } } diff --git a/docs/swagger.json b/docs/swagger.json index 99f04b3..508b9bb 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -11,13 +11,51 @@ }, "basePath": "/", "paths": { - "/api/images": { + "/api/alias-update": { "get": { + "description": "get update notification using websocket", + "summary": "Get notification when alias update", + "responses": {} + } + }, + "/api/alias/{id}": { + "delete": { + "description": "delete alias along with the links", + "summary": "Delete alias", + "parameters": [ + { + "type": "integer", + "description": "Alias Id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "Not Found" + } + } + } + }, + "/api/aliases": { + "get": { + "description": "get alias ids and names", + "summary": "Get aliases", "responses": { "200": { "description": "OK", "schema": { - "$ref": "#/definitions/api.getImagesOutputImage" + "type": "array", + "items": { + "$ref": "#/definitions/api.getAliasesOutputAlias" + } } }, "400": { @@ -28,9 +66,177 @@ } } } + }, + "/api/image": { + "post": { + "consumes": [ + "image/png", + "image/jpeg", + "image/gif" + ], + "parameters": [ + { + "type": "string", + "description": "userinfo from /auth/gen-login-url", + "name": "userinfo", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized" + } + } + } + }, + "/api/image/{id}": { + "delete": { + "description": "delete image along with the links", + "summary": "Delete image", + "parameters": [ + { + "type": "integer", + "description": "Image Id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "Not Found" + } + } + } + }, + "/api/image/{id}/aliases": { + "put": { + "parameters": [ + { + "type": "integer", + "description": "Image Id", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "Payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + } + ], + "responses": { + "200": { + "description": "OK" + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "Not Found" + } + } + } + }, + "/api/images": { + "get": { + "parameters": [ + { + "type": "array", + "items": { + "type": "integer" + }, + "collectionFormat": "csv", + "description": "Image Ids", + "name": "images", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "integer" + }, + "collectionFormat": "csv", + "description": "Alias Ids", + "name": "aliases", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/api.getImagesOutputImage" + } + } + }, + "400": { + "description": "Bad Request" + }, + "401": { + "description": "Unauthorized" + } + } + } + }, + "/auth/gen-login-url": { + "post": { + "parameters": [ + { + "description": "Payload", + "name": "payload", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/auth.postGenLoginUrlInput" + } + } + ], + "responses": { + "200": { + "description": "Payload", + "schema": { + "$ref": "#/definitions/auth.postGenLoginUrlOutput" + } + }, + "400": { + "description": "Bad Request" + } + } + } } }, "definitions": { + "api.getAliasesOutputAlias": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, "api.getImagesOutputImage": { "type": "object", "properties": { @@ -43,10 +249,26 @@ "id": { "type": "integer" }, - "uploaded_at": { + "uploadedAt": { "type": "integer" }, - "uploaded_user_id": { + "uploadedUserId": { + "type": "string" + } + } + }, + "auth.postGenLoginUrlInput": { + "type": "object", + "properties": { + "userId": { + "type": "string" + } + } + }, + "auth.postGenLoginUrlOutput": { + "type": "object", + "properties": { + "loginUrl": { "type": "string" } } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index ea7c45b..bc53e30 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,5 +1,12 @@ basePath: / definitions: + api.getAliasesOutputAlias: + properties: + id: + type: integer + name: + type: string + type: object api.getImagesOutputImage: properties: aliases: @@ -8,9 +15,19 @@ definitions: type: array id: type: integer - uploaded_at: + uploadedAt: type: integer - uploaded_user_id: + uploadedUserId: + type: string + type: object + auth.postGenLoginUrlInput: + properties: + userId: + type: string + type: object + auth.postGenLoginUrlOutput: + properties: + loginUrl: type: string type: object info: @@ -21,15 +38,142 @@ info: title: Golang 2025 Final Project version: 0.0.1 paths: - /api/images: + /api/alias-update: get: + description: get update notification using websocket + responses: {} + summary: Get notification when alias update + /api/alias/{id}: + delete: + description: delete alias along with the links + parameters: + - description: Alias Id + in: path + name: id + required: true + type: integer + responses: + "200": + description: OK + "401": + description: Unauthorized + "404": + description: Not Found + summary: Delete alias + /api/aliases: + get: + description: get alias ids and names responses: "200": description: OK schema: - $ref: '#/definitions/api.getImagesOutputImage' + items: + $ref: '#/definitions/api.getAliasesOutputAlias' + type: array "400": description: Bad Request "401": description: Unauthorized + summary: Get aliases + /api/image: + post: + consumes: + - image/png + - image/jpeg + - image/gif + parameters: + - description: userinfo from /auth/gen-login-url + in: header + name: userinfo + required: true + type: string + responses: + "200": + description: OK + "401": + description: Unauthorized + /api/image/{id}: + delete: + description: delete image along with the links + parameters: + - description: Image Id + in: path + name: id + required: true + type: integer + responses: + "200": + description: OK + "401": + description: Unauthorized + "404": + description: Not Found + summary: Delete image + /api/image/{id}/aliases: + put: + parameters: + - description: Image Id + in: path + name: id + required: true + type: integer + - description: Payload + in: body + name: payload + required: true + schema: + items: + type: string + type: array + responses: + "200": + description: OK + "401": + description: Unauthorized + "404": + description: Not Found + /api/images: + get: + parameters: + - collectionFormat: csv + description: Image Ids + in: query + items: + type: integer + name: images + type: array + - collectionFormat: csv + description: Alias Ids + in: query + items: + type: integer + name: aliases + type: array + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/api.getImagesOutputImage' + type: array + "400": + description: Bad Request + "401": + description: Unauthorized + /auth/gen-login-url: + post: + parameters: + - description: Payload + in: body + name: payload + required: true + schema: + $ref: '#/definitions/auth.postGenLoginUrlInput' + responses: + "200": + description: Payload + schema: + $ref: '#/definitions/auth.postGenLoginUrlOutput' + "400": + description: Bad Request swagger: "2.0" diff --git a/handlers/api/deleteAlias.go b/handlers/api/deleteAlias.go new file mode 100644 index 0000000..9c5a7e5 --- /dev/null +++ b/handlers/api/deleteAlias.go @@ -0,0 +1,23 @@ +package api + +import ( + "net/http" + + "gitea.konchin.com/go2025/backend/utils" + "github.com/uptrace/bunrouter" +) + +// DeleteAlias +// +// @summary Delete alias +// @description delete alias along with the links +// @param id path int64 true "Alias Id" +// @success 200 +// @failure 401 +// @failure 404 +// @router /api/alias/{id} [delete] +func (self *Handlers) DeleteAlias( + w http.ResponseWriter, req bunrouter.Request, +) error { + return utils.Success(w) +} diff --git a/handlers/api/deleteImage.go b/handlers/api/deleteImage.go new file mode 100644 index 0000000..382bae2 --- /dev/null +++ b/handlers/api/deleteImage.go @@ -0,0 +1,23 @@ +package api + +import ( + "net/http" + + "gitea.konchin.com/go2025/backend/utils" + "github.com/uptrace/bunrouter" +) + +// DeleteImage +// +// @summary Delete image +// @description delete image along with the links +// @param id path int64 true "Image Id" +// @success 200 +// @failure 401 +// @failure 404 +// @router /api/image/{id} [delete] +func (self *Handlers) DeleteImage( + w http.ResponseWriter, req bunrouter.Request, +) error { + return utils.Success(w) +} diff --git a/handlers/api/getAliasUpdate.go b/handlers/api/getAliasUpdate.go new file mode 100644 index 0000000..1c81676 --- /dev/null +++ b/handlers/api/getAliasUpdate.go @@ -0,0 +1,19 @@ +package api + +import ( + "net/http" + + "gitea.konchin.com/go2025/backend/utils" + "github.com/uptrace/bunrouter" +) + +// GetAliasUpdate +// +// @summary Get notification when alias update +// @description get update notification using websocket +// @router /api/alias-update [get] +func (self *Handlers) GetAliasUpdate( + w http.ResponseWriter, req bunrouter.Request, +) error { + return utils.Success(w) +} diff --git a/handlers/api/getAliases.go b/handlers/api/getAliases.go new file mode 100644 index 0000000..15742af --- /dev/null +++ b/handlers/api/getAliases.go @@ -0,0 +1,30 @@ +package api + +import ( + "fmt" + "net/http" + + "github.com/uptrace/bunrouter" +) + +type getAliasesOutputAlias struct { + Id int64 `json:"id"` + Name string `json:"name"` +} + +// GetAliases +// +// @summary Get aliases +// @description get alias ids and names +// @success 200 {object} []getAliasesOutputAlias +// @failure 400 +// @failure 401 +// @router /api/aliases [get] +func (self *Handlers) GetAliases( + w http.ResponseWriter, req bunrouter.Request, +) error { + // mock output + fmt.Fprintf(w, "%s", `[{"id": 1, "name": "yajiu"}]`) + return nil + // return utils.Success(w) +} diff --git a/handlers/api/getImages.go b/handlers/api/getImages.go index 896edd9..9f4ef03 100644 --- a/handlers/api/getImages.go +++ b/handlers/api/getImages.go @@ -9,14 +9,16 @@ import ( type getImagesOutputImage struct { Id int64 `json:"id"` - Uploader string `json:"uploaded_user_id"` - UploadTS int64 `json:"uploaded_at"` + Uploader string `json:"uploadedUserId"` + UploadTS int64 `json:"uploadedAt"` Aliases []string `json:"aliases"` } // GetImages // -// @success 200 {object} getImagesOutputImage +// @param images query []int64 false "Image Ids" attribute(optional) +// @param aliases query []int64 false "Alias Ids" attribute(optional) +// @success 200 {object} []getImagesOutputImage // @failure 400 // @failure 401 // @router /api/images [get] diff --git a/handlers/api/postImage.go b/handlers/api/postImage.go new file mode 100644 index 0000000..a2b1099 --- /dev/null +++ b/handlers/api/postImage.go @@ -0,0 +1,23 @@ +package api + +import ( + "net/http" + + "gitea.konchin.com/go2025/backend/utils" + "github.com/uptrace/bunrouter" +) + +// PostImage +// +// @param userinfo header string true "userinfo from /auth/gen-login-url" +// @accept image/png +// @accept image/jpeg +// @accept image/gif +// @success 200 +// @failure 401 +// @router /api/image [post] +func (self *Handlers) PostImage( + w http.ResponseWriter, req bunrouter.Request, +) error { + return utils.Success(w) +} diff --git a/handlers/api/putImageAliases.go b/handlers/api/putImageAliases.go new file mode 100644 index 0000000..c21954e --- /dev/null +++ b/handlers/api/putImageAliases.go @@ -0,0 +1,24 @@ +package api + +import ( + "net/http" + + "gitea.konchin.com/go2025/backend/utils" + "github.com/uptrace/bunrouter" +) + +type putImageAliasesInputAlias = string + +// PutImageAliases +// +// @param id path int64 true "Image Id" +// @param payload body []putImageAliasesInputAlias true "Payload" +// @success 200 +// @failure 401 +// @failure 404 +// @router /api/image/{id}/aliases [put] +func (self *Handlers) PutImageAliases( + w http.ResponseWriter, req bunrouter.Request, +) error { + return utils.Success(w) +} diff --git a/handlers/auth/postGenLoginUrl.go b/handlers/auth/postGenLoginUrl.go new file mode 100644 index 0000000..710dac1 --- /dev/null +++ b/handlers/auth/postGenLoginUrl.go @@ -0,0 +1,28 @@ +package auth + +import ( + "net/http" + + "gitea.konchin.com/go2025/backend/utils" + "github.com/uptrace/bunrouter" +) + +type postGenLoginUrlInput struct { + UserId string `json:"userId"` +} + +type postGenLoginUrlOutput struct { + LoginUrl string `json:"loginUrl"` +} + +// PostGenLoginUrl +// +// @param payload body postGenLoginUrlInput true "Payload" +// @success 200 {object} postGenLoginUrlOutput "Payload" +// @failure 400 +// @router /auth/gen-login-url [post] +func (self *Handlers) PostGenLoginUrl( + w http.ResponseWriter, req bunrouter.Request, +) error { + return utils.Success(w) +}