Commit c24e5de2 authored by Цой Данил's avatar Цой Данил 💬

#4 added functions to post, and get tracks by their ids and what was added inside input

parent 0bc634c4
......@@ -23,8 +23,8 @@ export class AlbumsController {
constructor() {
this.router = express.Router()
this.service = albumsService
this.router.get('/', this.getAlbumsHandler)
this.router.get('/:id', this.getAlbumsHandler)
this.router.get('/', this.getAlbums)
this.router.get('/:id', this.getAlbums)
this.router.post('/', upload.single('coverImage'), this.addAlbum)
}
......@@ -32,7 +32,7 @@ export class AlbumsController {
return this.router;
}
private getAlbumsHandler = async (req: Request, res: Response): Promise<void> => {
private getAlbums = async (req: Request, res: Response): Promise<void> => {
const response = await this.service.getAlbums(req)
if (response.status === EStatuses.FAILURE){
res.status(418).send(response)
......
import express, { Request, Response, Router } from "express";
import { EStatuses } from "../enum/EStatuses";
import ITrackDto from "../interfaces/ITrackDto";
import { tracksService, TracksService } from "../services/tracksService";
export class TracksController {
private router: Router
private service: TracksService
constructor() {
this.router = express.Router()
this.service = tracksService
this.router.get('/', this.getTracks)
this.router.post('/', this.addTrack)
}
getRouter () {
return this.router;
}
private getTracks = async (req: Request, res: Response) => {
const response = await this.service.getTracks(req)
if (response.status === EStatuses.FAILURE){
res.status(418).send(response)
} else{
res.send(response)
}
}
private addTrack = async (req: Request, res: Response) => {
const trackDto: ITrackDto = req.body
const response = await this.service.addTrack(trackDto)
if (response.status === EStatuses.FAILURE){
res.status(418).send(response)
} else{
res.send(response)
}
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ import { HealthCheckController } from "./controllers/healthCheck";
import { mongooseDB } from "./repository/mongooseDB";
import { ArtistsController } from "./controllers/artistsController";
import { AlbumsController } from "./controllers/albumsController";
import { TracksController } from "./controllers/tracksController";
dotenv.config()
......@@ -22,6 +23,7 @@ class App {
this.app.use('/health-check', new HealthCheckController().getRouter())
this.app.use('/artists', new ArtistsController().getRouter())
this.app.use('/albums', new AlbumsController().getRouter())
this.app.use('/tracks', new TracksController().getRouter())
this.app.listen(process.env.APP_PORT, () => {
console.log(`Server is running on http://localhost:${process.env.APP_PORT}`)
})
......
......@@ -54,4 +54,6 @@ export class TracksService {
return response
}
}
}
\ No newline at end of file
}
export const tracksService = new TracksService()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment