Skip to content

Commit

Permalink
Remove categories tab (not yet built) and catch 404 and cleaning errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ddxv committed Oct 23, 2023
1 parent 22ccac6 commit afff6ab
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
8 changes: 7 additions & 1 deletion backend/api_app/controllers/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from config import get_logger
from dbcon.queries import get_single_app, query_recent_apps
from litestar import Controller, get
from litestar.exceptions import NotFoundException

logger = get_logger(__name__)

Expand Down Expand Up @@ -61,7 +62,7 @@ async def get_apps_overview(self) -> AppsOverview:
Returns:
A dictionary representation of the list of apps for homepasge
"""
logger.info("inside a request")
logger.info(f"{self.path} start")
home_dict = get_app_overview_dict()

return home_dict
Expand All @@ -77,8 +78,13 @@ async def get_app_detail(self, store_id: str) -> AppDetail:
Returns:
json
"""
logger.info(f"{self.path} start")

app_df = get_single_app(store_id)
if app_df.empty:
raise NotFoundException(
f"Store ID not found: {store_id!r}", status_code=404
)
app_dict = app_df.to_dict(orient="records")[0]

return app_dict
2 changes: 1 addition & 1 deletion backend/api_app/controllers/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def get_categories_overview(self) -> CategoriesOverview:
A dictionary representation of the list of categories
each with an id, name, type and total of apps
"""
logger.info("inside a request")
logger.info(f"{self.path} start")
overview = category_overview()

return overview
11 changes: 6 additions & 5 deletions backend/dbcon/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ def get_top_apps_by_installs(
return df


def get_single_app(app_id: str) -> pd.DataFrame:
logger.info(f"Query for single app_id={app_id}")
where_str = f"WHERE store_id = '{app_id}'"
def get_single_app(store_id: str) -> pd.DataFrame:
logger.info(f"Query for single app_id={store_id}")
where_str = f"WHERE store_id = '{store_id}'"
where_str = text(where_str)
sel_query = f"""SELECT
sa.*,
Expand All @@ -367,7 +367,8 @@ def get_single_app(app_id: str) -> pd.DataFrame:
;
"""
df = pd.read_sql(sel_query, DBCON.engine)
df = clean_app_df(df)
if not df.empty:
df = clean_app_df(df)
return df


Expand All @@ -376,7 +377,7 @@ def clean_app_df(df: pd.DataFrame) -> pd.DataFrame:
string_nums = ["installs", "review_count", "rating_count"]
for col in string_nums:
df[col] = df[col].apply(
lambda x: "{:,.0f}".format(x) if not np.isnan(x) else "N/A"
lambda x: "N/A" if (x is None or np.isnan(x)) else "{:,.0f}".format(x)
)
df["rating"] = df["rating"].apply(lambda x: round(x, 2) if x else 0)
ios_link = "https://apps.apple.com/us/app/-/id"
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
<TabAnchor href="/" selected={$page.url.pathname === '/'}>
<span>HOME</span>
</TabAnchor>
<TabAnchor href="/categories" selected={$page.url.pathname === '/categories'}>
<span>CATEGORIES</span>
</TabAnchor>
<TabAnchor href="/about" selected={$page.url.pathname === '/about'}>
<span>ABOUT</span>
</TabAnchor>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/apps/[id]/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const ssr = true;
export const csr = false;
export const csr = true;
console.log('Script executed');

/** @type {import('../[id]/$types').PageServerLoad} */
Expand Down

0 comments on commit afff6ab

Please sign in to comment.