generated from Greenstand/treetracker-microservice-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrated handler logic to separate folder
- Loading branch information
1 parent
96b3879
commit 730ca78
Showing
5 changed files
with
86 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const Session = require('../models/Session'); | ||
const RegionService = require('../services/RegionService'); | ||
|
||
const regionHandlerGet = async function (req, res, next) { | ||
const { ownerId } = req.query; | ||
const session = new Session(); | ||
const regionSerivce = new RegionService(session); | ||
const ownerRegions = regionSerivce.regionRepository.getAllByOwnerId(ownerId); | ||
res.status(200).json({ | ||
regions: ownerRegions, | ||
}); | ||
}; | ||
|
||
const regionHandlerGetByRegionId = async function (req, res, next) { | ||
const { regionId } = req.params; | ||
const session = new Session(); | ||
const regionSerivce = new RegionService(session); | ||
const region = regionSerivce.getById(regionId); | ||
res.status(200).json({ | ||
region, | ||
}); | ||
}; | ||
|
||
const regionHandlerPost = async function (req, res, next) { | ||
const region = req.body; | ||
const session = new Session(); | ||
const regionSerivce = new RegionService(session); | ||
const newRegion = await regionSerivce.createRegion(region); | ||
res.status(200).json({ | ||
region: newRegion, | ||
}); | ||
}; | ||
|
||
const regionHandlerPut = async function (req, res, next) { | ||
const { regionId } = req.params; | ||
const region = req.body; | ||
region.id = regionId; | ||
const session = new Session(); | ||
const regionSerivce = new RegionService(session); | ||
const updatedRegion = await regionSerivce.updateRegion(region); | ||
res.status(200).json({ | ||
region: updatedRegion, | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
regionHandlerGet, | ||
regionHandlerGetByRegionId, | ||
regionHandlerPost, | ||
regionHandlerPut, | ||
}; |
File renamed without changes.
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,31 @@ | ||
const express = require('express'); | ||
const { handlerWrapper } = require('./handlers/utils'); | ||
const { | ||
regionHandlerGet, | ||
regionHandlerGetByRegionId, | ||
regionHandlerPost, | ||
regionHandlerPut,} = require('./handlers/regionHandler') | ||
|
||
const router = express.Router(); | ||
|
||
router.get( | ||
'/', | ||
handlerWrapper(regionHandlerGet), | ||
); | ||
|
||
router.get( | ||
'/:regionId', | ||
handlerWrapper(regionHandlerGetByRegionId), | ||
); | ||
|
||
router.post( | ||
'/', | ||
handlerWrapper(regionHandlerPost), | ||
); | ||
|
||
router.put( | ||
'/:regionId', | ||
handlerWrapper(regionHandlerPut), | ||
); | ||
|
||
module.exports = router; |
This file was deleted.
Oops, something went wrong.