generated from rakenduste-programmeerimine-2024/template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor entity routes to use userId from request (#27)
Closes #27
- Loading branch information
1 parent
7452fa8
commit 20a7397
Showing
19 changed files
with
86 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { createRouteHandler } from "@/utils/api/create-route-handler" | ||
import { getCurrentUserId } from "@/utils/api/user-utils" | ||
import CombatLogService from "@/lib/services/combat-log-service" | ||
|
||
// HARD DELETE a single combat log by ID | ||
export const DELETE = createRouteHandler(async (id, userId) => { | ||
export const DELETE = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const deletedCombatLog = await CombatLogService.hardDelete(id!, userId) | ||
return deletedCombatLog | ||
}) |
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 |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import { createRouteHandler } from "@/utils/api/create-route-handler" | ||
import { getCurrentUserId } from "@/utils/api/user-utils" | ||
import CombatLogService from "@/lib/services/combat-log-service" | ||
|
||
// GET a single combat log by ID | ||
export const GET = createRouteHandler(async (id, userId) => { | ||
export const GET = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const combatLog = await CombatLogService.get(id!, userId) | ||
return combatLog | ||
}) | ||
|
||
// UPDATE a single combat log by ID | ||
export const PUT = createRouteHandler(async (id, userId, req) => { | ||
export const PUT = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const updates = await req!.json() | ||
const updatedCombatLog = await CombatLogService.update(id!, updates, userId) | ||
return updatedCombatLog | ||
}) | ||
|
||
// SOFT DELETE a single combat log by ID | ||
export const DELETE = createRouteHandler(async (id, userId) => { | ||
export const DELETE = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const deletedCombatLog = await CombatLogService.softDelete(id!, userId) | ||
return deletedCombatLog | ||
}) |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { createRouteHandler } from "@/utils/api/create-route-handler" | ||
import { getCurrentUserId } from "@/utils/api/user-utils" | ||
import EncounterService from "@/lib/services/encounter-service" | ||
|
||
// HARD DELETE a single encounter by ID | ||
export const DELETE = createRouteHandler(async (id, userId) => { | ||
export const DELETE = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const deletedEncounter = await EncounterService.hardDelete(id!, userId) | ||
return deletedEncounter | ||
}) |
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 |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import { createRouteHandler } from "@/utils/api/create-route-handler" | ||
import { getCurrentUserId } from "@/utils/api/user-utils" | ||
import EncounterService from "@/lib/services/encounter-service" | ||
|
||
// GET a single encounter by ID | ||
export const GET = createRouteHandler(async (id, userId) => { | ||
export const GET = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const encounter = await EncounterService.get(id!, userId) | ||
return encounter | ||
}) | ||
|
||
// UPDATE a single encounter by ID | ||
export const PUT = createRouteHandler(async (id, userId, req) => { | ||
export const PUT = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const updates = await req!.json() | ||
const updatedEncounter = await EncounterService.update(id!, updates, userId) | ||
return updatedEncounter | ||
}) | ||
|
||
// SOFT DELETE a single encounter by ID | ||
export const DELETE = createRouteHandler(async (id, userId) => { | ||
export const DELETE = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const deletedEncounter = await EncounterService.softDelete(id!, userId) | ||
return deletedEncounter | ||
}) |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { createRouteHandler } from "@/utils/api/create-route-handler" | ||
import { getCurrentUserId } from "@/utils/api/user-utils" | ||
import ParticipantService from "@/lib/services/participant-service" | ||
|
||
// HARD DELETE a single participant by ID | ||
export const DELETE = createRouteHandler(async (id, userId) => { | ||
export const DELETE = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const deletedParticipant = await ParticipantService.hardDelete(id!, userId) | ||
return deletedParticipant | ||
}) |
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
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { createRouteHandler } from "@/utils/api/create-route-handler" | ||
import { getCurrentUserId } from "@/utils/api/user-utils" | ||
import StatBlockService from "@/lib/services/stat-block-service" | ||
|
||
// HARD DELETE a single stat block by ID | ||
export const DELETE = createRouteHandler(async (id, userId) => { | ||
export const DELETE = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const deletedStatBlock = await StatBlockService.hardDelete(id!, userId) | ||
return deletedStatBlock | ||
}) |
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 |
---|---|---|
@@ -1,21 +1,25 @@ | ||
import { createRouteHandler } from "@/utils/api/create-route-handler" | ||
import { getCurrentUserId } from "@/utils/api/user-utils" | ||
import StatBlockService from "@/lib/services/stat-block-service" | ||
|
||
// GET a single stat block by ID | ||
export const GET = createRouteHandler(async (id, userId) => { | ||
export const GET = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const statBlock = await StatBlockService.get(id!, userId) | ||
return statBlock | ||
}) | ||
|
||
// UPDATE a single stat block by ID | ||
export const PUT = createRouteHandler(async (id, userId, req) => { | ||
export const PUT = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const updates = await req!.json() | ||
const updatedStatBlock = await StatBlockService.update(id!, updates, userId) | ||
return updatedStatBlock | ||
}) | ||
|
||
// SOFT DELETE a single stat block by ID | ||
export const DELETE = createRouteHandler(async (id, userId) => { | ||
export const DELETE = createRouteHandler(async (id, req) => { | ||
const userId = await getCurrentUserId(req) | ||
const deletedStatBlock = await StatBlockService.softDelete(id!, userId) | ||
return deletedStatBlock | ||
}) |
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,9 @@ | ||
import { getUserIdFromRequest } from "@/middleware" | ||
|
||
export async function getCurrentUserId(req: Request): Promise<string> { | ||
const userId = await getUserIdFromRequest(req) | ||
if (!userId) { | ||
throw new Error("Unauthorized") | ||
} | ||
return userId | ||
} |