Skip to content

Commit

Permalink
Merge branch 'develop' into feature/oct-1857-octant-client-v1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
aziolek committed Oct 2, 2024
2 parents d2196e3 + 6fac929 commit f2c6655
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
8 changes: 8 additions & 0 deletions backend/app/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,11 @@ class InvalidAddressFormat(OctantException):

def __init__(self):
super().__init__(self.description, self.code)


class InvalidProjectDetailsInput(OctantException):
code = 400
description = "Invalid input for projects details"

def __init__(self):
super().__init__(self.description, self.code)
35 changes: 16 additions & 19 deletions backend/app/infrastructure/routes/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
get_projects_metadata,
)
from app.modules.projects.details import controller as projects_details_controller
from app.infrastructure.routes.validations.project_details_input import (
validate_project_details_input,
)

ns = Namespace("projects", description="Octant projects")
api.add_namespace(ns)
Expand All @@ -24,26 +27,20 @@
},
)

project_model = api.model(
"Project",
{
"name": fields.String(required=True, description="Project name"),
"address": fields.String(required=True, description="Project address"),
"epoch": fields.String(required=True, description="Project epoch"),
},
)

projects_details_model = api.model(
"ProjectsDetails",
{
"projects_details": fields.List(
fields.Nested(
api.model(
"ProjectsDetails",
{
"name": fields.String(
required=True, description="Project name"
),
"address": fields.String(
required=True, description="Project address"
),
"epoch": fields.String(
required=True, description="Project epoch"
),
},
)
),
"projectsDetails": fields.List(
fields.Nested(project_model),
required=False,
description="Projects details",
),
Expand Down Expand Up @@ -85,7 +82,7 @@ class ProjectsDetails(OctantResource):
@ns.response(200, "Projects metadata is successfully retrieved")
def get(self):
search_phrases = request.args.get("searchPhrases", "").split(",")
epochs = list(map(int, request.args.get("epochs", "").split(",")))
epochs = validate_project_details_input(request.args.get("epochs", ""))

app.logger.debug(
f"Getting projects details for epochs {epochs} and search phrase {search_phrases}"
Expand All @@ -98,7 +95,7 @@ def get(self):
app.logger.debug(f"Projects details for epochs {epochs}: {projects_details}")

return {
"projects_details": [
"projectsDetails": [
{
"name": project["name"],
"address": project["address"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import List

from app.exceptions import InvalidProjectDetailsInput


def validate_project_details_input(epochs: str) -> List[int]:
try:
epochs = list(map(int, epochs.split(",")))
except ValueError:
raise InvalidProjectDetailsInput

return epochs

0 comments on commit f2c6655

Please sign in to comment.