History module

Module for managing history

Route

app.features.history.route.delete_history_item(body)

Delete entries from user history — tags:

  • features/history

security:
  • BearerAuth: []

requestBody:

required: true content:

application/json:
schema:

type: object required: [ids] properties:

ids:

type: array description: IDs to delete items:

type: integer

example: [7, 8, 3]

responses:
200:

description: Successful deletion content:

application/json:
schema:

type: object required: [data, error] properties:

data:

type: object nullable: true example: null

error:

type: string nullable: true example: null

400:

description: Validation error of incoming JSON (Pydantic) content:

application/json:
schema:

type: object properties:

validation_error:

type: object properties:

body_params:

type: array items:

type: object properties:

input:

type: string example: “jhgjk”

loc:

type: array items:

type: string

example: [“ids”, 0]

msg:

type: string example: “Input should be a valid integer…”

type:

type: string example: “int_parsing”

url:

type: string example: “https://pydantic.dev…”

401:

description: Unauthorized (missing or invalid JWT) content:

application/json:
schema:

type: object properties:

message:

type: string example: “Missing Authorization Header”

409:

description: Server error / Business error content:

application/json:
schema:

type: object required: [data, error] properties:

data:

type: object nullable: true example: null

error:

type: string example: “Database error”

Parameters:

body (DeleteHistoryRequest)

app.features.history.route.get_history_route()

Get user history — tags:

  • features/history

security:
  • BearerAuth: []

responses:
200:

description: Successful retrieval of history content:

application/json:
schema:

type: object required: [data, error] properties:

data:

type: array items:

type: object required: [id, word] properties:

id:

type: integer example: 7

word:

type: string example: “meet”

error:

type: string nullable: true example: null

401:

description: Unauthorized (missing or invalid JWT) content:

application/json:
schema:

type: object properties:

message:

type: string example: “Missing Authorization Header”

409:

description: Server error / Business error content:

application/json:
schema:

type: object required: [data, error] properties:

data:

type: object nullable: true example: null

error:

type: string example: “Database error”

Service

class app.features.history.service.HistoryService

Bases: object

Service for managing user translation history data.

delete_history(ids, user_id)

Deletes specific items from a user’s translation history.

Parameters:
  • ids (list[int]) – A list of history entry IDs to be deleted.

  • user_id (int) – The unique ID of the user.

Returns:

The data transfer object containing the operation results.

Return type:

BaseDTO[None]

get_history(user_id)

Retrieves the translation history for a specific user.

Parameters:

user_id (int) – The unique ID of the user.

Returns:

The data transfer object containing the list of translation history entries.

Return type:

BaseDTO[list[TranslationDTO]]

is_user_owns_history_item(user_id, translation_id)

Checks if a specific history element belongs to a given user.

Parameters:
  • user_id (int) – The unique ID of the user.

  • translation_id (int) – The unique ID of the translation entry.

Returns:

True if the user owns the history element, False otherwise.

Return type:

bool

Repository

class app.features.history.repository.HistoryRepository

Bases: object

Repository for managing user translation history records in the database.

delete_history_item(id)

Deletes a specific element from the user’s translation history.

Parameters:

id (int) – The unique ID of the element to delete.

get_history(user_id)

Retrieves the translation history for a specific user.

Parameters:

user_id (int) – The unique ID of the user.

Returns:

A list of translation history elements.

Return type:

list[Translation]

get_history_item(translation_id)

Retrieves a specific translation history element by its ID.

Parameters:

translation_id (int) – The unique ID of the translation element.

Returns:

The requested translation history element.

Return type:

Translation

Requests

class app.features.history.requests.DeleteHistoryRequest

Bases: BaseModel

Represents a request payload for deleting specific items from the translation history.

Fields

Field

Type

Required

Default

Constraints

ids

List[int]

Yes

min_length=1

ids: List[int]

A list of unique IDs of the history items to be deleted.

Constraints:
  • min_length = 1

Responses

class app.features.history.responses.HistoryItem

Bases: BaseModel

Represents an individual entry within the translation history log.

Fields

Field

Type

Required

Default

id

int

Yes

word

str

Yes

id: int

The unique ID of the history item.

word: str

The word that was translated and saved.

app.features.history.responses.HistoryResponse

Type alias for the API response containing a list of history items.

Fields

Field

Type

Required

Default

data

List[HistoryItem] | None

No

None

error

str | None

No

None

Consts

DTO

class app.features.history.dto.TranslationDTO

Data transfer object representing a completed translation entry.

id: int

The unique identifier of the translation.

word: str

The translated word.