Skip to content

Commit

Permalink
schiffe backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Huschenhöfer authored and Christoph Huschenhöfer committed Jul 14, 2021
1 parent 4e58e9c commit cf6640f
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { AppController } from './app.controller'
import { AppService } from './app.service'
import { AuthModule } from './auth/auth.module'
import { UsersModule } from './users/users.module'
import { SchiffeModule } from './schiffe/schiffe.module';

@Module({
imports: [AuthModule, UsersModule],
imports: [AuthModule, UsersModule, SchiffeModule],
controllers: [AppController],
providers: [AppService],
})
Expand Down
9 changes: 9 additions & 0 deletions src/schiffe/model/position.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApiProperty } from "@nestjs/swagger"

export class Position {
@ApiProperty()
latitude: number

@ApiProperty()
longitude: number
}
13 changes: 13 additions & 0 deletions src/schiffe/model/schiffslocation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ApiProperty } from '@nestjs/swagger';
import { Position } from './position';

export class SchiffsLocation {
@ApiProperty()
id: string

@ApiProperty()
name: string

@ApiProperty()
position: Position
}
39 changes: 39 additions & 0 deletions src/schiffe/schiffe.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { ApiParam } from '@nestjs/swagger';
import { Position } from './model/position';
import { SchiffsLocation } from './model/schiffslocation';
import { SchiffeService } from './schiffe.service';

@Controller('schiffe')
export class SchiffeController {

constructor(private schiffeService: SchiffeService) {}

@Get('allSchiffe')
getAllSchiffsLocation(): SchiffsLocation[] {
return this.schiffeService.getAllSchiffsLocation()
}

@ApiParam({name: 'id'})
@Get(':id')
getOneSchiffslocation(@Param() param): SchiffsLocation {
return this.schiffeService.getOneSchiffslocation(param.id)
}

@Post('addSchiff')
addSchiff(@Body() schiffsLocation: SchiffsLocation) {
this.schiffeService.addSchiff(schiffsLocation)
}

@ApiParam({name: 'id'})
@Delete(':id')
deleteSchiff(@Param('id') id) {
this.schiffeService.deleteSchiff(id)
}

@ApiParam({name: 'id'})
@Patch(':id/position')
updateSchiff(@Param('id') id, @Body() position: Position) {
this.schiffeService.updateSchiff(id, position)
}
}
9 changes: 9 additions & 0 deletions src/schiffe/schiffe.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { SchiffeController } from './schiffe.controller';
import { SchiffeService } from './schiffe.service';

@Module({
controllers: [SchiffeController],
providers: [SchiffeService]
})
export class SchiffeModule {}
49 changes: 49 additions & 0 deletions src/schiffe/schiffe.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Injectable } from '@nestjs/common';
import { Position } from './model/position';
import { SchiffsLocation } from './model/schiffslocation';

@Injectable()
export class SchiffeService {

private schiffsLocation: SchiffsLocation[] = [
{ id: '1', name: 'Wassernixe 1', position: { latitude: 52.519328, longitude: 13.378559 } },
{ id: '2', name: 'Wassernixe 2', position: { latitude: 52.51751, longitude: 13.35551 } }
]

getAllSchiffsLocation(): SchiffsLocation[] {
return this.schiffsLocation
}

getOneSchiffslocation(id: number): SchiffsLocation {
// return { latitude: 1, longitude: 12 }
const schiff = (schiff) => {
if (schiff.id == id) {
return schiff
}
}
return this.schiffsLocation.find(schiff)
}

addSchiff(schiffsLocation: SchiffsLocation) {
let {id, name, position } = schiffsLocation
this.schiffsLocation.push({ id: id, name: name, position: position })
}

deleteSchiff(id: number): void {
const schiff = (schiff) => {
if (schiff.id !== id) {
return schiff
}
}
this.schiffsLocation = this.schiffsLocation.filter(schiff)
}

updateSchiff(id: number, position: Position){
const schiff = (schiff) => {
if (schiff.id == id) {
return schiff
}
}
this.schiffsLocation.find(schiff).position = position
}
}
3 changes: 2 additions & 1 deletion src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export class UsersService {
userId: 1,
username: '24225132',
password: 'password',
role: "admin"
role: 'administration'
},
{
userId: 2,
username: '24225131',
password: 'password',
role: 'administration'
},
{
userId: 3,
Expand Down

0 comments on commit cf6640f

Please sign in to comment.