Compare commits

...

10 commits

Author SHA1 Message Date
e0a68d7d0f feat: delete usertitle described 2025-11-27 05:48:13 +03:00
cb9fba6fbc feat: patch usertitle described
All checks were successful
Build and Deploy Go App / build (push) Successful in 5m48s
Build and Deploy Go App / deploy (push) Successful in 29s
2025-11-27 03:46:40 +03:00
759679990a Merge branch 'dev' of ssh://meowgit.nekoea.red:22222/nihonium/nyanimedb into dev
All checks were successful
Build and Deploy Go App / build (push) Successful in 5m44s
Build and Deploy Go App / deploy (push) Successful in 26s
2025-11-27 03:20:43 +03:00
65b76d58c3 fix: now post usertitle dont need title body 2025-11-27 03:19:53 +03:00
51bf7b6f7e
fix: UserTitle cards
All checks were successful
Build and Deploy Go App / build (push) Successful in 5m28s
Build and Deploy Go App / deploy (push) Successful in 26s
2025-11-25 05:36:57 +03:00
9139c77c5f Merge branch 'dev-ars' into dev
All checks were successful
Build and Deploy Go App / build (push) Successful in 5m36s
Build and Deploy Go App / deploy (push) Successful in 24s
2025-11-25 04:57:16 +03:00
b8bfe01ef5 fix: usertitles status mapping 2025-11-25 04:57:07 +03:00
0cda597001 Merge branch 'dev-ars' into dev
All checks were successful
Build and Deploy Go App / build (push) Successful in 5m20s
Build and Deploy Go App / deploy (push) Successful in 26s
2025-11-25 04:43:57 +03:00
354c577f7d
feat: reworked user and login page
Some checks failed
Build and Deploy Go App / build (push) Has been cancelled
Build and Deploy Go App / deploy (push) Has been cancelled
2025-11-25 04:38:36 +03:00
87eb6a6b12
feat: signup return username 2025-11-25 04:38:35 +03:00
24 changed files with 1061 additions and 437 deletions

View file

@ -11,52 +11,52 @@ paths:
parameters: parameters:
- $ref: '#/components/parameters/cursor' - $ref: '#/components/parameters/cursor'
- $ref: '#/components/parameters/title_sort' - $ref: '#/components/parameters/title_sort'
- in: query - name: sort_forward
name: sort_forward in: query
schema: schema:
type: boolean type: boolean
default: true default: true
- in: query - name: word
name: word in: query
schema: schema:
type: string type: string
- in: query - name: status
name: status in: query
description: List of title statuses to filter
schema: schema:
type: array type: array
items: items:
$ref: '#/components/schemas/TitleStatus' $ref: '#/components/schemas/TitleStatus'
description: List of title statuses to filter
style: form
explode: false explode: false
- in: query style: form
name: rating - name: rating
in: query
schema: schema:
type: number type: number
format: double format: double
- in: query - name: release_year
name: release_year in: query
schema: schema:
type: integer type: integer
format: int32 format: int32
- in: query - name: release_season
name: release_season in: query
schema: schema:
$ref: '#/components/schemas/ReleaseSeason' $ref: '#/components/schemas/ReleaseSeason'
- in: query - name: limit
name: limit in: query
schema: schema:
type: integer type: integer
format: int32 format: int32
default: 10 default: 10
- in: query - name: offset
name: offset in: query
schema: schema:
type: integer type: integer
format: int32 format: int32
default: 0 default: 0
- in: query - name: fields
name: fields in: query
schema: schema:
type: string type: string
default: all default: all
@ -69,10 +69,10 @@ paths:
type: object type: object
properties: properties:
data: data:
description: List of titles
type: array type: array
items: items:
$ref: '#/components/schemas/Title' $ref: '#/components/schemas/Title'
description: List of titles
cursor: cursor:
$ref: '#/components/schemas/CursorObj' $ref: '#/components/schemas/CursorObj'
required: required:
@ -88,14 +88,14 @@ paths:
get: get:
summary: Get title description summary: Get title description
parameters: parameters:
- in: path - name: title_id
name: title_id in: path
required: true required: true
schema: schema:
type: integer type: integer
format: int64 format: int64
- in: query - name: fields
name: fields in: query
schema: schema:
type: string type: string
default: all default: all
@ -118,13 +118,13 @@ paths:
get: get:
summary: Get user info summary: Get user info
parameters: parameters:
- in: path - name: user_id
name: user_id in: path
required: true required: true
schema: schema:
type: string type: string
- in: query - name: fields
name: fields in: query
schema: schema:
type: string type: string
default: all default: all
@ -142,59 +142,59 @@ paths:
'500': '500':
description: Unknown server error description: Unknown server error
patch: patch:
operationId: updateUser
summary: Partially update a user account summary: Partially update a user account
description: | description: |
Update selected user profile fields (excluding password). Update selected user profile fields (excluding password).
Password updates must be done via the dedicated auth-service (`/auth/`). Password updates must be done via the dedicated auth-service (`/auth/`).
Fields not provided in the request body remain unchanged. Fields not provided in the request body remain unchanged.
operationId: updateUser
parameters: parameters:
- name: user_id - name: user_id
in: path in: path
description: User ID (primary key)
required: true required: true
schema: schema:
type: integer type: integer
format: int64 format: int64
description: User ID (primary key)
example: 123 example: 123
requestBody: requestBody:
required: true required: true
content: content:
application/json: application/json:
schema: schema:
description: Only provided fields are updated. Omitted fields remain unchanged.
type: object type: object
properties: properties:
avatar_id: avatar_id:
description: ID of the user avatar (references `images.id`); set to `null` to remove avatar
type: integer type: integer
format: int64 format: int64
nullable: true
description: ID of the user avatar (references `images.id`); set to `null` to remove avatar
example: 42 example: 42
nullable: true
mail: mail:
description: User email (must be unique and valid)
type: string type: string
format: email 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 example: john.doe.updated@example.com
pattern: '^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+$'
nickname: nickname:
type: string
pattern: '^[a-zA-Z0-9_-]{3,16}$'
description: 'Username (alphanumeric + `_` or `-`, 316 chars)' description: 'Username (alphanumeric + `_` or `-`, 316 chars)'
type: string
example: john_doe_43
maxLength: 16 maxLength: 16
minLength: 3 minLength: 3
example: john_doe_43 pattern: '^[a-zA-Z0-9_-]{3,16}$'
disp_name: disp_name:
type: string
description: Display name description: Display name
maxLength: 32
example: John Smith
user_desc:
type: string type: string
example: John Smith
maxLength: 32
user_desc:
description: User description / bio description: User description / bio
maxLength: 512 type: string
example: Just a curious developer. example: Just a curious developer.
maxLength: 512
additionalProperties: false additionalProperties: false
description: Only provided fields are updated. Omitted fields remain unchanged.
responses: responses:
'200': '200':
description: User updated successfully. Returns updated user representation (excluding sensitive fields). description: User updated successfully. Returns updated user representation (excluding sensitive fields).
@ -222,64 +222,64 @@ paths:
parameters: parameters:
- $ref: '#/components/parameters/cursor' - $ref: '#/components/parameters/cursor'
- $ref: '#/components/parameters/title_sort' - $ref: '#/components/parameters/title_sort'
- in: path - name: user_id
name: user_id in: path
required: true required: true
schema: schema:
type: string type: string
- in: query - name: sort_forward
name: sort_forward in: query
schema: schema:
type: boolean type: boolean
default: true default: true
- in: query - name: word
name: word in: query
schema: schema:
type: string type: string
- in: query - name: status
name: status in: query
description: List of title statuses to filter
schema: schema:
type: array type: array
items: items:
$ref: '#/components/schemas/TitleStatus' $ref: '#/components/schemas/TitleStatus'
description: List of title statuses to filter
style: form
explode: false explode: false
- in: query style: form
name: watch_status - name: watch_status
in: query
schema: schema:
type: array type: array
items: items:
$ref: '#/components/schemas/UserTitleStatus' $ref: '#/components/schemas/UserTitleStatus'
style: form
explode: false explode: false
- in: query style: form
name: rating - name: rating
in: query
schema: schema:
type: number type: number
format: double format: double
- in: query - name: my_rate
name: my_rate in: query
schema: schema:
type: integer type: integer
format: int32 format: int32
- in: query - name: release_year
name: release_year in: query
schema: schema:
type: integer type: integer
format: int32 format: int32
- in: query - name: release_season
name: release_season in: query
schema: schema:
$ref: '#/components/schemas/ReleaseSeason' $ref: '#/components/schemas/ReleaseSeason'
- in: query - name: limit
name: limit in: query
schema: schema:
type: integer type: integer
format: int32 format: int32
default: 10 default: 10
- in: query - name: fields
name: fields in: query
schema: schema:
type: string type: string
default: all default: all
@ -309,42 +309,25 @@ paths:
'500': '500':
description: Unknown server error description: Unknown server error
post: post:
operationId: addUserTitle
summary: Add a title to a user summary: Add a title to a user
description: 'User adding title to list af watched, status required' description: 'User adding title to list af watched, status required'
operationId: addUserTitle
parameters: parameters:
- name: user_id - name: user_id
in: path in: path
description: ID of the user to assign the title to
required: true required: true
schema: schema:
type: integer type: integer
format: int64 format: int64
description: ID of the user to assign the title to
example: 123 example: 123
requestBody: requestBody:
required: true required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UserTitle'
responses:
'200':
description: Title successfully added to user
content: content:
application/json: application/json:
schema: schema:
type: object type: object
properties: properties:
data:
type: object
required:
- user_id
- title_id
- status
properties:
user_id:
type: integer
format: int64
title_id: title_id:
type: integer type: integer
format: int64 format: int64
@ -353,13 +336,16 @@ paths:
rate: rate:
type: integer type: integer
format: int32 format: int32
review_id: required:
type: integer - title_id
format: int64 - status
ctime: responses:
type: string '200':
format: date-time description: Title successfully added to user
additionalProperties: false content:
application/json:
schema:
$ref: '#/components/schemas/UserTitleMini'
'400': '400':
description: 'Invalid request body (missing fields, invalid types, etc.)' description: 'Invalid request body (missing fields, invalid types, etc.)'
'401': '401':
@ -372,6 +358,77 @@ paths:
description: Conflict — title already assigned to user (if applicable) description: Conflict — title already assigned to user (if applicable)
'500': '500':
description: Internal server error 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: components:
parameters: parameters:
cursor: cursor:
@ -387,25 +444,36 @@ components:
schema: schema:
$ref: '#/components/schemas/TitleSort' $ref: '#/components/schemas/TitleSort'
schemas: schemas:
CursorObj:
type: object
required:
- id
properties:
id:
type: integer
format: int64
param:
type: string
TitleSort: TitleSort:
type: string
description: Title sort order description: Title sort order
type: string
default: id default: id
enum: enum:
- id - id
- year - year
- rating - rating
- views - 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: Image:
type: object type: object
properties: properties:
@ -413,65 +481,11 @@ components:
type: integer type: integer
format: int64 format: int64
storage_type: storage_type:
type: string $ref: '#/components/schemas/StorageType'
description: Image storage type
enum:
- s3
- local
image_path: image_path:
type: string 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: Studio:
type: object type: object
required:
- id
- name
properties: properties:
id: id:
type: integer type: integer
@ -482,30 +496,41 @@ components:
$ref: '#/components/schemas/Image' $ref: '#/components/schemas/Image'
description: description:
type: string type: string
Title:
type: object
required: required:
- id - id
- title_names - name
- tags Tag:
properties: description: 'A localized tag: keys are language codes (ISO 639-1), values are tag names'
id:
type: integer
format: int64
description: Unique title ID (primary key)
example: 1
title_names:
type: object type: object
description: 'Localized titles. Key = language (ISO 639-1), value = list of names' example:
en: Shojo
ru: Сёдзё
ja: 少女
additionalProperties: additionalProperties:
type: string
Tags:
description: Array of localized tags
type: array type: array
items: items:
type: string $ref: '#/components/schemas/Tag'
example: Attack on Titan
minItems: 1
example: example:
- Attack on Titan - en: Shojo
- AoT ru: Сёдзё
ja: 少女
- en: Shounen
ru: Сёнен
ja: 少年
Title:
type: object
properties:
id:
description: Unique title ID (primary key)
type: integer
format: int64
example: 1
title_names:
description: 'Localized titles. Key = language (ISO 639-1), value = list of names'
type: object
example: example:
en: en:
- Attack on Titan - Attack on Titan
@ -515,6 +540,15 @@ components:
- Титаны - Титаны
ja: ja:
- 進撃の巨人 - 進撃の巨人
additionalProperties:
type: array
items:
type: string
example: Attack on Titan
minItems: 1
example:
- Attack on Titan
- AoT
studio: studio:
$ref: '#/components/schemas/Studio' $ref: '#/components/schemas/Studio'
tags: tags:
@ -546,50 +580,68 @@ components:
type: number type: number
format: double format: double
additionalProperties: true additionalProperties: true
User: required:
- id
- title_names
- tags
CursorObj:
type: object type: object
properties: properties:
id: id:
type: integer type: integer
format: int64 format: int64
param:
type: string
required:
- id
User:
type: object
properties:
id:
description: Unique user ID (primary key) description: Unique user ID (primary key)
type: integer
format: int64
example: 1 example: 1
image: image:
$ref: '#/components/schemas/Image' $ref: '#/components/schemas/Image'
mail: mail:
description: User email
type: string type: string
format: email format: email
description: User email
example: john.doe@example.com example: john.doe@example.com
nickname: nickname:
type: string
description: Username (alphanumeric + _ or -) description: Username (alphanumeric + _ or -)
maxLength: 16 type: string
example: john_doe_42 example: john_doe_42
maxLength: 16
disp_name: disp_name:
type: string
description: Display name description: Display name
maxLength: 32
example: John Doe
user_desc:
type: string type: string
example: John Doe
maxLength: 32
user_desc:
description: User description description: User description
maxLength: 512 type: string
example: Just a regular user. example: Just a regular user.
maxLength: 512
creation_date: creation_date:
description: Timestamp when the user was created
type: string type: string
format: date-time format: date-time
description: Timestamp when the user was created
example: '2025-10-10T23:45:47.908073Z' example: '2025-10-10T23:45:47.908073Z'
required: required:
- user_id - user_id
- nickname - nickname
UserTitleStatus:
description: User's title status
type: string
enum:
- finished
- planned
- dropped
- in-progress
UserTitle: UserTitle:
type: object type: object
required:
- user_id
- title_id
- status
properties: properties:
user_id: user_id:
type: integer type: integer
@ -607,4 +659,34 @@ components:
ctime: ctime:
type: string type: string
format: date-time 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 additionalProperties: true

View file

@ -16,12 +16,6 @@ import (
openapi_types "github.com/oapi-codegen/runtime/types" openapi_types "github.com/oapi-codegen/runtime/types"
) )
// Defines values for ImageStorageType.
const (
Local ImageStorageType = "local"
S3 ImageStorageType = "s3"
)
// Defines values for ReleaseSeason. // Defines values for ReleaseSeason.
const ( const (
Fall ReleaseSeason = "fall" Fall ReleaseSeason = "fall"
@ -30,6 +24,12 @@ const (
Winter ReleaseSeason = "winter" Winter ReleaseSeason = "winter"
) )
// Defines values for StorageType.
const (
Local StorageType = "local"
S3 StorageType = "s3"
)
// Defines values for TitleSort. // Defines values for TitleSort.
const ( const (
Id TitleSort = "id" Id TitleSort = "id"
@ -65,15 +65,15 @@ type Image struct {
ImagePath *string `json:"image_path,omitempty"` ImagePath *string `json:"image_path,omitempty"`
// StorageType Image storage type // 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 // ReleaseSeason Title release season
type ReleaseSeason string type ReleaseSeason string
// StorageType Image storage type
type StorageType string
// Studio defines model for Studio. // Studio defines model for Studio.
type Studio struct { type Studio struct {
Description *string `json:"description,omitempty"` Description *string `json:"description,omitempty"`
@ -154,7 +154,18 @@ type UserTitle struct {
Status UserTitleStatus `json:"status"` Status UserTitleStatus `json:"status"`
Title *Title `json:"title,omitempty"` Title *Title `json:"title,omitempty"`
UserId int64 `json:"user_id"` UserId int64 `json:"user_id"`
AdditionalProperties map[string]interface{} `json:"-"` }
// 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 // UserTitleStatus User's title status
@ -226,11 +237,32 @@ type GetUsersUserIdTitlesParams struct {
Fields *string `form:"fields,omitempty" json:"fields,omitempty"` 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. // UpdateUserJSONRequestBody defines body for UpdateUser for application/json ContentType.
type UpdateUserJSONRequestBody UpdateUserJSONBody type UpdateUserJSONRequestBody UpdateUserJSONBody
// UpdateUserTitleJSONRequestBody defines body for UpdateUserTitle for application/json ContentType.
type UpdateUserTitleJSONRequestBody UpdateUserTitleJSONBody
// AddUserTitleJSONRequestBody defines body for AddUserTitle for application/json ContentType. // AddUserTitleJSONRequestBody defines body for AddUserTitle for application/json ContentType.
type AddUserTitleJSONRequestBody = UserTitle type AddUserTitleJSONRequestBody AddUserTitleJSONBody
// Getter for additional properties for Title. Returns the specified // Getter for additional properties for Title. Returns the specified
// element and whether it was found // element and whether it was found
@ -474,145 +506,6 @@ func (a Title) MarshalJSON() ([]byte, error) {
return json.Marshal(object) 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. // ServerInterface represents all server handlers.
type ServerInterface interface { type ServerInterface interface {
// Get titles // Get titles
@ -627,9 +520,15 @@ type ServerInterface interface {
// Partially update a user account // Partially update a user account
// (PATCH /users/{user_id}) // (PATCH /users/{user_id})
UpdateUser(c *gin.Context, userId int64) UpdateUser(c *gin.Context, userId int64)
// Delete a usertitle
// (DELETE /users/{user_id}/titles)
DeleteUserTitle(c *gin.Context, userId int64)
// Get user titles // Get user titles
// (GET /users/{user_id}/titles) // (GET /users/{user_id}/titles)
GetUsersUserIdTitles(c *gin.Context, userId string, params GetUsersUserIdTitlesParams) 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 // Add a title to a user
// (POST /users/{user_id}/titles) // (POST /users/{user_id}/titles)
AddUserTitle(c *gin.Context, userId int64) AddUserTitle(c *gin.Context, userId int64)
@ -844,6 +743,30 @@ func (siw *ServerInterfaceWrapper) UpdateUser(c *gin.Context) {
siw.Handler.UpdateUser(c, userId) 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 // GetUsersUserIdTitles operation middleware
func (siw *ServerInterfaceWrapper) GetUsersUserIdTitles(c *gin.Context) { func (siw *ServerInterfaceWrapper) GetUsersUserIdTitles(c *gin.Context) {
@ -967,6 +890,30 @@ func (siw *ServerInterfaceWrapper) GetUsersUserIdTitles(c *gin.Context) {
siw.Handler.GetUsersUserIdTitles(c, userId, params) 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 // AddUserTitle operation middleware
func (siw *ServerInterfaceWrapper) AddUserTitle(c *gin.Context) { 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+"/titles/:title_id", wrapper.GetTitlesTitleId)
router.GET(options.BaseURL+"/users/:user_id", wrapper.GetUsersUserId) router.GET(options.BaseURL+"/users/:user_id", wrapper.GetUsersUserId)
router.PATCH(options.BaseURL+"/users/:user_id", wrapper.UpdateUser) 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.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) router.POST(options.BaseURL+"/users/:user_id/titles", wrapper.AddUserTitle)
} }
@ -1238,6 +1187,54 @@ func (response UpdateUser500Response) VisitUpdateUserResponse(w http.ResponseWri
return nil 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 { type GetUsersUserIdTitlesRequestObject struct {
UserId string `json:"user_id"` UserId string `json:"user_id"`
Params GetUsersUserIdTitlesParams Params GetUsersUserIdTitlesParams
@ -1291,6 +1288,64 @@ func (response GetUsersUserIdTitles500Response) VisitGetUsersUserIdTitlesRespons
return nil 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 { type AddUserTitleRequestObject struct {
UserId int64 `json:"user_id"` UserId int64 `json:"user_id"`
Body *AddUserTitleJSONRequestBody Body *AddUserTitleJSONRequestBody
@ -1300,18 +1355,7 @@ type AddUserTitleResponseObject interface {
VisitAddUserTitleResponse(w http.ResponseWriter) error VisitAddUserTitleResponse(w http.ResponseWriter) error
} }
type AddUserTitle200JSONResponse struct { type AddUserTitle200JSONResponse UserTitleMini
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"`
}
func (response AddUserTitle200JSONResponse) VisitAddUserTitleResponse(w http.ResponseWriter) error { func (response AddUserTitle200JSONResponse) VisitAddUserTitleResponse(w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
@ -1382,9 +1426,15 @@ type StrictServerInterface interface {
// Partially update a user account // Partially update a user account
// (PATCH /users/{user_id}) // (PATCH /users/{user_id})
UpdateUser(ctx context.Context, request UpdateUserRequestObject) (UpdateUserResponseObject, error) 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 user titles
// (GET /users/{user_id}/titles) // (GET /users/{user_id}/titles)
GetUsersUserIdTitles(ctx context.Context, request GetUsersUserIdTitlesRequestObject) (GetUsersUserIdTitlesResponseObject, error) 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 // Add a title to a user
// (POST /users/{user_id}/titles) // (POST /users/{user_id}/titles)
AddUserTitle(ctx context.Context, request AddUserTitleRequestObject) (AddUserTitleResponseObject, error) 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 // GetUsersUserIdTitles operation middleware
func (sh *strictHandler) GetUsersUserIdTitles(ctx *gin.Context, userId string, params GetUsersUserIdTitlesParams) { func (sh *strictHandler) GetUsersUserIdTitles(ctx *gin.Context, userId string, params GetUsersUserIdTitlesParams) {
var request GetUsersUserIdTitlesRequestObject 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 // AddUserTitle operation middleware
func (sh *strictHandler) AddUserTitle(ctx *gin.Context, userId int64) { func (sh *strictHandler) AddUserTitle(ctx *gin.Context, userId int64) {
var request AddUserTitleRequestObject var request AddUserTitleRequestObject

View file

@ -21,4 +21,3 @@ components:
$ref: "./parameters/_index.yaml" $ref: "./parameters/_index.yaml"
schemas: schemas:
$ref: "./schemas/_index.yaml" $ref: "./schemas/_index.yaml"

View file

@ -108,27 +108,27 @@ post:
content: content:
application/json: application/json:
schema: 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: responses:
'200': '200':
description: Title successfully added to user description: Title successfully added to user
content: content:
application/json: application/json:
schema: schema:
type: object
properties:
# success:
# type: boolean
# example: true
# error:
# type: string
# nullable: true
# example: null
data:
$ref: '../schemas/UserTitleMini.yaml' $ref: '../schemas/UserTitleMini.yaml'
# required:
# - success
# - error
'400': '400':
description: Invalid request body (missing fields, invalid types, etc.) description: Invalid request body (missing fields, invalid types, etc.)
'401': '401':
@ -141,3 +141,81 @@ post:
description: Conflict — title already assigned to user (if applicable) description: Conflict — title already assigned to user (if applicable)
'500': '500':
description: Internal server error 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

View file

@ -20,4 +20,3 @@ properties:
ctime: ctime:
type: string type: string
format: date-time format: date-time
additionalProperties: true

View file

@ -21,4 +21,3 @@ properties:
ctime: ctime:
type: string type: string
format: date-time format: date-time
additionalProperties: false

View file

@ -117,8 +117,8 @@ type PostAuthSignInResponseObject interface {
type PostAuthSignIn200JSONResponse struct { type PostAuthSignIn200JSONResponse struct {
Error *string `json:"error"` Error *string `json:"error"`
Success *bool `json:"success,omitempty"`
UserId *string `json:"user_id"` UserId *string `json:"user_id"`
UserName *string `json:"user_name"`
} }
func (response PostAuthSignIn200JSONResponse) VisitPostAuthSignInResponse(w http.ResponseWriter) error { func (response PostAuthSignIn200JSONResponse) VisitPostAuthSignInResponse(w http.ResponseWriter) error {

View file

@ -59,29 +59,23 @@ paths:
type: string type: string
format: password format: password
responses: responses:
# This one also sets two cookies: access_token and refresh_token
"200": "200":
description: Sign-in result with JWT description: Sign-in result with JWT
# headers:
# Set-Cookie:
# schema:
# type: array
# items:
# type: string
# explode: true
# style: simple
content: content:
application/json: application/json:
schema: schema:
type: object type: object
properties: properties:
success:
type: boolean
error: error:
type: string type: string
nullable: true nullable: true
user_id: user_id:
type: string type: string
nullable: true nullable: true
user_name:
type: string
nullable: true
"401": "401":
description: Access denied due to invalid credentials description: Access denied due to invalid credentials
content: content:

4
deploy/api_gen.ps1 Normal file
View 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

View file

@ -78,7 +78,6 @@ func (s Server) PostAuthSignIn(ctx context.Context, req auth.PostAuthSignInReque
} }
err := "" err := ""
success := true
pass, ok := UserDb[req.Body.Nickname] pass, ok := UserDb[req.Body.Nickname]
if !ok || pass != req.Body.Pass { if !ok || pass != req.Body.Pass {
@ -97,8 +96,8 @@ func (s Server) PostAuthSignIn(ctx context.Context, req auth.PostAuthSignInReque
// Return access token; refresh token can be returned in response or HttpOnly cookie // Return access token; refresh token can be returned in response or HttpOnly cookie
result := auth.PostAuthSignIn200JSONResponse{ result := auth.PostAuthSignIn200JSONResponse{
Error: &err, Error: &err,
Success: &success,
UserId: &req.Body.Nickname, UserId: &req.Body.Nickname,
UserName: &req.Body.Nickname,
} }
return result, nil return result, nil
} }

View file

@ -101,14 +101,14 @@ func sqlDate2oapi(p_date pgtype.Timestamptz) *time.Time {
func sql2usertitlestatus(s sqlc.UsertitleStatusT) (oapi.UserTitleStatus, error) { func sql2usertitlestatus(s sqlc.UsertitleStatusT) (oapi.UserTitleStatus, error) {
var status oapi.UserTitleStatus var status oapi.UserTitleStatus
switch status { switch s {
case "finished": case sqlc.UsertitleStatusTFinished:
status = oapi.UserTitleStatusFinished status = oapi.UserTitleStatusFinished
case "dropped": case sqlc.UsertitleStatusTDropped:
status = oapi.UserTitleStatusDropped status = oapi.UserTitleStatusDropped
case "planned": case sqlc.UsertitleStatusTPlanned:
status = oapi.UserTitleStatusPlanned status = oapi.UserTitleStatusPlanned
case "in-progress": case sqlc.UsertitleStatusTInProgress:
status = oapi.UserTitleStatusInProgress status = oapi.UserTitleStatusInProgress
default: default:
return status, fmt.Errorf("unexpected tittle status: %s", s) 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) { func UserTitleStatus2Sqlc1(s *oapi.UserTitleStatus) (*sqlc.UsertitleStatusT, error) {
var sqlc_status sqlc.UsertitleStatusT var sqlc_status sqlc.UsertitleStatusT = sqlc.UsertitleStatusTFinished
if s == nil { if s == nil {
return nil, nil return &sqlc_status, nil
} }
switch *s { switch *s {
@ -304,7 +304,7 @@ func (s Server) GetUsersUserIdTitles(ctx context.Context, request oapi.GetUsersU
tmp := fmt.Sprint(*t.Title.ReleaseYear) tmp := fmt.Sprint(*t.Title.ReleaseYear)
new_cursor.Param = &tmp new_cursor.Param = &tmp
case "rating": case "rating":
tmp := strconv.FormatFloat(*t.Title.Rating, 'f', -1, 64) tmp := strconv.FormatFloat(*t.Title.Rating, 'f', -1, 64) // падает
new_cursor.Param = &tmp 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) { func (s Server) AddUserTitle(ctx context.Context, request oapi.AddUserTitleRequestObject) (oapi.AddUserTitleResponseObject, error) {
//TODO: add review if exists
status, err := UserTitleStatus2Sqlc1(&request.Body.Status) status, err := UserTitleStatus2Sqlc1(&request.Body.Status)
if err != nil { if err != nil {
log.Errorf("%v", err) log.Errorf("%v", err)
@ -369,7 +369,7 @@ func (s Server) AddUserTitle(ctx context.Context, request oapi.AddUserTitleReque
params := sqlc.InsertUserTitleParams{ params := sqlc.InsertUserTitleParams{
UserID: request.UserId, UserID: request.UserId,
TitleID: request.Body.Title.Id, TitleID: request.Body.TitleId,
Status: *status, Status: *status,
Rate: request.Body.Rate, Rate: request.Body.Rate,
ReviewID: request.Body.ReviewId, ReviewID: request.Body.ReviewId,
@ -404,5 +404,5 @@ func (s Server) AddUserTitle(ctx context.Context, request oapi.AddUserTitleReque
UserId: user_title.UserID, UserId: user_title.UserID,
} }
return oapi.AddUserTitle200JSONResponse{Data: &oapi_usertitle}, nil return oapi.AddUserTitle200JSONResponse(oapi_usertitle), nil
} }

View file

@ -1,23 +1,34 @@
import React from "react"; import React from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; 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 TitlesPage from "./pages/TitlesPage/TitlesPage";
import { LoginPage } from "./pages/LoginPage/LoginPage"; import { LoginPage } from "./pages/LoginPage/LoginPage";
import { Header } from "./components/Header/Header"; import { Header } from "./components/Header/Header";
const App: React.FC = () => { const App: React.FC = () => {
const username = "nihonium"; // Получаем username из localStorage
const username = localStorage.getItem("username") || undefined;
const userId = localStorage.getItem("userId");
return ( return (
<Router> <Router>
<Header username={username} /> <Header username={username} />
<Routes> <Routes>
<Route path="/login" element={<LoginPage />} /> {/* <-- маршрут для логина */} <Route path="/login" element={<LoginPage />} />
<Route path="/signup" element={<LoginPage />} /> {/* <-- можно использовать тот же компонент для регистрации */} <Route path="/signup" element={<LoginPage />} />
<Route path="/users/:id" element={<UserPage />} />
{/* /profile рендерит UsersIdPage с id из localStorage */}
<Route
path="/profile"
element={userId ? <UsersIdPage userId={userId} /> : <LoginPage />}
/>
<Route path="/users/:id" element={<UsersIdPage />} />
<Route path="/titles" element={<TitlesPage />} /> <Route path="/titles" element={<TitlesPage />} />
</Routes> </Routes>
</Router> </Router>
); );
}; };
export default App; export default App;

View file

@ -20,7 +20,7 @@ export type OpenAPIConfig = {
}; };
export const OpenAPI: OpenAPIConfig = { export const OpenAPI: OpenAPIConfig = {
BASE: 'http://10.1.0.65:8081/api/v1', BASE: '/api/v1',
VERSION: '1.0.0', VERSION: '1.0.0',
WITH_CREDENTIALS: false, WITH_CREDENTIALS: false,
CREDENTIALS: 'include', CREDENTIALS: 'include',

View file

@ -4,7 +4,10 @@
/* eslint-disable */ /* eslint-disable */
export type Image = { export type Image = {
id?: number; id?: number;
storage_type?: string; /**
* Image storage type
*/
storage_type?: 's3' | 'local';
image_path?: string; image_path?: string;
}; };

View file

@ -2,15 +2,13 @@
/* istanbul ignore file */ /* istanbul ignore file */
/* tslint:disable */ /* tslint:disable */
/* eslint-disable */ /* eslint-disable */
import type { Image } from './Image';
export type User = { export type User = {
/** /**
* Unique user ID (primary key) * Unique user ID (primary key)
*/ */
id?: number; id?: number;
/** image?: Image;
* ID of the user avatar (references images table)
*/
avatar_id?: number;
/** /**
* User email * User email
*/ */

View file

@ -2,4 +2,14 @@
/* istanbul ignore file */ /* istanbul ignore file */
/* tslint:disable */ /* tslint:disable */
/* eslint-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;
};

View file

@ -20,7 +20,7 @@ export class DefaultService {
* @param sort * @param sort
* @param sortForward * @param sortForward
* @param word * @param word
* @param status * @param status List of title statuses to filter
* @param rating * @param rating
* @param releaseYear * @param releaseYear
* @param releaseSeason * @param releaseSeason
@ -35,7 +35,7 @@ export class DefaultService {
sort?: TitleSort, sort?: TitleSort,
sortForward: boolean = true, sortForward: boolean = true,
word?: string, word?: string,
status?: TitleStatus, status?: Array<TitleStatus>,
rating?: number, rating?: number,
releaseYear?: number, releaseYear?: number,
releaseSeason?: ReleaseSeason, 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 `-`, 316 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 * Get user titles
* @param userId * @param userId
* @param cursor * @param cursor
* @param sort
* @param sortForward
* @param word * @param word
* @param status * @param status List of title statuses to filter
* @param watchStatus * @param watchStatus
* @param rating * @param rating
* @param myRate
* @param releaseYear * @param releaseYear
* @param releaseSeason * @param releaseSeason
* @param limit * @param limit
* @param fields * @param fields
* @returns UserTitle List of user titles * @returns any List of user titles
* @throws ApiError * @throws ApiError
*/ */
public static getUsersTitles( public static getUsersTitles(
userId: string, userId: string,
cursor?: string, cursor?: string,
sort?: TitleSort,
sortForward: boolean = true,
word?: string, word?: string,
status?: TitleStatus, status?: Array<TitleStatus>,
watchStatus?: UserTitleStatus, watchStatus?: Array<UserTitleStatus>,
rating?: number, rating?: number,
myRate?: number,
releaseYear?: number, releaseYear?: number,
releaseSeason?: ReleaseSeason, releaseSeason?: ReleaseSeason,
limit: number = 10, limit: number = 10,
fields: string = 'all', fields: string = 'all',
): CancelablePromise<Array<UserTitle>> { ): CancelablePromise<{
data: Array<UserTitle>;
cursor: CursorObj;
}> {
return __request(OpenAPI, { return __request(OpenAPI, {
method: 'GET', method: 'GET',
url: '/users/{user_id}/titles/', url: '/users/{user_id}/titles',
path: { path: {
'user_id': userId, 'user_id': userId,
}, },
query: { query: {
'cursor': cursor, 'cursor': cursor,
'sort': sort,
'sort_forward': sortForward,
'word': word, 'word': word,
'status': status, 'status': status,
'watch_status': watchStatus, 'watch_status': watchStatus,
'rating': rating, 'rating': rating,
'my_rate': myRate,
'release_year': releaseYear, 'release_year': releaseYear,
'release_season': releaseSeason, 'release_season': releaseSeason,
'limit': limit, 'limit': limit,
@ -171,8 +238,48 @@ export class DefaultService {
}, },
errors: { errors: {
400: `Request params are not correct`, 400: `Request params are not correct`,
404: `User not found`,
500: `Unknown server error`, 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`,
},
});
}
} }

View file

@ -41,9 +41,9 @@ export class AuthService {
pass: string; pass: string;
}, },
): CancelablePromise<{ ): CancelablePromise<{
success?: boolean;
error?: string | null; error?: string | null;
user_id?: string | null; user_id?: string | null;
user_name?: string | null;
}> { }> {
return __request(OpenAPI, { return __request(OpenAPI, {
method: 'POST', method: 'POST',

View file

@ -12,7 +12,7 @@ export const Header: React.FC<HeaderProps> = ({ username }) => {
const toggleMenu = () => setMenuOpen(!menuOpen); const toggleMenu = () => setMenuOpen(!menuOpen);
return ( 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="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex justify-between h-16 items-center"> <div className="flex justify-between h-16 items-center">

View file

@ -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>
);
}

View file

@ -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>
);
}

View file

@ -18,17 +18,19 @@ export const LoginPage: React.FC = () => {
try { try {
if (isLogin) { if (isLogin) {
const res = await AuthService.postAuthSignIn({ nickname, pass: password }); const res = await AuthService.postAuthSignIn({ nickname, pass: password });
if (res.success) { if (res.user_id && res.user_name) {
// TODO: сохранить JWT в localStorage/cookie // Сохраняем user_id и username в localStorage
console.log("Logged in user id:", res.user_id); localStorage.setItem("userId", res.user_id);
navigate("/"); // редирект после успешного входа localStorage.setItem("username", res.user_name);
navigate("/profile"); // редирект на профиль
} else { } else {
setError(res.error || "Login failed"); setError(res.error || "Login failed");
} }
} else { } else {
// SignUp оставляем без сохранения данных
const res = await AuthService.postAuthSignUp({ nickname, pass: password }); const res = await AuthService.postAuthSignUp({ nickname, pass: password });
if (res.success) { if (res.user_id) {
console.log("User signed up with id:", res.user_id);
setIsLogin(true); // переключаемся на login после регистрации setIsLogin(true); // переключаемся на login после регистрации
} else { } else {
setError(res.error || "Sign up failed"); setError(res.error || "Sign up failed");

View file

@ -35,9 +35,9 @@ const UserPage: React.FC = () => {
<div className={styles.container}> <div className={styles.container}>
<div className={styles.header}> <div className={styles.header}>
<div className={styles.avatarWrapper}> <div className={styles.avatarWrapper}>
{user.avatar_id ? ( {user.image?.image_path ? (
<img <img
src={`/images/${user.avatar_id}.png`} src={`/images/${user.image.image_path}.png`}
alt="User Avatar" alt="User Avatar"
className={styles.avatarImg} className={styles.avatarImg}
/> />

View 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>
);
}