Compare commits
No commits in common. "b267d87ba66e19e61fc04a64dee5056e3cad91e5" and "24d890f638b2298ac2588786897490797a405ee5" have entirely different histories.
b267d87ba6
...
24d890f638
@ -1,7 +1,7 @@
|
|||||||
import { JsonController, Param, Body, Get, Post, Put, Delete, NotFoundError, OnUndefined, NotAcceptableError } from 'routing-controllers';
|
import { JsonController, Param, Body, Get, Post, Put, Delete, NotFoundError, OnUndefined } from 'routing-controllers';
|
||||||
import { getConnectionManager, Repository } from 'typeorm';
|
import { getConnectionManager, Repository } from 'typeorm';
|
||||||
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
import { EntityFromBody } from 'typeorm-routing-controllers-extensions';
|
||||||
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
|
import { 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';
|
||||||
|
|
||||||
@ -25,16 +25,12 @@ export class TrackNotFoundError extends NotFoundError {
|
|||||||
export class TrackController {
|
export class TrackController {
|
||||||
private trackRepository: Repository<Track>;
|
private trackRepository: Repository<Track>;
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the repository of this controller's model/entity.
|
|
||||||
*/
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.trackRepository = getConnectionManager().get().getRepository(Track);
|
this.trackRepository = getConnectionManager().get().getRepository(Track);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ResponseSchema(Track, { isArray: true })
|
@ResponseSchema(Track, { isArray: true })
|
||||||
@OpenAPI({description: "Lists all tracks."})
|
|
||||||
getAll() {
|
getAll() {
|
||||||
return this.trackRepository.find();
|
return this.trackRepository.find();
|
||||||
}
|
}
|
||||||
@ -42,14 +38,12 @@ export class TrackController {
|
|||||||
@Get('/:id')
|
@Get('/:id')
|
||||||
@ResponseSchema(Track)
|
@ResponseSchema(Track)
|
||||||
@OnUndefined(TrackNotFoundError)
|
@OnUndefined(TrackNotFoundError)
|
||||||
@OpenAPI({description: "Returns a track of a specified id (if it exists)"})
|
|
||||||
getOne(@Param('id') id: number) {
|
getOne(@Param('id') id: number) {
|
||||||
return this.trackRepository.findOne({ id: id });
|
return this.trackRepository.findOne({ id: id });
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
@ResponseSchema(Track)
|
@ResponseSchema(Track)
|
||||||
@OpenAPI({description: "Create a new track object (id will be generated automagicly)."})
|
|
||||||
post(
|
post(
|
||||||
@Body({ validate: true })
|
@Body({ validate: true })
|
||||||
track: CreateTrack
|
track: CreateTrack
|
||||||
@ -59,7 +53,6 @@ export class TrackController {
|
|||||||
|
|
||||||
@Put('/:id')
|
@Put('/:id')
|
||||||
@ResponseSchema(Track)
|
@ResponseSchema(Track)
|
||||||
@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 });
|
||||||
|
|
||||||
@ -73,7 +66,7 @@ export class TrackController {
|
|||||||
|
|
||||||
@Delete('/:id')
|
@Delete('/:id')
|
||||||
@ResponseSchema(Track)
|
@ResponseSchema(Track)
|
||||||
@OpenAPI({description: "Delete a specified track (if it exists)."})
|
@OnUndefined(TrackNotFoundError)
|
||||||
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 });
|
||||||
|
|
||||||
|
@ -7,12 +7,6 @@ import {
|
|||||||
IsString,
|
IsString,
|
||||||
} from "class-validator";
|
} from "class-validator";
|
||||||
|
|
||||||
/**
|
|
||||||
* @classdesc Defines a track of given length.
|
|
||||||
* @property {number} id - Autogenerated unique id
|
|
||||||
* @property {string} name - The track's name
|
|
||||||
* @property {number} lenth - The track's length in meters
|
|
||||||
*/
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Track {
|
export class Track {
|
||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user