From 78b84e155a20fca32c8039adb25fdaf72db070e8 Mon Sep 17 00:00:00 2001 From: PENN JR Date: Sun, 11 Aug 2024 18:10:42 +0100 Subject: [PATCH] #9 | @Payne680 | Building the matching functionality for audio files and their respective languages --- src/api/v1/index.ts | 2 +- src/api/v1/modules/match/match.controller.ts | 22 +++++++++++++------- src/api/v1/modules/match/match.service.ts | 13 +----------- src/api/v1/routes/match-router.ts | 3 +-- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/api/v1/index.ts b/src/api/v1/index.ts index 1b9376d..212bed4 100644 --- a/src/api/v1/index.ts +++ b/src/api/v1/index.ts @@ -13,6 +13,6 @@ routerV1.get("/", (_, res) => { routerV1.use("/auth", authRouter); routerV1.use("/languages", languageRouter); -routerV1.use("/match", matchRouter); +routerV1.use("/match/publish", matchRouter); export default routerV1; diff --git a/src/api/v1/modules/match/match.controller.ts b/src/api/v1/modules/match/match.controller.ts index 161b8f8..d11abd6 100644 --- a/src/api/v1/modules/match/match.controller.ts +++ b/src/api/v1/modules/match/match.controller.ts @@ -8,15 +8,15 @@ export class MatchController { this.matchService = new MatchService(); } - list: RequestHandler = (req, res) => { - return res.status(200).json({ - message: "return dictionaries", - }); - }; + public processMatch: RequestHandler = async (req, res) => { + const { id, label } = req.body; - processMatch: RequestHandler = async (req, res) => { - const { id } = req.body; - const { label } = req.body; + // Validate the parameters + if (!id || !label) { + return res + .status(400) + .json({ error: "Missing required parameters: id and label" }); + } try { const result = await this.matchService.processMatch(id, label); @@ -25,4 +25,10 @@ export class MatchController { return res.status(500).json({ error: error.message }); } }; + + public list: RequestHandler = (req, res) => { + return res.status(200).json({ + message: "return dictionaries", + }); + }; } diff --git a/src/api/v1/modules/match/match.service.ts b/src/api/v1/modules/match/match.service.ts index f2ebbb6..67e8789 100644 --- a/src/api/v1/modules/match/match.service.ts +++ b/src/api/v1/modules/match/match.service.ts @@ -2,9 +2,6 @@ import axios from "axios"; import { v4 as uuidv4 } from "uuid"; const API_BASE_URL = "https://www.wikidata.org/w/api.php"; -interface ClientRequestBody { - label: string; -} interface ClaimRequest { id: string; @@ -32,15 +29,7 @@ export class MatchService { this.token = "your_token_here"; // user token } - private checkParams(params: any[]): boolean { - return params.every((param) => param); - } - public async processMatch(id: string, label: string): Promise { - if (!this.checkParams([id, label, this.token])) { - throw new Error("Missing required parameters"); - } - try { const claimData = await this.setClaim(id, label); @@ -48,7 +37,7 @@ export class MatchService { throw new Error("ID does not match the claim"); } - const claimIdWithUUID = `${claimData.claim.id}-${uuidv4()}`; + const claimIdWithUUID = `${claimData.claim.id}$${uuidv4()}`; const qualifierData = await this.addQualifier(claimIdWithUUID); diff --git a/src/api/v1/routes/match-router.ts b/src/api/v1/routes/match-router.ts index 3ee8335..10c2353 100644 --- a/src/api/v1/routes/match-router.ts +++ b/src/api/v1/routes/match-router.ts @@ -5,7 +5,6 @@ const router = Router(); const matchController = new MatchController(); -router.get("/", matchController.list.bind(matchController)); -router.post("/match/publish", matchController.processMatch); +router.post("/", matchController.processMatch); export const matchRouter = router;