Skip to content

Commit

Permalink
#9 | @Payne680 | Building the matching functionality for audio files …
Browse files Browse the repository at this point in the history
…and their respective languages
  • Loading branch information
Payne680 committed Aug 11, 2024
1 parent 909f2bd commit 78b84e1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/api/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
22 changes: 14 additions & 8 deletions src/api/v1/modules/match/match.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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",
});
};
}
13 changes: 1 addition & 12 deletions src/api/v1/modules/match/match.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,23 +29,15 @@ 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<any> {
if (!this.checkParams([id, label, this.token])) {
throw new Error("Missing required parameters");
}

try {
const claimData = await this.setClaim(id, label);

if (!claimData.claim || claimData.claim.id !== id) {
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);

Expand Down
3 changes: 1 addition & 2 deletions src/api/v1/routes/match-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 78b84e1

Please sign in to comment.