Skip to content

Commit

Permalink
repository pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
extreme4all committed Mar 18, 2024
1 parent cfa6049 commit e67d15c
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/api/v2/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi import APIRouter, Depends, HTTPException, Query, status
from pydantic.fields import Field

from src.app.models.player import Player
from src.app.repositories.player import Player as repoPlayer
from src.app.views.response.feedback_score import FeedbackScoreResponse
from src.app.views.response.prediction import PredictionResponse
from src.app.views.response.report_score import ReportScoreResponse
Expand Down Expand Up @@ -36,9 +36,9 @@ async def get_players_kc(
Returns:
list[ReportScoreResponse]: A list of dictionaries containing KC data for each player.
"""
player = Player(session)
repo = repoPlayer(session)
names = await asyncio.gather(*[to_jagex_name(n) for n in name])
data = await player.get_report_score(player_names=names)
data = await repo.get_report_score(player_names=names)
return data


Expand All @@ -62,9 +62,9 @@ async def get_feedback_score(
Returns:
list[FeedbackScoreResponse]: A list of dictionaries containing KC data for each player.
"""
player = Player(session)
repo = repoPlayer(session)
names = await asyncio.gather(*[to_jagex_name(n) for n in name])
data = await player.get_feedback_score(player_names=names)
data = await repo.get_feedback_score(player_names=names)
return data


Expand Down Expand Up @@ -94,9 +94,9 @@ async def get_prediction(
HTTPException: Returns a 404 error with the message "Player not found" if no data is found for the user.
"""
player = Player(session)
repo = repoPlayer(session)
names = await asyncio.gather(*[to_jagex_name(n) for n in name])
data = await player.get_prediction(player_names=names)
data = await repo.get_prediction(player_names=names)
if not data:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Player not found"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/app/views/input/feedback.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from typing import Optional

from pydantic import BaseModel, Field, constr, validator
from pydantic import BaseModel, Field, validator


class FeedbackInput(BaseModel):
"""
Class representing prediction feedback input.
"""

player_name: constr(strip_whitespace=True) = Field(
player_name: str = Field(
...,
example="Player1",
min_length=1,
Expand All @@ -35,7 +35,7 @@ class FeedbackInput(BaseModel):
)

@validator("player_name")
def uuid_format(cls, value: str):
def player_name_validator(cls, value: str):
match value:
case _ if 1 <= len(value) <= 12:
return value
Expand Down

0 comments on commit e67d15c

Please sign in to comment.