diff --git a/README.md b/README.md index 84418a4..4153e8f 100644 --- a/README.md +++ b/README.md @@ -67,9 +67,12 @@ The fastest way to use it privately on PaaS available Base URL : [`http://localhost:3000`](https://kodepos.vercel.app) -| Endpoint | Description | Parameter | Method | -| ---------------------------------------------- | ------------------------------- | --------- | ------ | -| [`/search`](https://kodepos.vercel.app/search) | To find postcode using keywords | `q` | `GET` | +| Endpoint | Description | Parameter | Method | +| ---------------------------------------------- | ------------------------------- | ---------- | ------ | +| [`/search`](https://kodepos.vercel.app/search) | To find postcode using keywords | `q` | `GET` | +| | | `province` | `GET` | +| | | `regency` | `GET` | +| | | `district` | `GET` | ### Example of Use diff --git a/src/controllers/search.ts b/src/controllers/search.ts index 1ae4adc..0ea8a73 100644 --- a/src/controllers/search.ts +++ b/src/controllers/search.ts @@ -1,17 +1,17 @@ +import { KeywordOptions } from '../types' +import { createSpecResponse } from '../utils/spec' import { search as scrape } from '../utils/kodepos' -import { createSpecResponse, sendNotFound } from '../utils/spec' import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify' export const search = (app: FastifyInstance) => { - return async (request: FastifyRequest<{ Querystring: { q: string } }>, reply: FastifyReply) => { - const { q } = request.query - - if (typeof q === 'undefined' || q.trim() === '') { - return sendNotFound(reply) - } + return async ( + request: FastifyRequest<{ Querystring: KeywordOptions & { q: string } }>, + reply: FastifyReply + ) => { + const { q, province, regency, district } = request.query const provider = app.providers.next() - const result = await scrape({ query: q }, provider.value) + const result = await scrape({ query: q, province, regency, district }, provider.value) const response = createSpecResponse(result) return reply.send(response) diff --git a/src/core.ts b/src/core.ts index e0c788d..bfe2e77 100644 --- a/src/core.ts +++ b/src/core.ts @@ -6,7 +6,7 @@ import type { FastifyInstance, FastifyPluginOptions } from 'fastify' const load = async (app: FastifyInstance, _: FastifyPluginOptions) => { const providers = new SequentialRoundRobin([ { hostname: 'direktorikodepos.org', segment: 'wilayah' }, - { hostname: 'nomorkodepos.com', segment: 'di' }, + { hostname: 'carikodepos.com', segment: 'daerah' }, ]) app.decorate('providers', providers)