-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folder / File - Service, Controller, Route, Test files (#32)
- Loading branch information
Showing
16 changed files
with
330 additions
and
220 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,4 +1,5 @@ | ||
{ | ||
"**/*.{js,jsx,scss,json,md}": "prettier --write", | ||
"**/*.{js,jsx}": "eslint --fix --max-warnings=0" | ||
"fe/**/*.{js,jsx}": "eslint --fix --max-warnings=0", | ||
"be/**/*.{js,jsx}": "eslint --fix --max-warnings=0" | ||
} |
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,62 @@ | ||
import { FileService } from '../services/file.service.js' | ||
|
||
export class FilesController { | ||
get file() { | ||
return new FileService() | ||
} | ||
|
||
getFiles = async (req, res, next) => { | ||
try { | ||
const findAllFilesData = await this.file.findAllFile() | ||
|
||
res.status(200).json({ data: findAllFilesData, message: 'findAll' }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
|
||
getFileById = async (req, res, next) => { | ||
try { | ||
const fileId = Number(req.params.id) | ||
const findOneFileData = await this.file.findFileById(fileId) | ||
|
||
res.status(200).json({ data: findOneFileData, message: 'findOne' }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
|
||
createFile = async (req, res, next) => { | ||
try { | ||
const fileData = req.body | ||
const createFileData = await this.file.createFile(fileData) | ||
|
||
res.status(201).json({ data: createFileData, message: 'created' }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
|
||
updateFile = async (req, res, next) => { | ||
try { | ||
const fileId = Number(req.params.id) | ||
const fileData = req.body | ||
const updateFileData = await this.file.updateFile(fileId, fileData) | ||
|
||
res.status(200).json({ data: updateFileData, message: 'updated' }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
|
||
deleteFile = async (req, res, next) => { | ||
try { | ||
const fileId = Number(req.params.id) | ||
const deleteFileData = await this.file.deleteFile(fileId) | ||
|
||
res.status(200).json({ data: deleteFileData, message: 'deleted' }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
} |
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,65 @@ | ||
import { FolderService } from '../services/folder.service.js' | ||
|
||
export class FoldersController { | ||
get folder() { | ||
return new FolderService() | ||
} | ||
|
||
getFolders = async (req, res, next) => { | ||
try { | ||
const findAllFoldersData = await this.folder.findAllFolder() | ||
|
||
res.status(200).json({ data: findAllFoldersData, message: 'findAll' }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
|
||
getFolderById = async (req, res, next) => { | ||
try { | ||
const folderId = Number(req.params.id) | ||
const findOneFolderData = await this.folder.findFolderById(folderId) | ||
|
||
res.status(200).json({ data: findOneFolderData, message: 'findOne' }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
|
||
createFolder = async (req, res, next) => { | ||
try { | ||
const folderData = req.body | ||
const createFolderData = await this.folder.createFolder(folderData) | ||
|
||
res.status(201).json({ data: createFolderData, message: 'created' }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
|
||
updateFolder = async (req, res, next) => { | ||
try { | ||
const folderId = Number(req.params.id) | ||
const folderData = req.body | ||
const updateFolderData = await this.folder.updateFolder( | ||
folderId, | ||
folderData | ||
) | ||
|
||
res.status(200).json({ data: updateFolderData, message: 'updated' }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
|
||
deleteFolder = async (req, res, next) => { | ||
try { | ||
const folderId = Number(req.params.id) | ||
const deleteFolderData = await this.folder.deleteFolder(folderId) | ||
|
||
res.status(200).json({ data: deleteFolderData, message: 'deleted' }) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
import { Router } from 'express' | ||
import { FilesController } from '../controllers/files.controller.js' | ||
|
||
const router = Router() | ||
|
||
export class FileRoute { | ||
get path() { | ||
return '/files' | ||
} | ||
get router() { | ||
return router | ||
} | ||
|
||
get file() { | ||
return new FilesController() | ||
} | ||
|
||
constructor() { | ||
this.initializeRoutes() | ||
} | ||
|
||
async initializeRoutes() { | ||
this.router.get(`${this.path}`, await this.file.getFiles) | ||
this.router.get(`${this.path}/:id(\\d+)`, this.file.getFileById) | ||
this.router.post(`${this.path}`, this.file.createFile) | ||
this.router.put(`${this.path}/:id(\\d+)`, this.file.updateFile) | ||
this.router.delete(`${this.path}/:id(\\d+)`, this.file.deleteFile) | ||
} | ||
} |
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,29 @@ | ||
import { Router } from 'express' | ||
import { FoldersController } from '../controllers/folders.controller.js' | ||
|
||
const router = Router() | ||
|
||
export class FolderRoute { | ||
get path() { | ||
return '/folders' | ||
} | ||
get router() { | ||
return router | ||
} | ||
|
||
get folder() { | ||
return new FoldersController() | ||
} | ||
|
||
constructor() { | ||
this.initializeRoutes() | ||
} | ||
|
||
async initializeRoutes() { | ||
this.router.get(`${this.path}`, await this.folder.getFolders) | ||
this.router.get(`${this.path}/:id(\\d+)`, this.folder.getFolderById) | ||
this.router.post(`${this.path}`, this.folder.createFolder) | ||
this.router.put(`${this.path}/:id(\\d+)`, this.folder.updateFolder) | ||
this.router.delete(`${this.path}/:id(\\d+)`, this.folder.deleteFolder) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.