Implementace sluzby workdays
- endpointy /workdays/add, is-workday, next, previous, between - /holidays, /countries (filtr eu), /markets, /health, /version - data svatku z knihovny holidays 0.109, vsech 27 zemi EU vcetne regionu - vychozi zeme CZ a cestina pres DEFAULT_COUNTRY a DEFAULT_LANGUAGE - vlastni vikend, extra_holidays a extra_workdays v requestu - testy logiky, API a testy proti realnym kalendarum - CLAUDE.md s povinnym overenim vysledku proti realite - dokumentace ve slozce documentation - .gitignore: vyjimka pro app/lib
This commit is contained in:
+118
@@ -0,0 +1,118 @@
|
||||
"""Response models. They are the single description of the API shape."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
Weekday = Literal["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
|
||||
|
||||
|
||||
class CalendarRef(BaseModel):
|
||||
"""Kalendar, podle ktereho se pocitalo. Vraci se v kazde odpovedi."""
|
||||
|
||||
type: Literal["country", "market"]
|
||||
code: str = Field(examples=["CZ"])
|
||||
name: str = Field(examples=["Czechia"])
|
||||
region: str | None = Field(default=None, examples=[None])
|
||||
categories: list[str] = Field(examples=[["public"]])
|
||||
language: str | None = Field(default=None, examples=["cs"])
|
||||
weekend: list[Weekday] = Field(examples=[["sat", "sun"]])
|
||||
|
||||
|
||||
class DayInfoModel(BaseModel):
|
||||
"""Popis jednoho dne."""
|
||||
|
||||
date: date
|
||||
weekday: Weekday
|
||||
is_workday: bool
|
||||
is_weekend: bool
|
||||
holidays: list[str] = Field(description="Nazvy svatku v tento den, prazdne kdyz zadny neni.")
|
||||
override: Literal["extra_holiday", "extra_workday"] | None = Field(
|
||||
default=None,
|
||||
description="Den zmeneny parametrem extra_holidays nebo extra_workdays.",
|
||||
)
|
||||
|
||||
|
||||
class AddWorkdaysResponse(BaseModel):
|
||||
calendar: CalendarRef
|
||||
date: date
|
||||
days: int
|
||||
result: date = Field(examples=["2026-12-01"])
|
||||
skipped_holidays: list[DayInfoModel] = Field(
|
||||
description="Svatky a dny volna mimo vikend, ktere vypocet preskocil."
|
||||
)
|
||||
|
||||
|
||||
class DayResponse(DayInfoModel):
|
||||
calendar: CalendarRef
|
||||
|
||||
|
||||
class ShiftResponse(BaseModel):
|
||||
calendar: CalendarRef
|
||||
date: date
|
||||
result: date
|
||||
|
||||
|
||||
class BetweenResponse(BaseModel):
|
||||
calendar: CalendarRef
|
||||
start: date
|
||||
end: date
|
||||
workdays: int = Field(description="Pocet pracovnich dnu, oba krajni dny vcetne.")
|
||||
weekend_days: int
|
||||
holidays_off: int = Field(description="Pocet svatku a dnu volna, ktere padly mimo vikend.")
|
||||
holidays: list[DayInfoModel] = Field(description="Svatky a dny volna mimo vikend v intervalu.")
|
||||
|
||||
|
||||
class HolidayItem(BaseModel):
|
||||
date: date
|
||||
weekday: Weekday
|
||||
names: list[str]
|
||||
is_weekend: bool
|
||||
|
||||
|
||||
class HolidaysResponse(BaseModel):
|
||||
calendar: CalendarRef
|
||||
year: int
|
||||
holidays: list[HolidayItem]
|
||||
|
||||
|
||||
class RegionItem(BaseModel):
|
||||
code: str
|
||||
name: str | None
|
||||
|
||||
|
||||
class YearRange(BaseModel):
|
||||
from_: int = Field(alias="from")
|
||||
to: int
|
||||
|
||||
|
||||
class CalendarDescription(BaseModel):
|
||||
code: str
|
||||
name: str
|
||||
eu: bool
|
||||
regions: list[RegionItem]
|
||||
categories: list[str]
|
||||
languages: list[str]
|
||||
default_language: str | None
|
||||
years: YearRange
|
||||
|
||||
|
||||
class CalendarListResponse(BaseModel):
|
||||
items: list[CalendarDescription]
|
||||
|
||||
|
||||
class HealthResponse(BaseModel):
|
||||
status: Literal["ok"]
|
||||
app: str
|
||||
version: str
|
||||
holidays_library: str
|
||||
default_country: str
|
||||
|
||||
|
||||
class ErrorResponse(BaseModel):
|
||||
error_code: str
|
||||
message: str
|
||||
detail: dict | None = None
|
||||
Reference in New Issue
Block a user