-
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(prayerTime): add endpoint prayer time by date (#4)
* feat(prayerTime): add endpoint prayer time by date * feat(prayerTime): changes by location to longlat
- Loading branch information
1 parent
a1a859c
commit 9aae3f4
Showing
21 changed files
with
116 additions
and
56 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
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
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
Empty file.
Empty file.
Empty file.
Empty file.
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,24 @@ | ||
import { NextFunction, Request, Response } from 'express' | ||
import winston from 'winston' | ||
import Usecase from '../../usecase/usecase' | ||
import { FindByDate } from '../../entity/schema' | ||
import { ValidateParams } from '../../../../helpers/validate' | ||
import statusCode from '../../../../pkg/statusCode' | ||
|
||
class Handler { | ||
constructor(private usecase: Usecase, private logger: winston.Logger) {} | ||
public FindByDate() { | ||
return async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const value = ValidateParams(FindByDate, req.params.date) | ||
|
||
const result = await this.usecase.FindByDate(value) | ||
return res.status(statusCode.OK).json({ data: result }) | ||
} catch (error) { | ||
return next(error) | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default Handler |
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,3 @@ | ||
export interface FindByDate { | ||
date: Date | ||
} |
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,3 @@ | ||
import Joi from 'joi' | ||
|
||
export const FindByDate = Joi.string().isoDate().required() |
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,26 @@ | ||
import winston from 'winston' | ||
import { Config } from '../../config/config.interface' | ||
import Http from '../../transport/http/http' | ||
import Handler from './delivery/http/handler' | ||
import Repository from './repository/mongo/repository' | ||
import Usecase from './usecase/usecase' | ||
|
||
class PrayerTime { | ||
constructor( | ||
private http: Http, | ||
private logger: winston.Logger, | ||
private config: Config | ||
) { | ||
const repository = new Repository(logger) | ||
const usecase = new Usecase(repository, logger) | ||
|
||
this.loadHttp(usecase) | ||
} | ||
|
||
private loadHttp(usecase: Usecase) { | ||
const handler = new Handler(usecase, this.logger) | ||
this.http.app.get('/v1/prayer-times/:date', handler.FindByDate()) | ||
} | ||
} | ||
|
||
export default PrayerTime |
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,13 @@ | ||
import winston from 'winston' | ||
import prayerTimesSchema from '../../../../database/mongo/schema/prayerTimes.schema' | ||
|
||
class Repository { | ||
private prayerTime = prayerTimesSchema | ||
constructor(private logger: winston.Logger) {} | ||
|
||
public async FindByDate(date: Date) { | ||
return this.prayerTime.findOne({ date }) | ||
} | ||
} | ||
|
||
export default Repository |
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,23 @@ | ||
import winston from 'winston' | ||
import { Translate } from '../../../helpers/translate' | ||
import error from '../../../pkg/error' | ||
import statusCode from '../../../pkg/statusCode' | ||
import Repository from '../repository/mongo/repository' | ||
|
||
class Usecase { | ||
constructor( | ||
private repository: Repository, | ||
private logger: winston.Logger | ||
) {} | ||
|
||
public async FindByDate(date: Date) { | ||
const item = await this.repository.FindByDate(date) | ||
|
||
if (!item) | ||
throw new error(statusCode.NOT_FOUND, Translate('not_found', {})) | ||
|
||
return item | ||
} | ||
} | ||
|
||
export default Usecase |
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 +1,3 @@ | ||
{} | ||
{ | ||
"not_found": "Not Found!" | ||
} |
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