feat: add trip and trip settings with optimistic locking
This commit is contained in:
56
backend/apps/api/src/trips/trips.controller.ts
Normal file
56
backend/apps/api/src/trips/trips.controller.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { OidcAuthGuard } from '../../../../libs/auth/src';
|
||||
import type { AuthenticatedUser } from '../../../../libs/auth/src';
|
||||
import { TripsService } from '../../../../libs/trips/src';
|
||||
import type {
|
||||
CreateTripDto,
|
||||
Trip,
|
||||
UpdateTripDto,
|
||||
} from '../../../../libs/trips/src';
|
||||
import { CurrentUser } from '../auth/current-user.decorator';
|
||||
|
||||
@Controller('trips')
|
||||
@UseGuards(OidcAuthGuard)
|
||||
export class TripsController {
|
||||
constructor(private readonly tripsService: TripsService) {}
|
||||
|
||||
@Get()
|
||||
list(@CurrentUser() currentUser: AuthenticatedUser): Promise<Trip[]> {
|
||||
return this.tripsService.listTripsForUser(currentUser.id);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(
|
||||
@CurrentUser() currentUser: AuthenticatedUser,
|
||||
@Body() dto: CreateTripDto,
|
||||
): Promise<Trip> {
|
||||
return this.tripsService.createTrip(currentUser.id, dto);
|
||||
}
|
||||
|
||||
@Get(':tripId')
|
||||
getOne(@Param('tripId') tripId: string): Promise<Trip> {
|
||||
return this.tripsService.getTrip(tripId);
|
||||
}
|
||||
|
||||
@Patch(':tripId')
|
||||
update(
|
||||
@Param('tripId') tripId: string,
|
||||
@Body() dto: UpdateTripDto,
|
||||
): Promise<Trip> {
|
||||
return this.tripsService.updateTrip(tripId, dto);
|
||||
}
|
||||
|
||||
@Delete(':tripId')
|
||||
remove(@Param('tripId') tripId: string): Promise<void> {
|
||||
return this.tripsService.deleteTrip(tripId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user