Compare commits
No commits in common. "624ea6ba33f5339e0898f2beb29d31591a91947a" and "d85c126c276a91996178ccf8b8e7a566d33dac69" have entirely different histories.
624ea6ba33
...
d85c126c27
@ -4,7 +4,6 @@ import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
|||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
||||||
import { Track } from '../models/Track';
|
import { Track } from '../models/Track';
|
||||||
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
|
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
|
||||||
import {TrackIdChangeNotAllowedError, TrackNotFoundError} from "../errors/TrackErrors";
|
|
||||||
|
|
||||||
class CreateTrack {
|
class CreateTrack {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -16,6 +15,12 @@ class CreateTrack {
|
|||||||
length: number;
|
length: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class TrackNotFoundError extends NotFoundError {
|
||||||
|
constructor() {
|
||||||
|
super('Track not found!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JsonController('/tracks')
|
@JsonController('/tracks')
|
||||||
@Authorized("TRACKS:read")
|
@Authorized("TRACKS:read")
|
||||||
export class TrackController {
|
export class TrackController {
|
||||||
@ -37,7 +42,6 @@ export class TrackController {
|
|||||||
|
|
||||||
@Get('/:id')
|
@Get('/:id')
|
||||||
@ResponseSchema(Track)
|
@ResponseSchema(Track)
|
||||||
@ResponseSchema(TrackNotFoundError, {statusCode: 404})
|
|
||||||
@OnUndefined(TrackNotFoundError)
|
@OnUndefined(TrackNotFoundError)
|
||||||
@OpenAPI({ description: "Returns a track of a specified id (if it exists)" })
|
@OpenAPI({ description: "Returns a track of a specified id (if it exists)" })
|
||||||
getOne(@Param('id') id: number) {
|
getOne(@Param('id') id: number) {
|
||||||
@ -56,8 +60,6 @@ export class TrackController {
|
|||||||
|
|
||||||
@Put('/:id')
|
@Put('/:id')
|
||||||
@ResponseSchema(Track)
|
@ResponseSchema(Track)
|
||||||
@ResponseSchema(TrackNotFoundError, {statusCode: 404})
|
|
||||||
@ResponseSchema(TrackIdChangeNotAllowedError, {statusCode: 406})
|
|
||||||
@OpenAPI({ description: "Update a track object (id can't be changed)." })
|
@OpenAPI({ description: "Update a track object (id can't be changed)." })
|
||||||
async put(@Param('id') id: number, @EntityFromBody() track: Track) {
|
async put(@Param('id') id: number, @EntityFromBody() track: Track) {
|
||||||
let oldTrack = await this.trackRepository.findOne({ id: id });
|
let oldTrack = await this.trackRepository.findOne({ id: id });
|
||||||
@ -67,7 +69,7 @@ export class TrackController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (oldTrack.id != track.id) {
|
if (oldTrack.id != track.id) {
|
||||||
throw new TrackIdChangeNotAllowedError();
|
throw new NotAcceptableError("The id's don't match!");
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.trackRepository.update(oldTrack, track);
|
await this.trackRepository.update(oldTrack, track);
|
||||||
@ -76,7 +78,6 @@ export class TrackController {
|
|||||||
|
|
||||||
@Delete('/:id')
|
@Delete('/:id')
|
||||||
@ResponseSchema(Track)
|
@ResponseSchema(Track)
|
||||||
@ResponseSchema(TrackNotFoundError, {statusCode: 404})
|
|
||||||
@OpenAPI({ description: "Delete a specified track (if it exists)." })
|
@OpenAPI({ description: "Delete a specified track (if it exists)." })
|
||||||
async remove(@Param('id') id: number) {
|
async remove(@Param('id') id: number) {
|
||||||
let track = await this.trackRepository.findOne({ id: id });
|
let track = await this.trackRepository.findOne({ id: id });
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
import { JsonController, Param, Body, Get, Post, Put, Delete, NotFoundError, OnUndefined, NotAcceptableError } from 'routing-controllers';
|
|
||||||
import { IsInt, IsNotEmpty, IsPositive, IsString } from 'class-validator';
|
|
||||||
|
|
||||||
export class TrackNotFoundError extends NotFoundError {
|
|
||||||
@IsString()
|
|
||||||
name = "TrackNotFoundError"
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
message = "Track not found!"
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TrackIdChangeNotAllowedError extends NotAcceptableError {
|
|
||||||
@IsString()
|
|
||||||
name = "TrackIdChangeNotAllowed"
|
|
||||||
|
|
||||||
@IsString()
|
|
||||||
message = "The id's don't match!!"
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user