-
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.
- Loading branch information
1 parent
da916b1
commit a1814a2
Showing
11 changed files
with
190 additions
and
5 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 |
---|---|---|
@@ -1,19 +1,25 @@ | ||
const NoteController = require('./noteController') | ||
const SessionController = require('./sessionController') | ||
const TeamController = require('./teamController') | ||
|
||
class ControllersProvider { | ||
constructor (noteRepository, sessionRepository) { | ||
constructor (noteRepository, sessionRepository, teamRepository) { | ||
this.noteRepository = noteRepository | ||
this.sessionRepository = sessionRepository | ||
this.teamRepository = teamRepository | ||
} | ||
|
||
provideNotesController () { | ||
getNotesController () { | ||
return new NoteController(this.noteRepository) | ||
} | ||
|
||
getSessionsController () { | ||
return new SessionController(this.sessionRepository) | ||
} | ||
|
||
getTeamsController () { | ||
return new TeamController(this.teamRepository) | ||
} | ||
} | ||
|
||
module.exports = ControllersProvider |
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,53 @@ | ||
const Joi = require('joi') | ||
|
||
class TeamController { | ||
constructor (teamRepository) { | ||
this.teamRepository = teamRepository | ||
} | ||
|
||
async getTeams (team) { | ||
this.validateTeam(team) | ||
return this.teamRepository.getTeam(team) | ||
} | ||
|
||
async getTeam (team) { | ||
this.validateTeamId(team) | ||
return this.teamRepository.getTeam(team.getIdObject()) | ||
} | ||
|
||
async createTeam (team) { | ||
this.validateTeam(team) | ||
return this.teamRepository.createTeam(team.getTeam()) | ||
} | ||
|
||
async editTeam (team) { | ||
this.validateFullTeam(team) | ||
return this.teamRepository.editTeam(team.id, team.getTeam()) | ||
} | ||
|
||
async deleteTeam (team) { | ||
this.validateTeamId(team) | ||
return this.teamRepository.deleteTeam(team.id) | ||
} | ||
|
||
validateTeamId (team) { | ||
Joi.validate(team, Joi.object({ | ||
id: Joi.string().required() | ||
})) | ||
} | ||
|
||
validateFullTeam (team) { | ||
Joi.validate(team, Joi.object({ | ||
id: Joi.string().required(), | ||
topics: Joi.array().items(Joi.string()).required(), | ||
timestamp: Joi.date().timestamp().required() | ||
})) | ||
} | ||
|
||
validateTeam (team) { | ||
Joi.validate(team, Joi.object({ | ||
topics: Joi.array().items(Joi.string()).required() | ||
})) | ||
} | ||
} | ||
module.exports = TeamController |
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,24 @@ | ||
class Team { | ||
constructor (id, name, admin, members) { | ||
this.id = id | ||
this.name = name | ||
this.admin = admin | ||
this.members = members | ||
} | ||
|
||
getTeam () { | ||
return { | ||
name: this.name, | ||
admin: this.admin, | ||
members: this.members | ||
} | ||
} | ||
|
||
getIdObject () { | ||
return { | ||
id: this.id | ||
} | ||
} | ||
} | ||
|
||
module.exports = Team |
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,24 @@ | ||
class TeamRepository { | ||
constructor (db) { | ||
this.db = db | ||
this.table = 'teams' | ||
} | ||
|
||
async getTeam (team) { | ||
return this.db.executeGetDB(this.table, team) | ||
} | ||
|
||
async createTeam (team) { | ||
return this.db.executeInsert(this.table, team) | ||
} | ||
|
||
async deleteTeam (id) { | ||
return this.db.executeDelete(this.table, id) | ||
} | ||
|
||
async editTeam (id, team) { | ||
return this.db.executeUpdateDB(this.table, id, team) | ||
} | ||
} | ||
|
||
module.exports = TeamRepository |
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,43 @@ | ||
const express = require('express') | ||
const TeamMapper = require('./mapper') | ||
const Router = require('../router') | ||
|
||
class TeamRouter { | ||
constructor (teamController) { | ||
this.teamMapper = new TeamMapper() | ||
this.app = express() | ||
this.teamController = teamController | ||
this.genericRouter = new Router(this.teamMapper) | ||
} | ||
|
||
getRoutes () { | ||
this.app.get('/', (req, res) => { | ||
this.genericRouter.execute(this.teamController.getTeams | ||
.bind(this.teamController), req, res) | ||
}) | ||
|
||
this.app.get('/:id', (req, res) => { | ||
this.genericRouter.execute(this.teamController.getTeam | ||
.bind(this.teamController), req, res) | ||
}) | ||
|
||
this.app.post('/', (req, res) => { | ||
this.genericRouter.execute(this.teamController.createTeam | ||
.bind(this.teamController), req, res) | ||
}) | ||
|
||
this.app.put('/:id', (req, res) => { | ||
this.genericRouter.execute(this.teamController.editTeam | ||
.bind(this.teamController), req, res) | ||
}) | ||
|
||
this.app.delete('/:id', (req, res) => { | ||
this.genericRouter.execute(this.teamController.deleteTeam | ||
.bind(this.teamController), req, res) | ||
}) | ||
|
||
return this.app | ||
} | ||
} | ||
|
||
module.exports = TeamRouter |
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,22 @@ | ||
const Team = require('../../model/team') | ||
|
||
class TeamMapper { | ||
mapToDomain (req) { | ||
if (req.query.name !== undefined) { | ||
return new Team( | ||
null, | ||
req.query.name, | ||
null | ||
) | ||
} | ||
|
||
return new Team( | ||
req.params.id, | ||
req.body.name, | ||
req.body.admin, | ||
req.body.members | ||
) | ||
} | ||
} | ||
|
||
module.exports = TeamMapper |