-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring api and ui; working on profile form
- Loading branch information
1 parent
bc96599
commit e3e229c
Showing
12 changed files
with
172 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { RouterContext } from "oak"; | ||
|
||
export async function handleError(ctx: RouterContext<string>, next: () => Promise<void>) { | ||
try { | ||
await next(); | ||
} catch (err) { | ||
// TODO: handle various errors? | ||
console.error("ERROR!", err); | ||
ctx.response.status = 500; | ||
ctx.response.body = { msg: err.message }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import profileController from "@/controllers/profile.controller.ts"; | ||
import { searchTrainers } from "@/controllers/trainers.controller.ts"; | ||
import { logError } from "@/handlers/commands/createLog.handler.ts"; | ||
import { syncTrainerCodes } from "@/handlers/commands/syncTrainerCodes.handler.ts"; | ||
import { SyncTrainersRequest } from "@/types/requests/syncTrainersRequest.ts"; | ||
import { validateApiKey } from "@/utils/auth.ts"; | ||
import { handleResponse } from "@/utils/common.ts"; | ||
import { Router, RouterContext, Status } from "oak"; | ||
|
||
export function setupRoutes(router: Router<Record<string, any>>) { | ||
router | ||
.get("/api/health", (ctx: RouterContext<string>) => { | ||
ctx.response.body = { | ||
status: "Healthy", | ||
message: "Welcome to PoGo Trainer Codes", | ||
}; | ||
}) | ||
.get("/api/profile", profileController.getProfile) | ||
.post("/api/profile", profileController.create) | ||
.get("/api/trainer-codes/search", searchTrainers) | ||
// TODO: move to controller | ||
.post("/api/trainer-codes/sync", async (ctx: RouterContext<string>) => { | ||
try { | ||
const isValidApiKey = await validateApiKey(ctx.request.headers.get("X-API-KEY")); | ||
if (!isValidApiKey) { | ||
ctx.response.status = Status.Unauthorized; | ||
return; | ||
} | ||
|
||
const body = ctx.request.body(); | ||
const result = (await body.value) as SyncTrainersRequest; | ||
const source = result?.source; | ||
|
||
if (!source) { | ||
await logError("Missing source", null, ctx.state.requestId); | ||
ctx.response.body = { | ||
success: false, | ||
message: "Missing source", | ||
}; | ||
ctx.response.status = Status.BadRequest; | ||
return; | ||
} | ||
|
||
const response = await syncTrainerCodes(source!); | ||
|
||
handleResponse(ctx, response); | ||
} catch (e) { | ||
await logError("Unable to sync trainer codes.", e, ctx.state.requestId); | ||
ctx.response.body = { | ||
success: false, | ||
message: "Unable to sync trainer codes.", | ||
}; | ||
ctx.response.status = Status.InternalServerError; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,4 +50,11 @@ html { | |
flex-shrink: 0; | ||
} | ||
} | ||
.clickable { | ||
&:hover { | ||
opacity: 0.8; | ||
cursor: pointer; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<template> | ||
<form class="mt-6 flex"> | ||
<section class="pr-4"> | ||
<div class="flex flex-col my-4"> | ||
<label for="username" class="mb-2 font-semibold">Discord Username</label> | ||
<input | ||
class="p-4 rounded-lg border-2 border-black" | ||
type="text" | ||
id="username" | ||
:disabled="true" | ||
:value="profileStore.profile?.username" | ||
/> | ||
</div> | ||
</section> | ||
<section class="pl-4"> | ||
<div class="flex flex-col my-4"> | ||
<label for="trainer-name" class="mb-2 font-semibold">Trainer Name</label> | ||
<input class="p-4 rounded-lg border-2 border-black" type="text" id="trainer-name" /> | ||
</div> | ||
|
||
<div class="flex flex-col my-4"> | ||
<label for="trainer-code" class="mb-2 font-semibold">Trainer Code</label> | ||
<input class="p-4 rounded-lg border-2 border-black" type="text" id="trainer-code" :disabled="true" /> | ||
</div> | ||
</section> | ||
</form> | ||
</template> | ||
<script setup lang="ts"> | ||
import { useProfileStore } from "@/stores/profileStore"; | ||
const profileStore = useProfileStore(); | ||
</script> | ||
<style lang="scss" scoped> | ||
section { | ||
flex: 1 1 0; | ||
input { | ||
&:disabled { | ||
background-color: #e5e7eb; | ||
opacity: 0.75; | ||
border-color: #9ca3af; | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,10 +112,4 @@ $search-container-height: 175px; | |
border-color: #000; | ||
} | ||
} | ||
#search--btn { | ||
&:hover { | ||
opacity: 0.8; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ export interface Trainer { | |
export interface Profile { | ||
profileId: number; | ||
username: string; | ||
userId: string; | ||
} |