Skip to content

Commit

Permalink
Added search route
Browse files Browse the repository at this point in the history
  • Loading branch information
jzongker committed Jan 27, 2025
1 parent fd18dab commit 61cdfae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/controllers/BibleController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import { BibleTranslation, BibleVerseText } from "../models";
@controller("/bibles")
export class BibleController extends ContentBaseController {

@httpGet("/:translationKey/search")
public async search(@requestParam("translationKey") translationKey: string, req: express.Request<{}, {}, null>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapperAnon(req, res, async () => {
const query = req.query.query as string;
const result = await ApiBibleHelper.search(translationKey, query);
return result;
});
}

@httpGet("/:translationKey/books")
public async getBooks(@requestParam("translationKey") translationKey: string, req: express.Request<{}, {}, null>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapperAnon(req, res, async () => {
Expand Down
7 changes: 7 additions & 0 deletions src/helpers/ApiBibleHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export class ApiBibleHelper {
return result;
}

static async search(translationKey: string, query: string) {
const url = this.baseUrl + "/bibles/" + translationKey + "/search?query=" + encodeURIComponent(query);
const data = await this.getContent(url);

return data;
}

static async getBooks(translationKey: string) {
const result: BibleBook[] = [];
const url = this.baseUrl + "/bibles/" + translationKey + "/books";
Expand Down

0 comments on commit 61cdfae

Please sign in to comment.