Skip to content

Commit

Permalink
Merge pull request #14 from ddxv/broken-ios-search
Browse files Browse the repository at this point in the history
Broken ios search
  • Loading branch information
ddxv authored Nov 28, 2023
2 parents 623dd11 + 455dcb9 commit 499971f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 70 deletions.
6 changes: 4 additions & 2 deletions backend/api_app/controllers/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,16 @@ async def get_developer_apps(self, developer_id: str) -> DeveloperApps:
"""
logger.info(f"{self.path} start")
apps_df = query_single_developer(developer_id)

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

developer_apps = DeveloperApps(
developer_id=developer_id, title=app_dict["developer_name"], apps=app_dict
developer_id=developer_id, title=developer_name, apps=apps_dict
)
return developer_apps

Expand Down
37 changes: 5 additions & 32 deletions backend/dbcon/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,32 +255,6 @@ def query_updated_timestamps(
return df


def query_search_developers(search_input: str, limit: int = 1000):
logger.info(f"Developer search: {search_input=}")
search_input = f"%%{search_input}%%"
sel_query = f"""SELECT
d.*,
pd.*,
sa.*
FROM
app_urls_map aum
LEFT JOIN pub_domains pd ON
pd.id = aum.pub_domain
LEFT JOIN store_apps sa ON
sa.id = aum.store_app
LEFT JOIN developers d ON
d.id = sa.developer
WHERE
d.name ILIKE '{search_input}'
OR d.developer_id ILIKE '{search_input}'
OR pd.url ILIKE '{search_input}'
LIMIT {limit}
;
"""
df = pd.read_sql(sel_query, DBCON.engine)
return df


def get_all_tables_in_schema(schema_name: str):
logger.info("Get checks tables")
sel_schema = f"""SELECT table_name
Expand Down Expand Up @@ -507,16 +481,14 @@ def clean_app_df(df: pd.DataFrame) -> pd.DataFrame:
play_link = "https://play.google.com/store/apps/details?id="
play_dev_link = "https://play.google.com/store/apps/dev?id="
ios_dev_link = "https://apps.apple.com/us/developer/-/id"

df["store_link"] = (
np.where(df["store"].str.contains("Google"), play_link, ios_link)
+ df["store_id"]
)
if "developer_id" in df.columns:
df["store_developer_link"] = (
np.where(df["store"].str.contains("Google"), play_dev_link, ios_dev_link)
+ df["developer_id"]
)
df["store_developer_link"] = np.where(
df["store"].str.contains("Google"), play_dev_link, ios_dev_link
) + df["developer_id"].astype(str)

date_cols = ["created_at", "store_last_updated", "updated_at"]
for x in date_cols:
Expand Down Expand Up @@ -545,6 +517,7 @@ def query_single_developer(developer_id: str):
sel_query = """SELECT
d.name AS developer_name,
pd.url as developer_url,
d.store as developer_store,
sa.*
FROM
app_urls_map aum
Expand All @@ -563,7 +536,7 @@ def query_single_developer(developer_id: str):
DBCON.engine,
params=(developer_id,),
)
if df.empty:
if not df.empty:
df = clean_app_df(df)
return df

Expand Down
20 changes: 14 additions & 6 deletions frontend/src/routes/apps/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,21 @@

<div class="block md:hidden" />
{#if appdata.developer_id}
<a href="/developers/{appdata.developer_id}" class="btn btn-hover variant-ghost-primary"
><span>Developer: {appdata.developer_name}</span></a
>
<div class="p-2 md:py-2">
<a
href="/developers/{appdata.developer_id}"
class="btn hover:bg-primary-hover-token variant-ghost-primary"
><span>Developer: {appdata.developer_name}</span></a
>
</div>
{/if}
<a href="/categories/{appdata.category}" class="btn variant-ghost-primary"
><span>Category: {appdata.category}</span></a
>
<div class="p-2 md:py-2">
<a
href="/categories/{appdata.category}"
class="btn hover:bg-primary-hover-token variant-ghost-primary"
><span>Category: {appdata.category}</span></a
>
</div>
</div>

<div class="card-footer md:flex">
Expand Down
49 changes: 31 additions & 18 deletions frontend/src/routes/developers/[developer]/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
export const ssr: boolean = true;
export const csr: boolean = false;
import type { PageServerLoad } from './$types.js';

import type { AppGroup, DeveloperResponse } from '../../../types.js';
export const ssr: boolean = true;
export const csr: boolean = true;

console.log('Script executed');

/** @type {import('../[developer]/$types').PageServerLoad} */
export async function load({ params }): Promise<DeveloperResponse> {
export const load: PageServerLoad = async ({ params, locals }) => {
const developerValue = params.developer;
console.log(`load started collection=${developerValue}`);
const res = fetch(`http://localhost:8000/api/apps/developers/${developerValue}`);
console.log(`load started developer=${developerValue}`);
try {
const res = await fetch(`http://localhost:8000/api/apps/developers/${developerValue}`);

if (!res.ok) {
const text = await res.text();
throw new Error(`Failed to fetch developers status ${res.status} ${text}`);
}

const app_collections: AppGroup = await res.json();
console.log(`loaded developers with len: ${Object.keys(app_collections).length}`);
return { results: app_collections };
return {
results: {
streamed: res
.then((resp) => {
if (resp.status === 200) {
return resp.json();
} else if (resp.status === 404) {
console.log('App Not found');
return 'App Not Found';
} else if (resp.status === 500) {
console.log('API Server error');
return 'Backend Error';
}
})
.then(
(json) => json,
(error) => {
console.log('Uncaught error', error);
return 'Uncaught Error';
}
)
}
};
} catch (error) {
console.error('Failed to load data:', error);
return {
results: { streamed: {} },
status: 500,
error: 'Failed to load trending apps'
};
}
}
};
13 changes: 7 additions & 6 deletions frontend/src/routes/developers/[developer]/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<script lang="ts">
import type { DeveloperResponse } from '../../../types';
/** @type {import('../[developer]/$types').PageData} */
export let data: DeveloperResponse;
import AppsCard from '$lib/AppGroupCard.svelte';
</script>

<div>
{#await data}
{#await data.results.streamed}
<div>
<span>Loading...</span>
</div>
{:then data}
{#if data.results}
<h1 class="h1 p-2">Apps: {data.results.title}</h1>
<AppsCard apps={data.results} />
{:then devs}
{#if typeof devs == 'string'}
Failed to load developer
{:else}
<h1 class="h1 p-2">Apps: {devs.title}</h1>
<AppsCard apps={devs} />
<p class="p-2" />
{/if}
{:catch error}
Expand Down
11 changes: 5 additions & 6 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ export interface AppGroup {
title: string;
}

export interface DeveloperResponse {
results?: AppGroup;
status?: number;
error?: string;
}

export interface Category {
key: string;
google: AppGroup;
Expand All @@ -23,6 +17,11 @@ export interface CategoryResponse {
error?: string;
}

export interface DeveloperResponse {
results: { streamed: AppGroup };
status?: number;
error?: string;
}
export interface SearchResponse {
results: { streamed: AppGroup };
status?: number;
Expand Down

0 comments on commit 499971f

Please sign in to comment.