-
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(core-data): add endpoint banner & activity from Core Data (#7)
- Loading branch information
1 parent
4e7b90a
commit bb01906
Showing
9 changed files
with
127 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import winston from 'winston' | ||
import { Config } from '../../config/config.interface' | ||
import CoreData from '../../external/coreData' | ||
import Http from '../../transport/http/http' | ||
import Handler from './delivery/http/handler' | ||
import Usecase from './usecase/usecase' | ||
|
||
class Core { | ||
constructor( | ||
private http: Http, | ||
private logger: winston.Logger, | ||
private config: Config | ||
) { | ||
const coreData = new CoreData(config, logger) | ||
const usecase = new Usecase(coreData, logger) | ||
|
||
this.loadHttp(usecase) | ||
} | ||
|
||
private loadHttp(usecase: Usecase) { | ||
const handler = new Handler(usecase, this.logger) | ||
this.http.app.get('/v1/banners', handler.Banner()) | ||
this.http.app.get('/v1/activities', handler.Activity()) | ||
this.http.app.get('/v1/activities/:id', handler.ActivityByID()) | ||
} | ||
} | ||
|
||
export default Core |
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,51 @@ | ||
import { NextFunction, Response } from 'express' | ||
import winston from 'winston' | ||
import Usecase from '../../usecase/usecase' | ||
import statusCode from '../../../../pkg/statusCode' | ||
import { | ||
ValidateFormRequest, | ||
} from '../../../../helpers/validate' | ||
import { Activity } from '../../entity/schema' | ||
|
||
class Handler { | ||
constructor(private usecase: Usecase, private logger: winston.Logger) {} | ||
public Banner() { | ||
return async (req: any, res: Response, next: NextFunction) => { | ||
try { | ||
const result = await this.usecase.Banner() | ||
return res.status(statusCode.OK).json({ | ||
data: result, | ||
}) | ||
} catch (error) { | ||
return next(error) | ||
} | ||
} | ||
} | ||
public Activity() { | ||
return async (req: any, res: Response, next: NextFunction) => { | ||
try { | ||
const value = ValidateFormRequest(Activity, req.query) | ||
const result = await this.usecase.Activity(value) | ||
return res.status(statusCode.OK).json({ | ||
data: result, | ||
}) | ||
} catch (error) { | ||
return next(error) | ||
} | ||
} | ||
} | ||
public ActivityByID() { | ||
return async (req: any, res: Response, next: NextFunction) => { | ||
try { | ||
const result = await this.usecase.ActivityByID(req.params.id) | ||
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,4 @@ | ||
export interface Activity { | ||
start_date: string | ||
end_date: string | ||
} |
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,6 @@ | ||
import Joi from 'joi' | ||
|
||
export const Activity = Joi.object({ | ||
start_date: Joi.string().isoDate().required(), | ||
end_date: Joi.string().isoDate().required(), | ||
}) |
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,27 @@ | ||
import winston from 'winston' | ||
import CoreData from '../../../external/coreData' | ||
import { Activity } from '../entity/interface' | ||
|
||
class Usecase { | ||
constructor(private coreData: CoreData, private logger: winston.Logger) {} | ||
|
||
public async Banner() { | ||
const res = await this.coreData.Banner() | ||
|
||
return res | ||
} | ||
|
||
public async Activity({ start_date, end_date }: Activity) { | ||
const res = await this.coreData.Activity(start_date, end_date) | ||
|
||
return res | ||
} | ||
|
||
public async ActivityByID(id: string) { | ||
const res = await this.coreData.ActivityById(id) | ||
|
||
return res | ||
} | ||
} | ||
|
||
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