From 09fb43055a4cb6bc5e0f1981ad84a3cf993a1c3e Mon Sep 17 00:00:00 2001 From: everpcpc Date: Fri, 17 May 2024 12:51:21 +0000 Subject: [PATCH] feat: add user character & person collection api spec --- ...tion.yaml => user_subject_collection.yaml} | 0 ...er_subject_collection_modify_payload.yaml} | 0 openapi/v0.yaml | 346 +++++++++++++++++- web/routes.go | 13 +- 4 files changed, 353 insertions(+), 6 deletions(-) rename openapi/components/{subject_collection.yaml => user_subject_collection.yaml} (100%) rename openapi/components/{subject_collection_modify_payload.yaml => user_subject_collection_modify_payload.yaml} (100%) diff --git a/openapi/components/subject_collection.yaml b/openapi/components/user_subject_collection.yaml similarity index 100% rename from openapi/components/subject_collection.yaml rename to openapi/components/user_subject_collection.yaml diff --git a/openapi/components/subject_collection_modify_payload.yaml b/openapi/components/user_subject_collection_modify_payload.yaml similarity index 100% rename from openapi/components/subject_collection_modify_payload.yaml rename to openapi/components/user_subject_collection_modify_payload.yaml diff --git a/openapi/v0.yaml b/openapi/v0.yaml index 4825439e1..16fb81a38 100644 --- a/openapi/v0.yaml +++ b/openapi/v0.yaml @@ -571,6 +571,70 @@ paths: application/json: schema: "$ref": "#/components/schemas/ErrorDetail" + "/v0/characters/{character_id}/collect": + post: + tags: + - 角色 + summary: Collect character for current user + operationId: collectCharacterByCharacterIdAndUserId + description: 为当前用户收藏角色 + parameters: + - $ref: "#/components/parameters/path_character_id" + responses: + "204": + description: Successful Response + "400": + description: character ID not valid + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "401": + description: not authorized + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "404": + description: 角色不存在 + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + security: + - HTTPBearer: [] + delete: + tags: + - 角色 + summary: Uncollect character for current user + operationId: uncollectCharacterByCharacterIdAndUserId + description: 为当前用户取消收藏角色 + parameters: + - $ref: "#/components/parameters/path_character_id" + responses: + "204": + description: Successful Response + "400": + description: character ID not valid + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "401": + description: not authorized + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "404": + description: 角色不存在 + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + security: + - HTTPBearer: [] + "/v0/persons/{person_id}": get: tags: @@ -696,6 +760,69 @@ paths: application/json: schema: "$ref": "#/components/schemas/ErrorDetail" + "/v0/persons/{person_id}/collect": + post: + tags: + - 人物 + summary: Collect person for current user + operationId: collectPersonByPersonIdAndUserId + description: 为当前用户收藏人物 + parameters: + - $ref: "#/components/parameters/path_person_id" + responses: + "204": + description: Successful Response + "400": + description: person ID not valid + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "401": + description: not authorized + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "404": + description: 人物不存在 + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + security: + - OptionalHTTPBearer: [] + delete: + tags: + - 人物 + summary: Uncollect person for current user + operationId: uncollectPersonByPersonIdAndUserId + description: 为当前用户取消收藏人物 + parameters: + - $ref: "#/components/parameters/path_person_id" + responses: + "204": + description: Successful Response + "400": + description: person ID not valid + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "401": + description: not authorized + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "404": + description: 人物不存在 + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + security: + - OptionalHTTPBearer: [] "/v0/users/{username}": get: @@ -847,8 +974,8 @@ paths: get: tags: - 收藏 - summary: 获取用户单个收藏 - description: 获取对应用户的收藏,查看私有收藏需要access token。 + summary: 获取用户单个条目收藏 + description: 获取对应用户的收藏,查看私有收藏需要 access token operationId: getUserCollection parameters: - $ref: "#/components/parameters/path_username" @@ -878,7 +1005,7 @@ paths: post: tags: - 收藏 - summary: 新增或修改用户单个收藏 + summary: 新增或修改用户单个条目收藏 description: | 修改条目收藏状态, 如果不存在则创建,如果存在则修改 @@ -1143,6 +1270,106 @@ paths: security: - HTTPBearer: [] + "/v0/users/{username}/collections/-/characters": + get: + tags: + - 收藏 + summary: 获取用户角色收藏列表 + operationId: getUserCharacterCollections + parameters: + - $ref: "#/components/parameters/path_username" + responses: + "200": + description: Successful Response + content: + application/json: + schema: + "$ref": "#/components/schemas/Paged_UserCharacterCollection" + "404": + description: 用户不存在 + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "/v0/users/{username}/collections/-/characters/{character_id}": + get: + tags: + - 收藏 + summary: 获取用户单个角色收藏信息 + operationId: getUserCharacterCollection + parameters: + - $ref: "#/components/parameters/path_username" + - $ref: "#/components/parameters/path_character_id" + responses: + "200": + description: Successful Response + content: + application/json: + schema: + "$ref": "#/components/schemas/UserCharacterCollection" + "400": + description: character ID not valid + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "404": + description: 用户或角色不存在 + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + + "/v0/users/{username}/collections/-/persons": + get: + tags: + - 收藏 + summary: 获取用户人物收藏列表 + operationId: getUserPersonCollections + parameters: + - $ref: "#/components/parameters/path_username" + responses: + "200": + description: Successful Response + content: + application/json: + schema: + "$ref": "#/components/schemas/Paged_UserPersonCollection" + "404": + description: 用户不存在 + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "/v0/users/{username}/collections/-/persons/{person_id}": + get: + tags: + - 收藏 + summary: 获取用户单个人物收藏信息 + operationId: getUserPersonCollection + parameters: + - $ref: "#/components/parameters/path_username" + - $ref: "#/components/parameters/path_person_id" + responses: + "200": + description: Successful Response + content: + application/json: + schema: + "$ref": "#/components/schemas/UserPersonCollection" + "400": + description: person ID not valid + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "404": + description: 用户或人物不存在 + content: + application/json: + schema: + "$ref": "#/components/schemas/ErrorDetail" + "/v0/revisions/persons": get: tags: @@ -2342,6 +2569,50 @@ components: items: "$ref": "#/components/schemas/UserSubjectCollection" default: [] + Paged_UserCharacterCollection: + title: Paged[UserCharacterCollection] + type: object + properties: + total: + title: Total + type: integer + default: 0 + limit: + title: Limit + type: integer + default: 0 + offset: + title: Offset + type: integer + default: 0 + data: + title: Data + type: array + items: + "$ref": "#/components/schemas/UserCharacterCollection" + default: [] + Paged_UserPersonCollection: + title: Paged[UserPersonCollection] + type: object + properties: + total: + title: Total + type: integer + default: 0 + limit: + title: Limit + type: integer + default: 0 + offset: + title: Offset + type: integer + default: 0 + data: + title: Data + type: array + items: + "$ref": "#/components/schemas/UserPersonCollection" + default: [] Person: title: Person required: @@ -2621,6 +2892,71 @@ components: relation: title: Relation type: string + UserCharacterCollection: + title: UserCharacterCollection + required: + - id + - name + - type + - created_at + type: object + properties: + id: + title: ID + type: integer + name: + title: Name + type: string + type: + type: integer + allOf: + - "$ref": "#/components/schemas/CharacterType" + description: 角色,机体,舰船,组织... + images: + title: Images + type: object + allOf: + - "$ref": "#/components/schemas/PersonImages" + description: object with some size of images, this object maybe `null` + created_at: + title: Created At + type: string + format: date-time + UserPersonCollection: + title: UserPersonCollection + required: + - id + - name + - type + - career + - created_at + type: object + properties: + id: + title: ID + type: integer + name: + title: Name + type: string + type: + type: integer + allOf: + - "$ref": "#/components/schemas/PersonType" + description: "`1`, `2`, `3` 表示 `个人`, `公司`, `组合`" + career: + type: array + items: + "$ref": "#/components/schemas/PersonCareer" + images: + title: Images + type: object + allOf: + - "$ref": "#/components/schemas/PersonImages" + description: object with some size of images, this object maybe `null` + created_at: + title: Created At + type: string + format: date-time Revision: title: Revision required: @@ -2667,9 +3003,9 @@ components: SubjectType: $ref: "./components/subject_type.yaml" UserSubjectCollection: - $ref: "./components/subject_collection.yaml" + $ref: "./components/user_subject_collection.yaml" UserSubjectCollectionModifyPayload: - $ref: "./components/subject_collection_modify_payload.yaml" + $ref: "./components/user_subject_collection_modify_payload.yaml" UserEpisodeCollection: $ref: "./components/get-user-episodes-collection.yaml" v0_RelatedSubject: diff --git a/web/routes.go b/web/routes.go index dc071617c..8d46167cd 100644 --- a/web/routes.go +++ b/web/routes.go @@ -66,18 +66,26 @@ func AddRouters( v0.GET("/persons/:id/image", personHandler.GetImage) v0.GET("/persons/:id/subjects", personHandler.GetRelatedSubjects) v0.GET("/persons/:id/characters", personHandler.GetRelatedCharacters) + // v0.POST("/persons/:id/collect", personHandler.CollectCharacter, mw.NeedLogin) + // v0.DELETE("/persons/:id/collect", personHandler.UnCollectCharacter, mw.NeedLogin) + v0.GET("/characters/:id", characterHandler.Get) v0.GET("/characters/:id/image", characterHandler.GetImage) v0.GET("/characters/:id/subjects", characterHandler.GetRelatedSubjects) v0.GET("/characters/:id/persons", characterHandler.GetRelatedPersons) + // v0.POST("/characters/:id/collect", characterHandler.CollectCharacter, mw.NeedLogin) + // v0.DELETE("/characters/:id/collect", characterHandler.UnCollectCharacter, mw.NeedLogin) + v0.GET("/episodes/:id", h.GetEpisode) v0.GET("/episodes", h.ListEpisode) // echo 中间件从前往后运行按顺序 v0.GET("/me", userHandler.GetCurrent) v0.GET("/users/:username", userHandler.Get) + v0.GET("/users/:username/avatar", userHandler.GetAvatar) v0.GET("/users/:username/collections", userHandler.ListSubjectCollection) v0.GET("/users/:username/collections/:subject_id", userHandler.GetSubjectCollection) + v0.GET("/users/-/collections/-/episodes/:episode_id", userHandler.GetEpisodeCollection, mw.NeedLogin) v0.PUT("/users/-/collections/-/episodes/:episode_id", userHandler.PutEpisodeCollection, req.JSON, mw.NeedLogin) v0.GET("/users/-/collections/:subject_id/episodes", userHandler.GetSubjectEpisodeCollection, mw.NeedLogin) @@ -86,7 +94,10 @@ func AddRouters( v0.PATCH("/users/-/collections/:subject_id/episodes", userHandler.PatchEpisodeCollectionBatch, req.JSON, mw.NeedLogin) - v0.GET("/users/:username/avatar", userHandler.GetAvatar) + // v0.GET("/users/:username/collections/-/characters", userHandler.ListCharacterCollection) + // v0.GET("/users/:username/collections/-/characters/:character_id", userHandler.GetCharacterCollection) + // v0.GET("/users/:username/collections/-/persons", userHandler.ListPersonCollection) + // v0.GET("/users/:username/collections/-/persons/:person_id", userHandler.GetPersonCollection) { i := indexHandler