Compare commits
10 commits
dbdb52269a
...
e0a68d7d0f
| Author | SHA1 | Date | |
|---|---|---|---|
| e0a68d7d0f | |||
| cb9fba6fbc | |||
| 759679990a | |||
| 65b76d58c3 | |||
| 51bf7b6f7e | |||
| 9139c77c5f | |||
| b8bfe01ef5 | |||
| 0cda597001 | |||
| 354c577f7d | |||
| 87eb6a6b12 |
24 changed files with 1061 additions and 437 deletions
|
|
@ -11,52 +11,52 @@ paths:
|
|||
parameters:
|
||||
- $ref: '#/components/parameters/cursor'
|
||||
- $ref: '#/components/parameters/title_sort'
|
||||
- in: query
|
||||
name: sort_forward
|
||||
- name: sort_forward
|
||||
in: query
|
||||
schema:
|
||||
type: boolean
|
||||
default: true
|
||||
- in: query
|
||||
name: word
|
||||
- name: word
|
||||
in: query
|
||||
schema:
|
||||
type: string
|
||||
- in: query
|
||||
name: status
|
||||
- name: status
|
||||
in: query
|
||||
description: List of title statuses to filter
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/TitleStatus'
|
||||
description: List of title statuses to filter
|
||||
style: form
|
||||
explode: false
|
||||
- in: query
|
||||
name: rating
|
||||
style: form
|
||||
- name: rating
|
||||
in: query
|
||||
schema:
|
||||
type: number
|
||||
format: double
|
||||
- in: query
|
||||
name: release_year
|
||||
- name: release_year
|
||||
in: query
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
- in: query
|
||||
name: release_season
|
||||
- name: release_season
|
||||
in: query
|
||||
schema:
|
||||
$ref: '#/components/schemas/ReleaseSeason'
|
||||
- in: query
|
||||
name: limit
|
||||
- name: limit
|
||||
in: query
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
default: 10
|
||||
- in: query
|
||||
name: offset
|
||||
- name: offset
|
||||
in: query
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
default: 0
|
||||
- in: query
|
||||
name: fields
|
||||
- name: fields
|
||||
in: query
|
||||
schema:
|
||||
type: string
|
||||
default: all
|
||||
|
|
@ -69,10 +69,10 @@ paths:
|
|||
type: object
|
||||
properties:
|
||||
data:
|
||||
description: List of titles
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Title'
|
||||
description: List of titles
|
||||
cursor:
|
||||
$ref: '#/components/schemas/CursorObj'
|
||||
required:
|
||||
|
|
@ -88,14 +88,14 @@ paths:
|
|||
get:
|
||||
summary: Get title description
|
||||
parameters:
|
||||
- in: path
|
||||
name: title_id
|
||||
- name: title_id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
- in: query
|
||||
name: fields
|
||||
- name: fields
|
||||
in: query
|
||||
schema:
|
||||
type: string
|
||||
default: all
|
||||
|
|
@ -118,13 +118,13 @@ paths:
|
|||
get:
|
||||
summary: Get user info
|
||||
parameters:
|
||||
- in: path
|
||||
name: user_id
|
||||
- name: user_id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- in: query
|
||||
name: fields
|
||||
- name: fields
|
||||
in: query
|
||||
schema:
|
||||
type: string
|
||||
default: all
|
||||
|
|
@ -142,59 +142,59 @@ paths:
|
|||
'500':
|
||||
description: Unknown server error
|
||||
patch:
|
||||
operationId: updateUser
|
||||
summary: Partially update a user account
|
||||
description: |
|
||||
Update selected user profile fields (excluding password).
|
||||
Password updates must be done via the dedicated auth-service (`/auth/`).
|
||||
Fields not provided in the request body remain unchanged.
|
||||
operationId: updateUser
|
||||
parameters:
|
||||
- name: user_id
|
||||
in: path
|
||||
description: User ID (primary key)
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
description: User ID (primary key)
|
||||
example: 123
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
description: Only provided fields are updated. Omitted fields remain unchanged.
|
||||
type: object
|
||||
properties:
|
||||
avatar_id:
|
||||
description: ID of the user avatar (references `images.id`); set to `null` to remove avatar
|
||||
type: integer
|
||||
format: int64
|
||||
nullable: true
|
||||
description: ID of the user avatar (references `images.id`); set to `null` to remove avatar
|
||||
example: 42
|
||||
nullable: true
|
||||
mail:
|
||||
description: User email (must be unique and valid)
|
||||
type: string
|
||||
format: email
|
||||
pattern: '^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+$'
|
||||
description: User email (must be unique and valid)
|
||||
example: john.doe.updated@example.com
|
||||
pattern: '^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+$'
|
||||
nickname:
|
||||
type: string
|
||||
pattern: '^[a-zA-Z0-9_-]{3,16}$'
|
||||
description: 'Username (alphanumeric + `_` or `-`, 3–16 chars)'
|
||||
type: string
|
||||
example: john_doe_43
|
||||
maxLength: 16
|
||||
minLength: 3
|
||||
example: john_doe_43
|
||||
pattern: '^[a-zA-Z0-9_-]{3,16}$'
|
||||
disp_name:
|
||||
type: string
|
||||
description: Display name
|
||||
maxLength: 32
|
||||
example: John Smith
|
||||
user_desc:
|
||||
type: string
|
||||
example: John Smith
|
||||
maxLength: 32
|
||||
user_desc:
|
||||
description: User description / bio
|
||||
maxLength: 512
|
||||
type: string
|
||||
example: Just a curious developer.
|
||||
maxLength: 512
|
||||
additionalProperties: false
|
||||
description: Only provided fields are updated. Omitted fields remain unchanged.
|
||||
responses:
|
||||
'200':
|
||||
description: User updated successfully. Returns updated user representation (excluding sensitive fields).
|
||||
|
|
@ -222,64 +222,64 @@ paths:
|
|||
parameters:
|
||||
- $ref: '#/components/parameters/cursor'
|
||||
- $ref: '#/components/parameters/title_sort'
|
||||
- in: path
|
||||
name: user_id
|
||||
- name: user_id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- in: query
|
||||
name: sort_forward
|
||||
- name: sort_forward
|
||||
in: query
|
||||
schema:
|
||||
type: boolean
|
||||
default: true
|
||||
- in: query
|
||||
name: word
|
||||
- name: word
|
||||
in: query
|
||||
schema:
|
||||
type: string
|
||||
- in: query
|
||||
name: status
|
||||
- name: status
|
||||
in: query
|
||||
description: List of title statuses to filter
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/TitleStatus'
|
||||
description: List of title statuses to filter
|
||||
style: form
|
||||
explode: false
|
||||
- in: query
|
||||
name: watch_status
|
||||
style: form
|
||||
- name: watch_status
|
||||
in: query
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/UserTitleStatus'
|
||||
style: form
|
||||
explode: false
|
||||
- in: query
|
||||
name: rating
|
||||
style: form
|
||||
- name: rating
|
||||
in: query
|
||||
schema:
|
||||
type: number
|
||||
format: double
|
||||
- in: query
|
||||
name: my_rate
|
||||
- name: my_rate
|
||||
in: query
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
- in: query
|
||||
name: release_year
|
||||
- name: release_year
|
||||
in: query
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
- in: query
|
||||
name: release_season
|
||||
- name: release_season
|
||||
in: query
|
||||
schema:
|
||||
$ref: '#/components/schemas/ReleaseSeason'
|
||||
- in: query
|
||||
name: limit
|
||||
- name: limit
|
||||
in: query
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
default: 10
|
||||
- in: query
|
||||
name: fields
|
||||
- name: fields
|
||||
in: query
|
||||
schema:
|
||||
type: string
|
||||
default: all
|
||||
|
|
@ -309,57 +309,43 @@ paths:
|
|||
'500':
|
||||
description: Unknown server error
|
||||
post:
|
||||
operationId: addUserTitle
|
||||
summary: Add a title to a user
|
||||
description: 'User adding title to list af watched, status required'
|
||||
operationId: addUserTitle
|
||||
parameters:
|
||||
- name: user_id
|
||||
in: path
|
||||
description: ID of the user to assign the title to
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
description: ID of the user to assign the title to
|
||||
example: 123
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/UserTitle'
|
||||
type: object
|
||||
properties:
|
||||
title_id:
|
||||
type: integer
|
||||
format: int64
|
||||
status:
|
||||
$ref: '#/components/schemas/UserTitleStatus'
|
||||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
required:
|
||||
- title_id
|
||||
- status
|
||||
responses:
|
||||
'200':
|
||||
description: Title successfully added to user
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
data:
|
||||
type: object
|
||||
required:
|
||||
- user_id
|
||||
- title_id
|
||||
- status
|
||||
properties:
|
||||
user_id:
|
||||
type: integer
|
||||
format: int64
|
||||
title_id:
|
||||
type: integer
|
||||
format: int64
|
||||
status:
|
||||
$ref: '#/components/schemas/UserTitleStatus'
|
||||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
review_id:
|
||||
type: integer
|
||||
format: int64
|
||||
ctime:
|
||||
type: string
|
||||
format: date-time
|
||||
additionalProperties: false
|
||||
$ref: '#/components/schemas/UserTitleMini'
|
||||
'400':
|
||||
description: 'Invalid request body (missing fields, invalid types, etc.)'
|
||||
'401':
|
||||
|
|
@ -372,6 +358,77 @@ paths:
|
|||
description: Conflict — title already assigned to user (if applicable)
|
||||
'500':
|
||||
description: Internal server error
|
||||
patch:
|
||||
operationId: updateUserTitle
|
||||
summary: Update a usertitle
|
||||
description: User updating title list of watched
|
||||
parameters:
|
||||
- name: user_id
|
||||
in: path
|
||||
description: ID of the user to assign the title to
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
example: 123
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
title_id:
|
||||
type: integer
|
||||
format: int64
|
||||
status:
|
||||
$ref: '#/components/schemas/UserTitleStatus'
|
||||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
required:
|
||||
- title_id
|
||||
responses:
|
||||
'200':
|
||||
description: Title successfully updated
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/UserTitleMini'
|
||||
'400':
|
||||
description: 'Invalid request body (missing fields, invalid types, etc.)'
|
||||
'401':
|
||||
description: Unauthorized — missing or invalid auth token
|
||||
'403':
|
||||
description: Forbidden — user not allowed to update title
|
||||
'404':
|
||||
description: User or Title not found
|
||||
'500':
|
||||
description: Internal server error
|
||||
delete:
|
||||
operationId: deleteUserTitle
|
||||
summary: Delete a usertitle
|
||||
description: User deleting title from list of watched
|
||||
parameters:
|
||||
- name: user_id
|
||||
in: path
|
||||
description: ID of the user to assign the title to
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
example: 123
|
||||
responses:
|
||||
'200':
|
||||
description: Title successfully deleted
|
||||
'401':
|
||||
description: Unauthorized — missing or invalid auth token
|
||||
'403':
|
||||
description: Forbidden — user not allowed to delete title
|
||||
'404':
|
||||
description: User or Title not found
|
||||
'500':
|
||||
description: Internal server error
|
||||
components:
|
||||
parameters:
|
||||
cursor:
|
||||
|
|
@ -387,25 +444,36 @@ components:
|
|||
schema:
|
||||
$ref: '#/components/schemas/TitleSort'
|
||||
schemas:
|
||||
CursorObj:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
param:
|
||||
type: string
|
||||
TitleSort:
|
||||
type: string
|
||||
description: Title sort order
|
||||
type: string
|
||||
default: id
|
||||
enum:
|
||||
- id
|
||||
- year
|
||||
- rating
|
||||
- views
|
||||
TitleStatus:
|
||||
description: Title status
|
||||
type: string
|
||||
enum:
|
||||
- finished
|
||||
- ongoing
|
||||
- planned
|
||||
ReleaseSeason:
|
||||
description: Title release season
|
||||
type: string
|
||||
enum:
|
||||
- winter
|
||||
- spring
|
||||
- summer
|
||||
- fall
|
||||
StorageType:
|
||||
description: Image storage type
|
||||
type: string
|
||||
enum:
|
||||
- s3
|
||||
- local
|
||||
Image:
|
||||
type: object
|
||||
properties:
|
||||
|
|
@ -413,65 +481,11 @@ components:
|
|||
type: integer
|
||||
format: int64
|
||||
storage_type:
|
||||
type: string
|
||||
description: Image storage type
|
||||
enum:
|
||||
- s3
|
||||
- local
|
||||
$ref: '#/components/schemas/StorageType'
|
||||
image_path:
|
||||
type: string
|
||||
TitleStatus:
|
||||
type: string
|
||||
description: Title status
|
||||
enum:
|
||||
- finished
|
||||
- ongoing
|
||||
- planned
|
||||
ReleaseSeason:
|
||||
type: string
|
||||
description: Title release season
|
||||
enum:
|
||||
- winter
|
||||
- spring
|
||||
- summer
|
||||
- fall
|
||||
UserTitleStatus:
|
||||
type: string
|
||||
description: User's title status
|
||||
enum:
|
||||
- finished
|
||||
- planned
|
||||
- dropped
|
||||
- in-progress
|
||||
Review:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
Tag:
|
||||
type: object
|
||||
description: 'A localized tag: keys are language codes (ISO 639-1), values are tag names'
|
||||
additionalProperties:
|
||||
type: string
|
||||
example:
|
||||
en: Shojo
|
||||
ru: Сёдзё
|
||||
ja: 少女
|
||||
Tags:
|
||||
type: array
|
||||
description: Array of localized tags
|
||||
items:
|
||||
$ref: '#/components/schemas/Tag'
|
||||
example:
|
||||
- en: Shojo
|
||||
ru: Сёдзё
|
||||
ja: 少女
|
||||
- en: Shounen
|
||||
ru: Сёнен
|
||||
ja: 少年
|
||||
Studio:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
|
|
@ -482,30 +496,41 @@ components:
|
|||
$ref: '#/components/schemas/Image'
|
||||
description:
|
||||
type: string
|
||||
Title:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
- title_names
|
||||
- tags
|
||||
- name
|
||||
Tag:
|
||||
description: 'A localized tag: keys are language codes (ISO 639-1), values are tag names'
|
||||
type: object
|
||||
example:
|
||||
en: Shojo
|
||||
ru: Сёдзё
|
||||
ja: 少女
|
||||
additionalProperties:
|
||||
type: string
|
||||
Tags:
|
||||
description: Array of localized tags
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Tag'
|
||||
example:
|
||||
- en: Shojo
|
||||
ru: Сёдзё
|
||||
ja: 少女
|
||||
- en: Shounen
|
||||
ru: Сёнен
|
||||
ja: 少年
|
||||
Title:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
description: Unique title ID (primary key)
|
||||
type: integer
|
||||
format: int64
|
||||
description: Unique title ID (primary key)
|
||||
example: 1
|
||||
title_names:
|
||||
type: object
|
||||
description: 'Localized titles. Key = language (ISO 639-1), value = list of names'
|
||||
additionalProperties:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
example: Attack on Titan
|
||||
minItems: 1
|
||||
example:
|
||||
- Attack on Titan
|
||||
- AoT
|
||||
type: object
|
||||
example:
|
||||
en:
|
||||
- Attack on Titan
|
||||
|
|
@ -515,6 +540,15 @@ components:
|
|||
- Титаны
|
||||
ja:
|
||||
- 進撃の巨人
|
||||
additionalProperties:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
example: Attack on Titan
|
||||
minItems: 1
|
||||
example:
|
||||
- Attack on Titan
|
||||
- AoT
|
||||
studio:
|
||||
$ref: '#/components/schemas/Studio'
|
||||
tags:
|
||||
|
|
@ -546,50 +580,68 @@ components:
|
|||
type: number
|
||||
format: double
|
||||
additionalProperties: true
|
||||
User:
|
||||
required:
|
||||
- id
|
||||
- title_names
|
||||
- tags
|
||||
CursorObj:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
param:
|
||||
type: string
|
||||
required:
|
||||
- id
|
||||
User:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
description: Unique user ID (primary key)
|
||||
type: integer
|
||||
format: int64
|
||||
example: 1
|
||||
image:
|
||||
$ref: '#/components/schemas/Image'
|
||||
mail:
|
||||
description: User email
|
||||
type: string
|
||||
format: email
|
||||
description: User email
|
||||
example: john.doe@example.com
|
||||
nickname:
|
||||
type: string
|
||||
description: Username (alphanumeric + _ or -)
|
||||
maxLength: 16
|
||||
type: string
|
||||
example: john_doe_42
|
||||
maxLength: 16
|
||||
disp_name:
|
||||
type: string
|
||||
description: Display name
|
||||
maxLength: 32
|
||||
example: John Doe
|
||||
user_desc:
|
||||
type: string
|
||||
example: John Doe
|
||||
maxLength: 32
|
||||
user_desc:
|
||||
description: User description
|
||||
maxLength: 512
|
||||
type: string
|
||||
example: Just a regular user.
|
||||
maxLength: 512
|
||||
creation_date:
|
||||
description: Timestamp when the user was created
|
||||
type: string
|
||||
format: date-time
|
||||
description: Timestamp when the user was created
|
||||
example: '2025-10-10T23:45:47.908073Z'
|
||||
required:
|
||||
- user_id
|
||||
- nickname
|
||||
UserTitleStatus:
|
||||
description: User's title status
|
||||
type: string
|
||||
enum:
|
||||
- finished
|
||||
- planned
|
||||
- dropped
|
||||
- in-progress
|
||||
UserTitle:
|
||||
type: object
|
||||
required:
|
||||
- user_id
|
||||
- title_id
|
||||
- status
|
||||
properties:
|
||||
user_id:
|
||||
type: integer
|
||||
|
|
@ -607,4 +659,34 @@ components:
|
|||
ctime:
|
||||
type: string
|
||||
format: date-time
|
||||
required:
|
||||
- user_id
|
||||
- title_id
|
||||
- status
|
||||
UserTitleMini:
|
||||
type: object
|
||||
properties:
|
||||
user_id:
|
||||
type: integer
|
||||
format: int64
|
||||
title_id:
|
||||
type: integer
|
||||
format: int64
|
||||
status:
|
||||
$ref: '#/components/schemas/UserTitleStatus'
|
||||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
review_id:
|
||||
type: integer
|
||||
format: int64
|
||||
ctime:
|
||||
type: string
|
||||
format: date-time
|
||||
required:
|
||||
- user_id
|
||||
- title_id
|
||||
- status
|
||||
Review:
|
||||
type: object
|
||||
additionalProperties: true
|
||||
|
|
|
|||
444
api/api.gen.go
444
api/api.gen.go
|
|
@ -16,12 +16,6 @@ import (
|
|||
openapi_types "github.com/oapi-codegen/runtime/types"
|
||||
)
|
||||
|
||||
// Defines values for ImageStorageType.
|
||||
const (
|
||||
Local ImageStorageType = "local"
|
||||
S3 ImageStorageType = "s3"
|
||||
)
|
||||
|
||||
// Defines values for ReleaseSeason.
|
||||
const (
|
||||
Fall ReleaseSeason = "fall"
|
||||
|
|
@ -30,6 +24,12 @@ const (
|
|||
Winter ReleaseSeason = "winter"
|
||||
)
|
||||
|
||||
// Defines values for StorageType.
|
||||
const (
|
||||
Local StorageType = "local"
|
||||
S3 StorageType = "s3"
|
||||
)
|
||||
|
||||
// Defines values for TitleSort.
|
||||
const (
|
||||
Id TitleSort = "id"
|
||||
|
|
@ -65,15 +65,15 @@ type Image struct {
|
|||
ImagePath *string `json:"image_path,omitempty"`
|
||||
|
||||
// StorageType Image storage type
|
||||
StorageType *ImageStorageType `json:"storage_type,omitempty"`
|
||||
StorageType *StorageType `json:"storage_type,omitempty"`
|
||||
}
|
||||
|
||||
// ImageStorageType Image storage type
|
||||
type ImageStorageType string
|
||||
|
||||
// ReleaseSeason Title release season
|
||||
type ReleaseSeason string
|
||||
|
||||
// StorageType Image storage type
|
||||
type StorageType string
|
||||
|
||||
// Studio defines model for Studio.
|
||||
type Studio struct {
|
||||
Description *string `json:"description,omitempty"`
|
||||
|
|
@ -151,10 +151,21 @@ type UserTitle struct {
|
|||
ReviewId *int64 `json:"review_id,omitempty"`
|
||||
|
||||
// Status User's title status
|
||||
Status UserTitleStatus `json:"status"`
|
||||
Title *Title `json:"title,omitempty"`
|
||||
UserId int64 `json:"user_id"`
|
||||
AdditionalProperties map[string]interface{} `json:"-"`
|
||||
Status UserTitleStatus `json:"status"`
|
||||
Title *Title `json:"title,omitempty"`
|
||||
UserId int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
// UserTitleMini defines model for UserTitleMini.
|
||||
type UserTitleMini struct {
|
||||
Ctime *time.Time `json:"ctime,omitempty"`
|
||||
Rate *int32 `json:"rate,omitempty"`
|
||||
ReviewId *int64 `json:"review_id,omitempty"`
|
||||
|
||||
// Status User's title status
|
||||
Status UserTitleStatus `json:"status"`
|
||||
TitleId int64 `json:"title_id"`
|
||||
UserId int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
// UserTitleStatus User's title status
|
||||
|
|
@ -226,11 +237,32 @@ type GetUsersUserIdTitlesParams struct {
|
|||
Fields *string `form:"fields,omitempty" json:"fields,omitempty"`
|
||||
}
|
||||
|
||||
// UpdateUserTitleJSONBody defines parameters for UpdateUserTitle.
|
||||
type UpdateUserTitleJSONBody struct {
|
||||
Rate *int32 `json:"rate,omitempty"`
|
||||
|
||||
// Status User's title status
|
||||
Status *UserTitleStatus `json:"status,omitempty"`
|
||||
TitleId int64 `json:"title_id"`
|
||||
}
|
||||
|
||||
// AddUserTitleJSONBody defines parameters for AddUserTitle.
|
||||
type AddUserTitleJSONBody struct {
|
||||
Rate *int32 `json:"rate,omitempty"`
|
||||
|
||||
// Status User's title status
|
||||
Status UserTitleStatus `json:"status"`
|
||||
TitleId int64 `json:"title_id"`
|
||||
}
|
||||
|
||||
// UpdateUserJSONRequestBody defines body for UpdateUser for application/json ContentType.
|
||||
type UpdateUserJSONRequestBody UpdateUserJSONBody
|
||||
|
||||
// UpdateUserTitleJSONRequestBody defines body for UpdateUserTitle for application/json ContentType.
|
||||
type UpdateUserTitleJSONRequestBody UpdateUserTitleJSONBody
|
||||
|
||||
// AddUserTitleJSONRequestBody defines body for AddUserTitle for application/json ContentType.
|
||||
type AddUserTitleJSONRequestBody = UserTitle
|
||||
type AddUserTitleJSONRequestBody AddUserTitleJSONBody
|
||||
|
||||
// Getter for additional properties for Title. Returns the specified
|
||||
// element and whether it was found
|
||||
|
|
@ -474,145 +506,6 @@ func (a Title) MarshalJSON() ([]byte, error) {
|
|||
return json.Marshal(object)
|
||||
}
|
||||
|
||||
// Getter for additional properties for UserTitle. Returns the specified
|
||||
// element and whether it was found
|
||||
func (a UserTitle) Get(fieldName string) (value interface{}, found bool) {
|
||||
if a.AdditionalProperties != nil {
|
||||
value, found = a.AdditionalProperties[fieldName]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Setter for additional properties for UserTitle
|
||||
func (a *UserTitle) Set(fieldName string, value interface{}) {
|
||||
if a.AdditionalProperties == nil {
|
||||
a.AdditionalProperties = make(map[string]interface{})
|
||||
}
|
||||
a.AdditionalProperties[fieldName] = value
|
||||
}
|
||||
|
||||
// Override default JSON handling for UserTitle to handle AdditionalProperties
|
||||
func (a *UserTitle) UnmarshalJSON(b []byte) error {
|
||||
object := make(map[string]json.RawMessage)
|
||||
err := json.Unmarshal(b, &object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if raw, found := object["ctime"]; found {
|
||||
err = json.Unmarshal(raw, &a.Ctime)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading 'ctime': %w", err)
|
||||
}
|
||||
delete(object, "ctime")
|
||||
}
|
||||
|
||||
if raw, found := object["rate"]; found {
|
||||
err = json.Unmarshal(raw, &a.Rate)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading 'rate': %w", err)
|
||||
}
|
||||
delete(object, "rate")
|
||||
}
|
||||
|
||||
if raw, found := object["review_id"]; found {
|
||||
err = json.Unmarshal(raw, &a.ReviewId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading 'review_id': %w", err)
|
||||
}
|
||||
delete(object, "review_id")
|
||||
}
|
||||
|
||||
if raw, found := object["status"]; found {
|
||||
err = json.Unmarshal(raw, &a.Status)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading 'status': %w", err)
|
||||
}
|
||||
delete(object, "status")
|
||||
}
|
||||
|
||||
if raw, found := object["title"]; found {
|
||||
err = json.Unmarshal(raw, &a.Title)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading 'title': %w", err)
|
||||
}
|
||||
delete(object, "title")
|
||||
}
|
||||
|
||||
if raw, found := object["user_id"]; found {
|
||||
err = json.Unmarshal(raw, &a.UserId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading 'user_id': %w", err)
|
||||
}
|
||||
delete(object, "user_id")
|
||||
}
|
||||
|
||||
if len(object) != 0 {
|
||||
a.AdditionalProperties = make(map[string]interface{})
|
||||
for fieldName, fieldBuf := range object {
|
||||
var fieldVal interface{}
|
||||
err := json.Unmarshal(fieldBuf, &fieldVal)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error unmarshaling field %s: %w", fieldName, err)
|
||||
}
|
||||
a.AdditionalProperties[fieldName] = fieldVal
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Override default JSON handling for UserTitle to handle AdditionalProperties
|
||||
func (a UserTitle) MarshalJSON() ([]byte, error) {
|
||||
var err error
|
||||
object := make(map[string]json.RawMessage)
|
||||
|
||||
if a.Ctime != nil {
|
||||
object["ctime"], err = json.Marshal(a.Ctime)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling 'ctime': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if a.Rate != nil {
|
||||
object["rate"], err = json.Marshal(a.Rate)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling 'rate': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if a.ReviewId != nil {
|
||||
object["review_id"], err = json.Marshal(a.ReviewId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling 'review_id': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
object["status"], err = json.Marshal(a.Status)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling 'status': %w", err)
|
||||
}
|
||||
|
||||
if a.Title != nil {
|
||||
object["title"], err = json.Marshal(a.Title)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling 'title': %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
object["user_id"], err = json.Marshal(a.UserId)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling 'user_id': %w", err)
|
||||
}
|
||||
|
||||
for fieldName, field := range a.AdditionalProperties {
|
||||
object[fieldName], err = json.Marshal(field)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error marshaling '%s': %w", fieldName, err)
|
||||
}
|
||||
}
|
||||
return json.Marshal(object)
|
||||
}
|
||||
|
||||
// ServerInterface represents all server handlers.
|
||||
type ServerInterface interface {
|
||||
// Get titles
|
||||
|
|
@ -627,9 +520,15 @@ type ServerInterface interface {
|
|||
// Partially update a user account
|
||||
// (PATCH /users/{user_id})
|
||||
UpdateUser(c *gin.Context, userId int64)
|
||||
// Delete a usertitle
|
||||
// (DELETE /users/{user_id}/titles)
|
||||
DeleteUserTitle(c *gin.Context, userId int64)
|
||||
// Get user titles
|
||||
// (GET /users/{user_id}/titles)
|
||||
GetUsersUserIdTitles(c *gin.Context, userId string, params GetUsersUserIdTitlesParams)
|
||||
// Update a usertitle
|
||||
// (PATCH /users/{user_id}/titles)
|
||||
UpdateUserTitle(c *gin.Context, userId int64)
|
||||
// Add a title to a user
|
||||
// (POST /users/{user_id}/titles)
|
||||
AddUserTitle(c *gin.Context, userId int64)
|
||||
|
|
@ -844,6 +743,30 @@ func (siw *ServerInterfaceWrapper) UpdateUser(c *gin.Context) {
|
|||
siw.Handler.UpdateUser(c, userId)
|
||||
}
|
||||
|
||||
// DeleteUserTitle operation middleware
|
||||
func (siw *ServerInterfaceWrapper) DeleteUserTitle(c *gin.Context) {
|
||||
|
||||
var err error
|
||||
|
||||
// ------------- Path parameter "user_id" -------------
|
||||
var userId int64
|
||||
|
||||
err = runtime.BindStyledParameterWithOptions("simple", "user_id", c.Param("user_id"), &userId, runtime.BindStyledParameterOptions{Explode: false, Required: true})
|
||||
if err != nil {
|
||||
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter user_id: %w", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
for _, middleware := range siw.HandlerMiddlewares {
|
||||
middleware(c)
|
||||
if c.IsAborted() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
siw.Handler.DeleteUserTitle(c, userId)
|
||||
}
|
||||
|
||||
// GetUsersUserIdTitles operation middleware
|
||||
func (siw *ServerInterfaceWrapper) GetUsersUserIdTitles(c *gin.Context) {
|
||||
|
||||
|
|
@ -967,6 +890,30 @@ func (siw *ServerInterfaceWrapper) GetUsersUserIdTitles(c *gin.Context) {
|
|||
siw.Handler.GetUsersUserIdTitles(c, userId, params)
|
||||
}
|
||||
|
||||
// UpdateUserTitle operation middleware
|
||||
func (siw *ServerInterfaceWrapper) UpdateUserTitle(c *gin.Context) {
|
||||
|
||||
var err error
|
||||
|
||||
// ------------- Path parameter "user_id" -------------
|
||||
var userId int64
|
||||
|
||||
err = runtime.BindStyledParameterWithOptions("simple", "user_id", c.Param("user_id"), &userId, runtime.BindStyledParameterOptions{Explode: false, Required: true})
|
||||
if err != nil {
|
||||
siw.ErrorHandler(c, fmt.Errorf("Invalid format for parameter user_id: %w", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
for _, middleware := range siw.HandlerMiddlewares {
|
||||
middleware(c)
|
||||
if c.IsAborted() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
siw.Handler.UpdateUserTitle(c, userId)
|
||||
}
|
||||
|
||||
// AddUserTitle operation middleware
|
||||
func (siw *ServerInterfaceWrapper) AddUserTitle(c *gin.Context) {
|
||||
|
||||
|
|
@ -1022,7 +969,9 @@ func RegisterHandlersWithOptions(router gin.IRouter, si ServerInterface, options
|
|||
router.GET(options.BaseURL+"/titles/:title_id", wrapper.GetTitlesTitleId)
|
||||
router.GET(options.BaseURL+"/users/:user_id", wrapper.GetUsersUserId)
|
||||
router.PATCH(options.BaseURL+"/users/:user_id", wrapper.UpdateUser)
|
||||
router.DELETE(options.BaseURL+"/users/:user_id/titles", wrapper.DeleteUserTitle)
|
||||
router.GET(options.BaseURL+"/users/:user_id/titles", wrapper.GetUsersUserIdTitles)
|
||||
router.PATCH(options.BaseURL+"/users/:user_id/titles", wrapper.UpdateUserTitle)
|
||||
router.POST(options.BaseURL+"/users/:user_id/titles", wrapper.AddUserTitle)
|
||||
}
|
||||
|
||||
|
|
@ -1238,6 +1187,54 @@ func (response UpdateUser500Response) VisitUpdateUserResponse(w http.ResponseWri
|
|||
return nil
|
||||
}
|
||||
|
||||
type DeleteUserTitleRequestObject struct {
|
||||
UserId int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
type DeleteUserTitleResponseObject interface {
|
||||
VisitDeleteUserTitleResponse(w http.ResponseWriter) error
|
||||
}
|
||||
|
||||
type DeleteUserTitle200Response struct {
|
||||
}
|
||||
|
||||
func (response DeleteUserTitle200Response) VisitDeleteUserTitleResponse(w http.ResponseWriter) error {
|
||||
w.WriteHeader(200)
|
||||
return nil
|
||||
}
|
||||
|
||||
type DeleteUserTitle401Response struct {
|
||||
}
|
||||
|
||||
func (response DeleteUserTitle401Response) VisitDeleteUserTitleResponse(w http.ResponseWriter) error {
|
||||
w.WriteHeader(401)
|
||||
return nil
|
||||
}
|
||||
|
||||
type DeleteUserTitle403Response struct {
|
||||
}
|
||||
|
||||
func (response DeleteUserTitle403Response) VisitDeleteUserTitleResponse(w http.ResponseWriter) error {
|
||||
w.WriteHeader(403)
|
||||
return nil
|
||||
}
|
||||
|
||||
type DeleteUserTitle404Response struct {
|
||||
}
|
||||
|
||||
func (response DeleteUserTitle404Response) VisitDeleteUserTitleResponse(w http.ResponseWriter) error {
|
||||
w.WriteHeader(404)
|
||||
return nil
|
||||
}
|
||||
|
||||
type DeleteUserTitle500Response struct {
|
||||
}
|
||||
|
||||
func (response DeleteUserTitle500Response) VisitDeleteUserTitleResponse(w http.ResponseWriter) error {
|
||||
w.WriteHeader(500)
|
||||
return nil
|
||||
}
|
||||
|
||||
type GetUsersUserIdTitlesRequestObject struct {
|
||||
UserId string `json:"user_id"`
|
||||
Params GetUsersUserIdTitlesParams
|
||||
|
|
@ -1291,6 +1288,64 @@ func (response GetUsersUserIdTitles500Response) VisitGetUsersUserIdTitlesRespons
|
|||
return nil
|
||||
}
|
||||
|
||||
type UpdateUserTitleRequestObject struct {
|
||||
UserId int64 `json:"user_id"`
|
||||
Body *UpdateUserTitleJSONRequestBody
|
||||
}
|
||||
|
||||
type UpdateUserTitleResponseObject interface {
|
||||
VisitUpdateUserTitleResponse(w http.ResponseWriter) error
|
||||
}
|
||||
|
||||
type UpdateUserTitle200JSONResponse UserTitleMini
|
||||
|
||||
func (response UpdateUserTitle200JSONResponse) VisitUpdateUserTitleResponse(w http.ResponseWriter) error {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(200)
|
||||
|
||||
return json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
|
||||
type UpdateUserTitle400Response struct {
|
||||
}
|
||||
|
||||
func (response UpdateUserTitle400Response) VisitUpdateUserTitleResponse(w http.ResponseWriter) error {
|
||||
w.WriteHeader(400)
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateUserTitle401Response struct {
|
||||
}
|
||||
|
||||
func (response UpdateUserTitle401Response) VisitUpdateUserTitleResponse(w http.ResponseWriter) error {
|
||||
w.WriteHeader(401)
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateUserTitle403Response struct {
|
||||
}
|
||||
|
||||
func (response UpdateUserTitle403Response) VisitUpdateUserTitleResponse(w http.ResponseWriter) error {
|
||||
w.WriteHeader(403)
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateUserTitle404Response struct {
|
||||
}
|
||||
|
||||
func (response UpdateUserTitle404Response) VisitUpdateUserTitleResponse(w http.ResponseWriter) error {
|
||||
w.WriteHeader(404)
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateUserTitle500Response struct {
|
||||
}
|
||||
|
||||
func (response UpdateUserTitle500Response) VisitUpdateUserTitleResponse(w http.ResponseWriter) error {
|
||||
w.WriteHeader(500)
|
||||
return nil
|
||||
}
|
||||
|
||||
type AddUserTitleRequestObject struct {
|
||||
UserId int64 `json:"user_id"`
|
||||
Body *AddUserTitleJSONRequestBody
|
||||
|
|
@ -1300,18 +1355,7 @@ type AddUserTitleResponseObject interface {
|
|||
VisitAddUserTitleResponse(w http.ResponseWriter) error
|
||||
}
|
||||
|
||||
type AddUserTitle200JSONResponse struct {
|
||||
Data *struct {
|
||||
Ctime *time.Time `json:"ctime,omitempty"`
|
||||
Rate *int32 `json:"rate,omitempty"`
|
||||
ReviewId *int64 `json:"review_id,omitempty"`
|
||||
|
||||
// Status User's title status
|
||||
Status UserTitleStatus `json:"status"`
|
||||
TitleId int64 `json:"title_id"`
|
||||
UserId int64 `json:"user_id"`
|
||||
} `json:"data,omitempty"`
|
||||
}
|
||||
type AddUserTitle200JSONResponse UserTitleMini
|
||||
|
||||
func (response AddUserTitle200JSONResponse) VisitAddUserTitleResponse(w http.ResponseWriter) error {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
|
@ -1382,9 +1426,15 @@ type StrictServerInterface interface {
|
|||
// Partially update a user account
|
||||
// (PATCH /users/{user_id})
|
||||
UpdateUser(ctx context.Context, request UpdateUserRequestObject) (UpdateUserResponseObject, error)
|
||||
// Delete a usertitle
|
||||
// (DELETE /users/{user_id}/titles)
|
||||
DeleteUserTitle(ctx context.Context, request DeleteUserTitleRequestObject) (DeleteUserTitleResponseObject, error)
|
||||
// Get user titles
|
||||
// (GET /users/{user_id}/titles)
|
||||
GetUsersUserIdTitles(ctx context.Context, request GetUsersUserIdTitlesRequestObject) (GetUsersUserIdTitlesResponseObject, error)
|
||||
// Update a usertitle
|
||||
// (PATCH /users/{user_id}/titles)
|
||||
UpdateUserTitle(ctx context.Context, request UpdateUserTitleRequestObject) (UpdateUserTitleResponseObject, error)
|
||||
// Add a title to a user
|
||||
// (POST /users/{user_id}/titles)
|
||||
AddUserTitle(ctx context.Context, request AddUserTitleRequestObject) (AddUserTitleResponseObject, error)
|
||||
|
|
@ -1520,6 +1570,33 @@ func (sh *strictHandler) UpdateUser(ctx *gin.Context, userId int64) {
|
|||
}
|
||||
}
|
||||
|
||||
// DeleteUserTitle operation middleware
|
||||
func (sh *strictHandler) DeleteUserTitle(ctx *gin.Context, userId int64) {
|
||||
var request DeleteUserTitleRequestObject
|
||||
|
||||
request.UserId = userId
|
||||
|
||||
handler := func(ctx *gin.Context, request interface{}) (interface{}, error) {
|
||||
return sh.ssi.DeleteUserTitle(ctx, request.(DeleteUserTitleRequestObject))
|
||||
}
|
||||
for _, middleware := range sh.middlewares {
|
||||
handler = middleware(handler, "DeleteUserTitle")
|
||||
}
|
||||
|
||||
response, err := handler(ctx, request)
|
||||
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
ctx.Status(http.StatusInternalServerError)
|
||||
} else if validResponse, ok := response.(DeleteUserTitleResponseObject); ok {
|
||||
if err := validResponse.VisitDeleteUserTitleResponse(ctx.Writer); err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
} else if response != nil {
|
||||
ctx.Error(fmt.Errorf("unexpected response type: %T", response))
|
||||
}
|
||||
}
|
||||
|
||||
// GetUsersUserIdTitles operation middleware
|
||||
func (sh *strictHandler) GetUsersUserIdTitles(ctx *gin.Context, userId string, params GetUsersUserIdTitlesParams) {
|
||||
var request GetUsersUserIdTitlesRequestObject
|
||||
|
|
@ -1548,6 +1625,41 @@ func (sh *strictHandler) GetUsersUserIdTitles(ctx *gin.Context, userId string, p
|
|||
}
|
||||
}
|
||||
|
||||
// UpdateUserTitle operation middleware
|
||||
func (sh *strictHandler) UpdateUserTitle(ctx *gin.Context, userId int64) {
|
||||
var request UpdateUserTitleRequestObject
|
||||
|
||||
request.UserId = userId
|
||||
|
||||
var body UpdateUserTitleJSONRequestBody
|
||||
if err := ctx.ShouldBindJSON(&body); err != nil {
|
||||
ctx.Status(http.StatusBadRequest)
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
request.Body = &body
|
||||
|
||||
handler := func(ctx *gin.Context, request interface{}) (interface{}, error) {
|
||||
return sh.ssi.UpdateUserTitle(ctx, request.(UpdateUserTitleRequestObject))
|
||||
}
|
||||
for _, middleware := range sh.middlewares {
|
||||
handler = middleware(handler, "UpdateUserTitle")
|
||||
}
|
||||
|
||||
response, err := handler(ctx, request)
|
||||
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
ctx.Status(http.StatusInternalServerError)
|
||||
} else if validResponse, ok := response.(UpdateUserTitleResponseObject); ok {
|
||||
if err := validResponse.VisitUpdateUserTitleResponse(ctx.Writer); err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
} else if response != nil {
|
||||
ctx.Error(fmt.Errorf("unexpected response type: %T", response))
|
||||
}
|
||||
}
|
||||
|
||||
// AddUserTitle operation middleware
|
||||
func (sh *strictHandler) AddUserTitle(ctx *gin.Context, userId int64) {
|
||||
var request AddUserTitleRequestObject
|
||||
|
|
|
|||
|
|
@ -21,4 +21,3 @@ components:
|
|||
$ref: "./parameters/_index.yaml"
|
||||
schemas:
|
||||
$ref: "./schemas/_index.yaml"
|
||||
|
||||
|
|
@ -108,27 +108,27 @@ post:
|
|||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '../schemas/UserTitle.yaml'
|
||||
type: object
|
||||
required:
|
||||
- title_id
|
||||
- status
|
||||
properties:
|
||||
title_id:
|
||||
type: integer
|
||||
format: int64
|
||||
status:
|
||||
$ref: '../schemas/enums/UserTitleStatus.yaml'
|
||||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
'200':
|
||||
description: Title successfully added to user
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
# success:
|
||||
# type: boolean
|
||||
# example: true
|
||||
# error:
|
||||
# type: string
|
||||
# nullable: true
|
||||
# example: null
|
||||
data:
|
||||
$ref: '../schemas/UserTitleMini.yaml'
|
||||
# required:
|
||||
# - success
|
||||
# - error
|
||||
$ref: '../schemas/UserTitleMini.yaml'
|
||||
|
||||
'400':
|
||||
description: Invalid request body (missing fields, invalid types, etc.)
|
||||
'401':
|
||||
|
|
@ -141,3 +141,81 @@ post:
|
|||
description: Conflict — title already assigned to user (if applicable)
|
||||
'500':
|
||||
description: Internal server error
|
||||
|
||||
patch:
|
||||
summary: Update a usertitle
|
||||
description: User updating title list of watched
|
||||
operationId: updateUserTitle
|
||||
parameters:
|
||||
- name: user_id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
description: ID of the user to assign the title to
|
||||
example: 123
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required:
|
||||
- title_id
|
||||
properties:
|
||||
title_id:
|
||||
type: integer
|
||||
format: int64
|
||||
status:
|
||||
$ref: '../schemas/enums/UserTitleStatus.yaml'
|
||||
rate:
|
||||
type: integer
|
||||
format: int32
|
||||
|
||||
responses:
|
||||
'200':
|
||||
description: Title successfully updated
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '../schemas/UserTitleMini.yaml'
|
||||
|
||||
'400':
|
||||
description: Invalid request body (missing fields, invalid types, etc.)
|
||||
'401':
|
||||
description: Unauthorized — missing or invalid auth token
|
||||
'403':
|
||||
description: Forbidden — user not allowed to update title
|
||||
'404':
|
||||
description: User or Title not found
|
||||
'500':
|
||||
description: Internal server error
|
||||
|
||||
delete:
|
||||
summary: Delete a usertitle
|
||||
description: User deleting title from list of watched
|
||||
operationId: deleteUserTitle
|
||||
parameters:
|
||||
- name: user_id
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
description: ID of the user to assign the title to
|
||||
example: 123
|
||||
|
||||
responses:
|
||||
'200':
|
||||
description: Title successfully deleted
|
||||
# '400':
|
||||
# description: Invalid request body (missing fields, invalid types, etc.)
|
||||
'401':
|
||||
description: Unauthorized — missing or invalid auth token
|
||||
'403':
|
||||
description: Forbidden — user not allowed to delete title
|
||||
'404':
|
||||
description: User or Title not found
|
||||
'500':
|
||||
description: Internal server error
|
||||
|
|
@ -20,4 +20,3 @@ properties:
|
|||
ctime:
|
||||
type: string
|
||||
format: date-time
|
||||
additionalProperties: true
|
||||
|
|
|
|||
|
|
@ -21,4 +21,3 @@ properties:
|
|||
ctime:
|
||||
type: string
|
||||
format: date-time
|
||||
additionalProperties: false
|
||||
|
|
|
|||
|
|
@ -116,9 +116,9 @@ type PostAuthSignInResponseObject interface {
|
|||
}
|
||||
|
||||
type PostAuthSignIn200JSONResponse struct {
|
||||
Error *string `json:"error"`
|
||||
Success *bool `json:"success,omitempty"`
|
||||
UserId *string `json:"user_id"`
|
||||
Error *string `json:"error"`
|
||||
UserId *string `json:"user_id"`
|
||||
UserName *string `json:"user_name"`
|
||||
}
|
||||
|
||||
func (response PostAuthSignIn200JSONResponse) VisitPostAuthSignInResponse(w http.ResponseWriter) error {
|
||||
|
|
|
|||
|
|
@ -59,29 +59,23 @@ paths:
|
|||
type: string
|
||||
format: password
|
||||
responses:
|
||||
# This one also sets two cookies: access_token and refresh_token
|
||||
"200":
|
||||
description: Sign-in result with JWT
|
||||
# headers:
|
||||
# Set-Cookie:
|
||||
# schema:
|
||||
# type: array
|
||||
# items:
|
||||
# type: string
|
||||
# explode: true
|
||||
# style: simple
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
success:
|
||||
type: boolean
|
||||
error:
|
||||
type: string
|
||||
nullable: true
|
||||
user_id:
|
||||
type: string
|
||||
nullable: true
|
||||
user_name:
|
||||
type: string
|
||||
nullable: true
|
||||
"401":
|
||||
description: Access denied due to invalid credentials
|
||||
content:
|
||||
|
|
|
|||
4
deploy/api_gen.ps1
Normal file
4
deploy/api_gen.ps1
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
cd ./api
|
||||
openapi-format .\openapi.yaml --output .\_build\openapi.yaml --yaml
|
||||
cd ..
|
||||
oapi-codegen --config=api\oapi-codegen.yaml api\_build\openapi.yaml
|
||||
|
|
@ -78,7 +78,6 @@ func (s Server) PostAuthSignIn(ctx context.Context, req auth.PostAuthSignInReque
|
|||
}
|
||||
|
||||
err := ""
|
||||
success := true
|
||||
|
||||
pass, ok := UserDb[req.Body.Nickname]
|
||||
if !ok || pass != req.Body.Pass {
|
||||
|
|
@ -96,9 +95,9 @@ func (s Server) PostAuthSignIn(ctx context.Context, req auth.PostAuthSignInReque
|
|||
|
||||
// Return access token; refresh token can be returned in response or HttpOnly cookie
|
||||
result := auth.PostAuthSignIn200JSONResponse{
|
||||
Error: &err,
|
||||
Success: &success,
|
||||
UserId: &req.Body.Nickname,
|
||||
Error: &err,
|
||||
UserId: &req.Body.Nickname,
|
||||
UserName: &req.Body.Nickname,
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,14 +101,14 @@ func sqlDate2oapi(p_date pgtype.Timestamptz) *time.Time {
|
|||
func sql2usertitlestatus(s sqlc.UsertitleStatusT) (oapi.UserTitleStatus, error) {
|
||||
var status oapi.UserTitleStatus
|
||||
|
||||
switch status {
|
||||
case "finished":
|
||||
switch s {
|
||||
case sqlc.UsertitleStatusTFinished:
|
||||
status = oapi.UserTitleStatusFinished
|
||||
case "dropped":
|
||||
case sqlc.UsertitleStatusTDropped:
|
||||
status = oapi.UserTitleStatusDropped
|
||||
case "planned":
|
||||
case sqlc.UsertitleStatusTPlanned:
|
||||
status = oapi.UserTitleStatusPlanned
|
||||
case "in-progress":
|
||||
case sqlc.UsertitleStatusTInProgress:
|
||||
status = oapi.UserTitleStatusInProgress
|
||||
default:
|
||||
return status, fmt.Errorf("unexpected tittle status: %s", s)
|
||||
|
|
@ -140,9 +140,9 @@ func UserTitleStatus2Sqlc(s *[]oapi.UserTitleStatus) ([]sqlc.UsertitleStatusT, e
|
|||
}
|
||||
|
||||
func UserTitleStatus2Sqlc1(s *oapi.UserTitleStatus) (*sqlc.UsertitleStatusT, error) {
|
||||
var sqlc_status sqlc.UsertitleStatusT
|
||||
var sqlc_status sqlc.UsertitleStatusT = sqlc.UsertitleStatusTFinished
|
||||
if s == nil {
|
||||
return nil, nil
|
||||
return &sqlc_status, nil
|
||||
}
|
||||
|
||||
switch *s {
|
||||
|
|
@ -304,7 +304,7 @@ func (s Server) GetUsersUserIdTitles(ctx context.Context, request oapi.GetUsersU
|
|||
tmp := fmt.Sprint(*t.Title.ReleaseYear)
|
||||
new_cursor.Param = &tmp
|
||||
case "rating":
|
||||
tmp := strconv.FormatFloat(*t.Title.Rating, 'f', -1, 64)
|
||||
tmp := strconv.FormatFloat(*t.Title.Rating, 'f', -1, 64) // падает
|
||||
new_cursor.Param = &tmp
|
||||
}
|
||||
}
|
||||
|
|
@ -360,7 +360,7 @@ func (s Server) UpdateUser(ctx context.Context, request oapi.UpdateUserRequestOb
|
|||
}
|
||||
|
||||
func (s Server) AddUserTitle(ctx context.Context, request oapi.AddUserTitleRequestObject) (oapi.AddUserTitleResponseObject, error) {
|
||||
|
||||
//TODO: add review if exists
|
||||
status, err := UserTitleStatus2Sqlc1(&request.Body.Status)
|
||||
if err != nil {
|
||||
log.Errorf("%v", err)
|
||||
|
|
@ -369,7 +369,7 @@ func (s Server) AddUserTitle(ctx context.Context, request oapi.AddUserTitleReque
|
|||
|
||||
params := sqlc.InsertUserTitleParams{
|
||||
UserID: request.UserId,
|
||||
TitleID: request.Body.Title.Id,
|
||||
TitleID: request.Body.TitleId,
|
||||
Status: *status,
|
||||
Rate: request.Body.Rate,
|
||||
ReviewID: request.Body.ReviewId,
|
||||
|
|
@ -404,5 +404,5 @@ func (s Server) AddUserTitle(ctx context.Context, request oapi.AddUserTitleReque
|
|||
UserId: user_title.UserID,
|
||||
}
|
||||
|
||||
return oapi.AddUserTitle200JSONResponse{Data: &oapi_usertitle}, nil
|
||||
return oapi.AddUserTitle200JSONResponse(oapi_usertitle), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,34 @@
|
|||
import React from "react";
|
||||
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
|
||||
import UserPage from "./pages/UserPage/UserPage";
|
||||
import UsersIdPage from "./pages/UsersIdPage/UsersIdPage";
|
||||
import TitlesPage from "./pages/TitlesPage/TitlesPage";
|
||||
import { LoginPage } from "./pages/LoginPage/LoginPage";
|
||||
import { Header } from "./components/Header/Header";
|
||||
|
||||
const App: React.FC = () => {
|
||||
const username = "nihonium";
|
||||
// Получаем username из localStorage
|
||||
const username = localStorage.getItem("username") || undefined;
|
||||
const userId = localStorage.getItem("userId");
|
||||
|
||||
return (
|
||||
<Router>
|
||||
<Header username={username} />
|
||||
<Routes>
|
||||
<Route path="/login" element={<LoginPage />} /> {/* <-- маршрут для логина */}
|
||||
<Route path="/signup" element={<LoginPage />} /> {/* <-- можно использовать тот же компонент для регистрации */}
|
||||
<Route path="/users/:id" element={<UserPage />} />
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<Route path="/signup" element={<LoginPage />} />
|
||||
|
||||
{/* /profile рендерит UsersIdPage с id из localStorage */}
|
||||
<Route
|
||||
path="/profile"
|
||||
element={userId ? <UsersIdPage userId={userId} /> : <LoginPage />}
|
||||
/>
|
||||
|
||||
<Route path="/users/:id" element={<UsersIdPage />} />
|
||||
<Route path="/titles" element={<TitlesPage />} />
|
||||
</Routes>
|
||||
</Router>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
export default App;
|
||||
|
|
@ -20,7 +20,7 @@ export type OpenAPIConfig = {
|
|||
};
|
||||
|
||||
export const OpenAPI: OpenAPIConfig = {
|
||||
BASE: 'http://10.1.0.65:8081/api/v1',
|
||||
BASE: '/api/v1',
|
||||
VERSION: '1.0.0',
|
||||
WITH_CREDENTIALS: false,
|
||||
CREDENTIALS: 'include',
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@
|
|||
/* eslint-disable */
|
||||
export type Image = {
|
||||
id?: number;
|
||||
storage_type?: string;
|
||||
/**
|
||||
* Image storage type
|
||||
*/
|
||||
storage_type?: 's3' | 'local';
|
||||
image_path?: string;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,15 +2,13 @@
|
|||
/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import type { Image } from './Image';
|
||||
export type User = {
|
||||
/**
|
||||
* Unique user ID (primary key)
|
||||
*/
|
||||
id?: number;
|
||||
/**
|
||||
* ID of the user avatar (references images table)
|
||||
*/
|
||||
avatar_id?: number;
|
||||
image?: Image;
|
||||
/**
|
||||
* User email
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -2,4 +2,14 @@
|
|||
/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
export type UserTitle = Record<string, any>;
|
||||
import type { Title } from './Title';
|
||||
import type { UserTitleStatus } from './UserTitleStatus';
|
||||
export type UserTitle = {
|
||||
user_id: number;
|
||||
title?: Title;
|
||||
status: UserTitleStatus;
|
||||
rate?: number;
|
||||
review_id?: number;
|
||||
ctime?: string;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export class DefaultService {
|
|||
* @param sort
|
||||
* @param sortForward
|
||||
* @param word
|
||||
* @param status
|
||||
* @param status List of title statuses to filter
|
||||
* @param rating
|
||||
* @param releaseYear
|
||||
* @param releaseSeason
|
||||
|
|
@ -35,7 +35,7 @@ export class DefaultService {
|
|||
sort?: TitleSort,
|
||||
sortForward: boolean = true,
|
||||
word?: string,
|
||||
status?: TitleStatus,
|
||||
status?: Array<TitleStatus>,
|
||||
rating?: number,
|
||||
releaseYear?: number,
|
||||
releaseSeason?: ReleaseSeason,
|
||||
|
|
@ -125,45 +125,112 @@ export class DefaultService {
|
|||
},
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Partially update a user account
|
||||
* Update selected user profile fields (excluding password).
|
||||
* Password updates must be done via the dedicated auth-service (`/auth/`).
|
||||
* Fields not provided in the request body remain unchanged.
|
||||
*
|
||||
* @param userId User ID (primary key)
|
||||
* @param requestBody
|
||||
* @returns User User updated successfully. Returns updated user representation (excluding sensitive fields).
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static updateUser(
|
||||
userId: number,
|
||||
requestBody: {
|
||||
/**
|
||||
* ID of the user avatar (references `images.id`); set to `null` to remove avatar
|
||||
*/
|
||||
avatar_id?: number | null;
|
||||
/**
|
||||
* User email (must be unique and valid)
|
||||
*/
|
||||
mail?: string;
|
||||
/**
|
||||
* Username (alphanumeric + `_` or `-`, 3–16 chars)
|
||||
*/
|
||||
nickname?: string;
|
||||
/**
|
||||
* Display name
|
||||
*/
|
||||
disp_name?: string;
|
||||
/**
|
||||
* User description / bio
|
||||
*/
|
||||
user_desc?: string;
|
||||
},
|
||||
): CancelablePromise<User> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'PATCH',
|
||||
url: '/users/{user_id}',
|
||||
path: {
|
||||
'user_id': userId,
|
||||
},
|
||||
body: requestBody,
|
||||
mediaType: 'application/json',
|
||||
errors: {
|
||||
400: `Invalid input (e.g., validation failed, nickname/email conflict, malformed JSON)`,
|
||||
401: `Unauthorized — missing or invalid authentication token`,
|
||||
403: `Forbidden — user is not allowed to modify this resource (e.g., not own profile & no admin rights)`,
|
||||
404: `User not found`,
|
||||
409: `Conflict — e.g., requested \`nickname\` or \`mail\` already taken by another user`,
|
||||
422: `Unprocessable Entity — semantic errors not caught by schema (e.g., invalid \`avatar_id\`)`,
|
||||
500: `Unknown server error`,
|
||||
},
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Get user titles
|
||||
* @param userId
|
||||
* @param cursor
|
||||
* @param sort
|
||||
* @param sortForward
|
||||
* @param word
|
||||
* @param status
|
||||
* @param status List of title statuses to filter
|
||||
* @param watchStatus
|
||||
* @param rating
|
||||
* @param myRate
|
||||
* @param releaseYear
|
||||
* @param releaseSeason
|
||||
* @param limit
|
||||
* @param fields
|
||||
* @returns UserTitle List of user titles
|
||||
* @returns any List of user titles
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static getUsersTitles(
|
||||
userId: string,
|
||||
cursor?: string,
|
||||
sort?: TitleSort,
|
||||
sortForward: boolean = true,
|
||||
word?: string,
|
||||
status?: TitleStatus,
|
||||
watchStatus?: UserTitleStatus,
|
||||
status?: Array<TitleStatus>,
|
||||
watchStatus?: Array<UserTitleStatus>,
|
||||
rating?: number,
|
||||
myRate?: number,
|
||||
releaseYear?: number,
|
||||
releaseSeason?: ReleaseSeason,
|
||||
limit: number = 10,
|
||||
fields: string = 'all',
|
||||
): CancelablePromise<Array<UserTitle>> {
|
||||
): CancelablePromise<{
|
||||
data: Array<UserTitle>;
|
||||
cursor: CursorObj;
|
||||
}> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'GET',
|
||||
url: '/users/{user_id}/titles/',
|
||||
url: '/users/{user_id}/titles',
|
||||
path: {
|
||||
'user_id': userId,
|
||||
},
|
||||
query: {
|
||||
'cursor': cursor,
|
||||
'sort': sort,
|
||||
'sort_forward': sortForward,
|
||||
'word': word,
|
||||
'status': status,
|
||||
'watch_status': watchStatus,
|
||||
'rating': rating,
|
||||
'my_rate': myRate,
|
||||
'release_year': releaseYear,
|
||||
'release_season': releaseSeason,
|
||||
'limit': limit,
|
||||
|
|
@ -171,8 +238,48 @@ export class DefaultService {
|
|||
},
|
||||
errors: {
|
||||
400: `Request params are not correct`,
|
||||
404: `User not found`,
|
||||
500: `Unknown server error`,
|
||||
},
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Add a title to a user
|
||||
* User adding title to list af watched, status required
|
||||
* @param userId ID of the user to assign the title to
|
||||
* @param requestBody
|
||||
* @returns any Title successfully added to user
|
||||
* @throws ApiError
|
||||
*/
|
||||
public static addUserTitle(
|
||||
userId: number,
|
||||
requestBody: UserTitle,
|
||||
): CancelablePromise<{
|
||||
data?: {
|
||||
user_id: number;
|
||||
title_id: number;
|
||||
status: UserTitleStatus;
|
||||
rate?: number;
|
||||
review_id?: number;
|
||||
ctime?: string;
|
||||
};
|
||||
}> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'POST',
|
||||
url: '/users/{user_id}/titles',
|
||||
path: {
|
||||
'user_id': userId,
|
||||
},
|
||||
body: requestBody,
|
||||
mediaType: 'application/json',
|
||||
errors: {
|
||||
400: `Invalid request body (missing fields, invalid types, etc.)`,
|
||||
401: `Unauthorized — missing or invalid auth token`,
|
||||
403: `Forbidden — user not allowed to assign titles to this user`,
|
||||
404: `User or Title not found`,
|
||||
409: `Conflict — title already assigned to user (if applicable)`,
|
||||
500: `Internal server error`,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ export class AuthService {
|
|||
pass: string;
|
||||
},
|
||||
): CancelablePromise<{
|
||||
success?: boolean;
|
||||
error?: string | null;
|
||||
user_id?: string | null;
|
||||
user_name?: string | null;
|
||||
}> {
|
||||
return __request(OpenAPI, {
|
||||
method: 'POST',
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export const Header: React.FC<HeaderProps> = ({ username }) => {
|
|||
const toggleMenu = () => setMenuOpen(!menuOpen);
|
||||
|
||||
return (
|
||||
<header className="w-full bg-white shadow-md fixed top-0 left-0 z-50">
|
||||
<header className="w-full bg-white shadow-md sticky top-0 left-0 z-50">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div className="flex justify-between h-16 items-center">
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
import type { UserTitle } from "../../api";
|
||||
|
||||
export function UserTitleCardHorizontal({ title }: { title: UserTitle }) {
|
||||
return (
|
||||
<div style={{
|
||||
display: "flex",
|
||||
gap: 12,
|
||||
padding: 12,
|
||||
border: "1px solid #ddd",
|
||||
borderRadius: 8
|
||||
}}>
|
||||
{title.title?.poster?.image_path && (
|
||||
<img src={title.title?.poster.image_path} width={80} />
|
||||
)}
|
||||
<div>
|
||||
<h3>{title.title?.title_names["en"]}</h3>
|
||||
<p>{title.title?.release_year} · {title.title?.release_season} · Rating: {title.title?.rating}</p>
|
||||
<p>Status: {title.title?.title_status}</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import type { UserTitle } from "../../api";
|
||||
|
||||
export function UserTitleCardSquare({ title }: { title: UserTitle }) {
|
||||
return (
|
||||
<div style={{
|
||||
width: 160,
|
||||
border: "1px solid #ddd",
|
||||
padding: 8,
|
||||
borderRadius: 8,
|
||||
textAlign: "center"
|
||||
}}>
|
||||
{title.title?.poster?.image_path && (
|
||||
<img src={title.title?.poster.image_path} width={140} />
|
||||
)}
|
||||
<div>
|
||||
<h4>{title.title?.title_names["en"]}</h4>
|
||||
<h5>{title.status}</h5>
|
||||
<small>{title.title?.release_year} • {title.title?.rating}</small>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -18,17 +18,19 @@ export const LoginPage: React.FC = () => {
|
|||
try {
|
||||
if (isLogin) {
|
||||
const res = await AuthService.postAuthSignIn({ nickname, pass: password });
|
||||
if (res.success) {
|
||||
// TODO: сохранить JWT в localStorage/cookie
|
||||
console.log("Logged in user id:", res.user_id);
|
||||
navigate("/"); // редирект после успешного входа
|
||||
if (res.user_id && res.user_name) {
|
||||
// Сохраняем user_id и username в localStorage
|
||||
localStorage.setItem("userId", res.user_id);
|
||||
localStorage.setItem("username", res.user_name);
|
||||
|
||||
navigate("/profile"); // редирект на профиль
|
||||
} else {
|
||||
setError(res.error || "Login failed");
|
||||
}
|
||||
} else {
|
||||
// SignUp оставляем без сохранения данных
|
||||
const res = await AuthService.postAuthSignUp({ nickname, pass: password });
|
||||
if (res.success) {
|
||||
console.log("User signed up with id:", res.user_id);
|
||||
if (res.user_id) {
|
||||
setIsLogin(true); // переключаемся на login после регистрации
|
||||
} else {
|
||||
setError(res.error || "Sign up failed");
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ const UserPage: React.FC = () => {
|
|||
<div className={styles.container}>
|
||||
<div className={styles.header}>
|
||||
<div className={styles.avatarWrapper}>
|
||||
{user.avatar_id ? (
|
||||
{user.image?.image_path ? (
|
||||
<img
|
||||
src={`/images/${user.avatar_id}.png`}
|
||||
src={`/images/${user.image.image_path}.png`}
|
||||
alt="User Avatar"
|
||||
className={styles.avatarImg}
|
||||
/>
|
||||
|
|
|
|||
183
modules/frontend/src/pages/UsersIdPage/UsersIdPage.tsx
Normal file
183
modules/frontend/src/pages/UsersIdPage/UsersIdPage.tsx
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
// pages/UserPage/UserPage.tsx
|
||||
import { useEffect, useState } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { DefaultService } from "../../api/services/DefaultService";
|
||||
import { SearchBar } from "../../components/SearchBar/SearchBar";
|
||||
import { TitlesSortBox } from "../../components/TitlesSortBox/TitlesSortBox";
|
||||
import { LayoutSwitch } from "../../components/LayoutSwitch/LayoutSwitch";
|
||||
import { ListView } from "../../components/ListView/ListView";
|
||||
import { UserTitleCardSquare } from "../../components/cards/UserTitleCardSquare";
|
||||
import { UserTitleCardHorizontal } from "../../components/cards/UserTitleCardHorizontal";
|
||||
import type { User, UserTitle, CursorObj, TitleSort } from "../../api";
|
||||
|
||||
const PAGE_SIZE = 10;
|
||||
|
||||
type UsersIdPageProps = {
|
||||
userId?: string;
|
||||
};
|
||||
|
||||
export default function UsersIdPage({ userId }: UsersIdPageProps) {
|
||||
const params = useParams();
|
||||
const id = userId || params?.id;
|
||||
|
||||
const [user, setUser] = useState<User | null>(null);
|
||||
const [loadingUser, setLoadingUser] = useState(true);
|
||||
const [errorUser, setErrorUser] = useState<string | null>(null);
|
||||
|
||||
// Для списка тайтлов
|
||||
const [titles, setTitles] = useState<UserTitle[]>([]);
|
||||
const [nextPage, setNextPage] = useState<UserTitle[]>([]);
|
||||
const [cursor, setCursor] = useState<CursorObj | null>(null);
|
||||
const [loadingTitles, setLoadingTitles] = useState(true);
|
||||
const [loadingMore, setLoadingMore] = useState(false);
|
||||
const [search, setSearch] = useState("");
|
||||
const [sort, setSort] = useState<TitleSort>("id");
|
||||
const [sortForward, setSortForward] = useState(true);
|
||||
const [layout, setLayout] = useState<"square" | "horizontal">("square");
|
||||
|
||||
// --- Получение данных пользователя ---
|
||||
useEffect(() => {
|
||||
const fetchUser = async () => {
|
||||
if (!id) return;
|
||||
setLoadingUser(true);
|
||||
try {
|
||||
const result = await DefaultService.getUsers(id, "all");
|
||||
setUser(result);
|
||||
setErrorUser(null);
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
setErrorUser(err?.message || "Failed to fetch user data");
|
||||
} finally {
|
||||
setLoadingUser(false);
|
||||
}
|
||||
};
|
||||
fetchUser();
|
||||
}, [id]);
|
||||
|
||||
// --- Получение списка тайтлов пользователя ---
|
||||
const fetchPage = async (cursorObj: CursorObj | null) => {
|
||||
if (!id) return { items: [], nextCursor: null };
|
||||
const cursorStr = cursorObj
|
||||
? btoa(JSON.stringify(cursorObj)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")
|
||||
: "";
|
||||
|
||||
try {
|
||||
const result = await DefaultService.getUsersTitles(
|
||||
id,
|
||||
cursorStr,
|
||||
sort,
|
||||
sortForward,
|
||||
search.trim() || undefined,
|
||||
undefined, // status фильтр, можно добавить
|
||||
undefined, // watchStatus
|
||||
undefined, // rating
|
||||
undefined, // myRate
|
||||
undefined, // releaseYear
|
||||
undefined, // releaseSeason
|
||||
PAGE_SIZE,
|
||||
"all"
|
||||
);
|
||||
|
||||
if (!result?.data?.length) return { items: [], nextCursor: null };
|
||||
|
||||
return { items: result.data, nextCursor: result.cursor ?? null };
|
||||
} catch (err: any) {
|
||||
if (err.status === 204) return { items: [], nextCursor: null };
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
// Инициализация: загружаем сразу две страницы
|
||||
useEffect(() => {
|
||||
const initLoad = async () => {
|
||||
setLoadingTitles(true);
|
||||
setTitles([]);
|
||||
setNextPage([]);
|
||||
setCursor(null);
|
||||
|
||||
const firstPage = await fetchPage(null);
|
||||
const secondPage = firstPage.nextCursor ? await fetchPage(firstPage.nextCursor) : { items: [], nextCursor: null };
|
||||
|
||||
setTitles(firstPage.items);
|
||||
setNextPage(secondPage.items);
|
||||
setCursor(secondPage.nextCursor);
|
||||
setLoadingTitles(false);
|
||||
};
|
||||
initLoad();
|
||||
}, [id, search, sort, sortForward]);
|
||||
|
||||
const handleLoadMore = async () => {
|
||||
if (nextPage.length === 0) {
|
||||
setLoadingMore(false);
|
||||
return;
|
||||
}
|
||||
setLoadingMore(true);
|
||||
|
||||
setTitles(prev => [...prev, ...nextPage]);
|
||||
setNextPage([]);
|
||||
|
||||
if (cursor) {
|
||||
try {
|
||||
const next = await fetchPage(cursor);
|
||||
if (next.items.length > 0) setNextPage(next.items);
|
||||
setCursor(next.nextCursor);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
setLoadingMore(false);
|
||||
};
|
||||
|
||||
// const getAvatarUrl = (avatarId?: number) => (avatarId ? `/api/images/${avatarId}` : "/default-avatar.png");
|
||||
|
||||
return (
|
||||
<div className="w-full min-h-screen bg-gray-50 p-6 flex flex-col items-center">
|
||||
|
||||
{/* --- Карточка пользователя --- */}
|
||||
{loadingUser && <div className="mt-10 text-xl font-medium">Loading user...</div>}
|
||||
{errorUser && <div className="mt-10 text-red-600 font-medium">{errorUser}</div>}
|
||||
{user && (
|
||||
<div className="bg-white shadow-lg rounded-xl p-6 w-full max-w-sm flex flex-col items-center mb-8">
|
||||
<img src={user.image?.image_path} alt={user.nickname} className="w-32 h-32 rounded-full object-cover mb-4" />
|
||||
<h2 className="text-2xl font-bold mb-2">{user.disp_name || user.nickname}</h2>
|
||||
{user.mail && <p className="text-gray-600 mb-2">{user.mail}</p>}
|
||||
{user.user_desc && <p className="text-gray-700 text-center">{user.user_desc}</p>}
|
||||
{user.creation_date && <p className="text-gray-400 mt-4 text-sm">Registered: {new Date(user.creation_date).toLocaleDateString()}</p>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* --- Панель поиска, сортировки и лейаута --- */}
|
||||
<div className="w-full sm:w-4/5 flex flex-col sm:flex-row gap-4 mb-6 items-center">
|
||||
<SearchBar placeholder="Search titles..." search={search} setSearch={setSearch} />
|
||||
<LayoutSwitch layout={layout} setLayout={setLayout} />
|
||||
<TitlesSortBox sort={sort} setSort={setSort} sortForward={sortForward} setSortForward={setSortForward} />
|
||||
</div>
|
||||
|
||||
{/* --- Список тайтлов --- */}
|
||||
{loadingTitles && <div className="mt-6 font-medium text-black">Loading titles...</div>}
|
||||
{!loadingTitles && titles.length === 0 && <div className="mt-6 font-medium text-black">No titles found.</div>}
|
||||
|
||||
{titles.length > 0 && (
|
||||
<>
|
||||
<ListView<UserTitle>
|
||||
items={titles}
|
||||
layout={layout}
|
||||
hasMore={!!cursor || nextPage.length > 1}
|
||||
loadingMore={loadingMore}
|
||||
onLoadMore={handleLoadMore}
|
||||
renderItem={(title, layout) =>
|
||||
layout === "square" ? <UserTitleCardSquare title={title} /> : <UserTitleCardHorizontal title={title} />
|
||||
}
|
||||
/>
|
||||
|
||||
{!cursor && nextPage.length === 0 && (
|
||||
<div className="mt-6 font-medium text-black">
|
||||
Результатов больше нет, было найдено {titles.length} тайтлов.
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue