Repository navigation
MSPCA-11 Add POST /recommendations endpoint #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c1a1763
Add POST /recommendations endpoint
Juwang110 fff3cbe
Fix recommendations boot failure and duplicate-POST race
Juwang110 0919162
Remove recommendations module spec
justin-wang110 e5d347e
Remove explanatory comments
justin-wang110 1c7edd7
Restore example service functions in VolunteersService
justin-wang110 498dea5
Respect @Column names in PluralNamingStrategy
justin-wang110 f3d9709
Respond to review comments
Juwang110 e725b6e
Merge branch 'main' into jw/mspca-11-recommendations-endpoint
Juwang110 a6b7aa1
Address second round of PR review comments
Juwang110 5f15894
remove comment
Juwang110 c396d1c
Merge remote-tracking branch 'origin/main' into jw/mspca-11-recommend…
Juwang110 901de52
Address third round of PR review comments
Juwang110 22141c2
Merge origin/main into jw/mspca-11-recommendations-endpoint
Juwang110 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
apps/backend/src/recommendations/dto/create-recommendation.dto.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { IsInt, IsPositive } from 'class-validator'; | ||
|
|
||
| export class CreateRecommendationDTO { | ||
| @IsInt() | ||
| @IsPositive() | ||
| volunteerId!: number; | ||
|
|
||
| @IsInt() | ||
| @IsPositive() | ||
| chameleonAnimalId!: number; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 32 additions & 2 deletions
34
apps/backend/src/recommendations/recommendations.controller.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,37 @@ | ||
| import { Controller } from '@nestjs/common'; | ||
| import { Body, Controller, HttpStatus, Post } from '@nestjs/common'; | ||
| import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; | ||
| import { RecommendationsService } from './recommendations.service'; | ||
| import { Recommendation } from './recommendations.entity'; | ||
| import { CreateRecommendationDTO } from './dto/create-recommendation.dto'; | ||
| import { VolunteersService } from '../volunteers/volunteers.service'; | ||
| import { validateId } from '../utils/validation.utils'; | ||
|
|
||
| @ApiTags('Recommendations') | ||
| // @ApiBearerAuth() | ||
| @Controller('recommendations') | ||
| export class RecommendationsController { | ||
| constructor(private recommendationsService: RecommendationsService) {} | ||
| constructor( | ||
| private recommendationsService: RecommendationsService, | ||
| private volunteersService: VolunteersService, | ||
| ) {} | ||
|
|
||
| @Post() | ||
|
Juwang110 marked this conversation as resolved.
|
||
| @ApiOperation({ | ||
| summary: 'Recommend a Chameleon Animal to an active Volunteer', | ||
| }) | ||
| @ApiResponse({ | ||
| status: HttpStatus.CREATED, | ||
|
Juwang110 marked this conversation as resolved.
|
||
| description: 'The created or reactivated recommendation', | ||
| type: Recommendation, | ||
| }) | ||
| async createRecommendation( | ||
| @Body() body: CreateRecommendationDTO, | ||
| ): Promise<Recommendation> { | ||
| validateId(body.volunteerId, 'Volunteer'); | ||
| validateId(body.chameleonAnimalId, 'Chameleon Animal'); | ||
|
|
||
| await this.volunteersService.findActiveOrFail(body.volunteerId); | ||
|
|
||
|
Juwang110 marked this conversation as resolved.
|
||
| return this.recommendationsService.create(body); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { BadRequestException } from '@nestjs/common'; | ||
|
|
||
| export function validateId(id: number, entityName: string): void { | ||
| if (!id || id < 1) { | ||
| if (!Number.isInteger(id) || id < 1) { | ||
|
Juwang110 marked this conversation as resolved.
|
||
| throw new BadRequestException(`Invalid ${entityName} ID`); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.