Skip to content

Commit

Permalink
link all routes [scuffed]
Browse files Browse the repository at this point in the history
  • Loading branch information
dromzeh committed Oct 15, 2023
1 parent cacbbd4 commit 15d3ef1
Show file tree
Hide file tree
Showing 23 changed files with 399 additions and 113 deletions.
12 changes: 7 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Hono } from "hono"
import assetRoute from "./v2/routes/asset/assetRoute"
import discordRoute from "./v2/routes/discord/discordRoute"
import assetRoute from "./v2/routes/asset/assetRoutes"
import discordRoute from "./v2/routes/discord/discordRoutes"
import ocGeneratorRoute from "./v2/routes/oc-generators/ocGeneratorRoutes"
import gamesRoute from "./v2/routes/games/gamesRoute"
import authRoute from "./v2/routes/auth/authRoute"
import searchRoute from "./v2/routes/search/searchRoute"
import gamesRoute from "./v2/routes/games/gamesRoutes"
import authRoute from "./v2/routes/auth/authRoutes"
import searchRoute from "./v2/routes/search/searchRoutes"
import tagsRoute from "./v2/routes/tags/tagsRoutes"
import { getRuntimeKey } from "hono/adapter"

const app = new Hono<{ Bindings: Bindings }>()
Expand All @@ -27,6 +28,7 @@ app.route("/v2/oc-generators", ocGeneratorRoute)
app.route("/v2/search", searchRoute)
app.route("/v2/games", gamesRoute)
app.route("/v2/auth", authRoute)
app.route("/v2/tags", tagsRoute)
app.all("*", (c) => {
return c.json(
{ success: false, status: "error", error: "route doesn't exist" },
Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions src/v2/routes/auth/asset-categories/assetCategoryRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createAssetCategory } from "./createAssetCategory"
import { deleteAssetCategory } from "./deleteAssetCategory"
import { Hono } from "hono"
import { cors } from "hono/cors"

const assetCategoryRoute = new Hono<{ Bindings: Bindings }>()

assetCategoryRoute.use(
"*",
cors({
credentials: true,
origin: ["http://localhost:3000"], // TODO: update this - temporary
})
)

assetCategoryRoute.post("/create", async (c) => {
return createAssetCategory(c)
})

assetCategoryRoute.post("/delete", async (c) => {
return deleteAssetCategory(c)
})

export default assetCategoryRoute
39 changes: 39 additions & 0 deletions src/v2/routes/auth/assets/assetRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { approveAsset } from "./approveAsset"
import { getUnapprovedAssets } from "./getUnapprovedAssets"
import { modifyAssetData } from "./modifyAsset"
import { uploadAsset } from "./uploadAsset"
import { Hono } from "hono"
import { cors } from "hono/cors"
import collectionsRoute from "./collections/collectionsRoutes"
import favoriteAssetRoute from "./favorite/favoriteAssetRoutes"

const assetRoute = new Hono<{ Bindings: Bindings }>()

assetRoute.use(
"*",
cors({
credentials: true,
origin: ["http://localhost:3000"], // TODO: update this - temporary
})
)

assetRoute.get("/unapproved", async (c) => {
return getUnapprovedAssets(c)
})

assetRoute.post("/approve/:assetIdToApprove", async (c) => {
return approveAsset(c)
})

assetRoute.post("/modify/:assetIdToModify", async (c) => {
return modifyAssetData(c)
})

assetRoute.post("/upload", async (c) => {
return uploadAsset(c)
})

assetRoute.route("/collections", collectionsRoute)
assetRoute.route("/favorite", favoriteAssetRoute)

export default assetRoute
44 changes: 44 additions & 0 deletions src/v2/routes/auth/assets/collections/collectionsRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { addAssetToCollection } from "./addAssetToCollection"
import { createAssetCollection } from "./createAssetCollection"
import { deleteAssetCollection } from "./deleteAssetCollection"
import { deleteAssetFromCollection } from "./deleteAssetFromCollection"
import { viewAssetCollection } from "./viewAssetCollection"
import { viewAssetCollections } from "./viewAssetCollections"
import { Hono } from "hono"
import { cors } from "hono/cors"

const collectionsRoute = new Hono<{ Bindings: Bindings }>()

collectionsRoute.use(
"*",
cors({
credentials: true,
origin: ["http://localhost:3000"], // TODO: update this - temporary
})
)

collectionsRoute.post("/create", async (c) => {
return createAssetCollection(c)
})

collectionsRoute.post("/delete", async (c) => {
return deleteAssetCollection(c)
})

collectionsRoute.post("/add", async (c) => {
return addAssetToCollection(c)
})

collectionsRoute.post("/remove", async (c) => {
return deleteAssetFromCollection(c)
})

collectionsRoute.get("/all", async (c) => {
return viewAssetCollections(c)
})

collectionsRoute.get("/:collectionId", async (c) => {
return viewAssetCollection(c)
})

export default collectionsRoute
12 changes: 4 additions & 8 deletions src/v2/routes/auth/assets/collections/viewAssetCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ export async function viewAssetCollection(c: APIContext): Promise<Response> {
return c.json({ success: false, state: "invalid session" }, 401)
}

const formData = await c.req.formData()
const collectionId = c.req.param("collectionId")

const collection = {
id: formData.get("collectionId") as string | null,
}

if (!collection.id) {
if (!collectionId) {
return c.json(
{ success: false, state: "no collection id entered" },
200
Expand All @@ -34,7 +30,7 @@ export async function viewAssetCollection(c: APIContext): Promise<Response> {
where: (userCollections, { eq, or, and }) =>
and(
or(
eq(userCollections.id, collection.id),
eq(userCollections.id, collectionId),
eq(userCollections.isPublic, 1)
),
eq(userCollections.userId, session.user.userId)
Expand All @@ -54,7 +50,7 @@ export async function viewAssetCollection(c: APIContext): Promise<Response> {
where: (userCollections, { eq, or, and }) =>
and(
or(
eq(userCollections.id, collection.id),
eq(userCollections.id, collectionId),
eq(userCollections.isPublic, 1)
),
eq(userCollections.userId, session.user.userId)
Expand Down
29 changes: 29 additions & 0 deletions src/v2/routes/auth/assets/favorite/favoriteAssetRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Hono } from "hono"
import { cors } from "hono/cors"
import { favoriteAsset } from "./addFavoriteAsset"
import { removeFavoriteAsset } from "./removeFavoriteAsset"
import { viewFavoriteAssets } from "./viewFavoriteAssets"

const favoriteAssetRoute = new Hono<{ Bindings: Bindings }>()

favoriteAssetRoute.use(
"*",
cors({
credentials: true,
origin: ["http://localhost:3000"], // TODO: update this - temporary
})
)

favoriteAssetRoute.post("/add", async (c) => {
return favoriteAsset(c)
})

favoriteAssetRoute.post("/remove", async (c) => {
return removeFavoriteAsset(c)
})

favoriteAssetRoute.get("/all", async (c) => {
return viewFavoriteAssets(c)
})

export default favoriteAssetRoute
90 changes: 0 additions & 90 deletions src/v2/routes/auth/authRoute.ts

This file was deleted.

47 changes: 47 additions & 0 deletions src/v2/routes/auth/authRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Hono } from "hono"
import { login } from "./login"
import { logout } from "./logout"
import { signup } from "./signup"
import { cors } from "hono/cors"
import { validate } from "./validate"
import assetCategoryRoute from "./asset-categories/assetCategoryRoutes"
import assetRoute from "./assets/assetRoutes"
import ocGeneratorRoute from "./oc-generators/ocGeneratorRoutes"
import gameRoute from "./games/gameRoutes"
import tagRoute from "./tags/tagRoutes"
import userAttributesRoute from "./user-attributes/userAttributesRoutes"

const authRoute = new Hono<{ Bindings: Bindings }>()

authRoute.use(
"*",
cors({
credentials: true,
origin: ["http://localhost:3000"], // TODO: update this - temporary
})
)

authRoute.post("/login", async (c) => {
return login(c)
})

authRoute.get("/validate", async (c) => {
return validate(c)
})

authRoute.post("/logout", async (c) => {
return logout(c)
})

authRoute.post("/signup", async (c) => {
return signup(c)
})

authRoute.route("/assets", assetRoute)
authRoute.route("/asset-categories", assetCategoryRoute)
authRoute.route("/oc-generators", ocGeneratorRoute)
authRoute.route("/games", gameRoute)
authRoute.route("/tags", tagRoute)
authRoute.route("/user-attributes", userAttributesRoute)

export default authRoute
24 changes: 24 additions & 0 deletions src/v2/routes/auth/games/gameRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createGame } from "./createGame"
import { deleteGame } from "./deleteGame"
import { Hono } from "hono"
import { cors } from "hono/cors"

const gameRoute = new Hono<{ Bindings: Bindings }>()

gameRoute.use(
"*",
cors({
credentials: true,
origin: ["http://localhost:3000"], // TODO: update this - temporary
})
)

gameRoute.post("/create", async (c) => {
return createGame(c)
})

gameRoute.post("/delete", async (c) => {
return deleteGame(c)
})

export default gameRoute
29 changes: 29 additions & 0 deletions src/v2/routes/auth/oc-generators/ocGeneratorRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { saveOCGeneratorResponse } from "./saveOCGeneratorResponse"
import { deleteOCGeneratorResponse } from "./deleteOCGeneratorResponse"
import { viewOCGeneratorResponses } from "./viewOCGeneratorResponses"
import { Hono } from "hono"
import { cors } from "hono/cors"

const ocGeneratorRoute = new Hono<{ Bindings: Bindings }>()

ocGeneratorRoute.use(
"*",
cors({
credentials: true,
origin: ["http://localhost:3000"], // TODO: update this - temporary
})
)

ocGeneratorRoute.post("/save", async (c) => {
return saveOCGeneratorResponse(c)
})

ocGeneratorRoute.post("/delete", async (c) => {
return deleteOCGeneratorResponse(c)
})

ocGeneratorRoute.get("/all", async (c) => {
return viewOCGeneratorResponses(c)
})

export default ocGeneratorRoute
Loading

0 comments on commit 15d3ef1

Please sign in to comment.