|  | 
|  | 1 | +import { | 
|  | 2 | +  Controller, | 
|  | 3 | +  Get, | 
|  | 4 | +  Param, | 
|  | 5 | +  ParseIntPipe, | 
|  | 6 | +  Post, | 
|  | 7 | +  Body, | 
|  | 8 | +} from '@nestjs/common'; | 
|  | 9 | +import { ApiBody } from '@nestjs/swagger'; | 
|  | 10 | +import { RequestsService } from './request.service'; | 
|  | 11 | +import { FoodRequest } from './request.entity'; | 
|  | 12 | + | 
|  | 13 | +@Controller('requests') | 
|  | 14 | +//@UseInterceptors() | 
|  | 15 | +export class FoodRequestsController { | 
|  | 16 | +  constructor(private requestsService: RequestsService) {} | 
|  | 17 | + | 
|  | 18 | +  @Get('/:pantryId') | 
|  | 19 | +  async getAllPantryRequests( | 
|  | 20 | +    @Param('pantryId', ParseIntPipe) pantryId: number, | 
|  | 21 | +  ): Promise<FoodRequest[]> { | 
|  | 22 | +    return this.requestsService.find(pantryId); | 
|  | 23 | +  } | 
|  | 24 | + | 
|  | 25 | +  @Post('/create') | 
|  | 26 | +  @ApiBody({ | 
|  | 27 | +    description: 'Details for creating a food request', | 
|  | 28 | +    schema: { | 
|  | 29 | +      type: 'object', | 
|  | 30 | +      properties: { | 
|  | 31 | +        pantryId: { type: 'integer', example: 1 }, | 
|  | 32 | +        requestedSize: { type: 'string', example: 'Medium (5-10 boxes)' }, | 
|  | 33 | +        requestedItems: { | 
|  | 34 | +          type: 'array', | 
|  | 35 | +          items: { type: 'string' }, | 
|  | 36 | +          example: ['Rice Noodles', 'Quinoa'], | 
|  | 37 | +        }, | 
|  | 38 | +        additionalInformation: { | 
|  | 39 | +          type: 'string', | 
|  | 40 | +          nullable: true, | 
|  | 41 | +          example: 'Urgent request', | 
|  | 42 | +        }, | 
|  | 43 | +        status: { type: 'string', example: 'pending' }, | 
|  | 44 | +        fulfilledBy: { type: 'integer', nullable: true, example: null }, | 
|  | 45 | +        dateReceived: { | 
|  | 46 | +          type: 'string', | 
|  | 47 | +          format: 'date-time', | 
|  | 48 | +          nullable: true, | 
|  | 49 | +          example: null, | 
|  | 50 | +        }, | 
|  | 51 | +        feedback: { type: 'string', nullable: true, example: null }, | 
|  | 52 | +        photos: { | 
|  | 53 | +          type: 'array', | 
|  | 54 | +          items: { type: 'string' }, | 
|  | 55 | +          nullable: true, | 
|  | 56 | +          example: [], | 
|  | 57 | +        }, | 
|  | 58 | +      }, | 
|  | 59 | +    }, | 
|  | 60 | +  }) | 
|  | 61 | +  async createRequest( | 
|  | 62 | +    @Body() | 
|  | 63 | +    body: { | 
|  | 64 | +      pantryId: number; | 
|  | 65 | +      requestedSize: string; | 
|  | 66 | +      requestedItems: string[]; | 
|  | 67 | +      additionalInformation: string; | 
|  | 68 | +      status: string; | 
|  | 69 | +      fulfilledBy: number; | 
|  | 70 | +      dateReceived: Date; | 
|  | 71 | +      feedback: string; | 
|  | 72 | +      photos: string[]; | 
|  | 73 | +    }, | 
|  | 74 | +  ): Promise<FoodRequest> { | 
|  | 75 | +    return this.requestsService.create( | 
|  | 76 | +      body.pantryId, | 
|  | 77 | +      body.requestedSize, | 
|  | 78 | +      body.requestedItems, | 
|  | 79 | +      body.additionalInformation, | 
|  | 80 | +      body.status, | 
|  | 81 | +      body.fulfilledBy, | 
|  | 82 | +      body.dateReceived, | 
|  | 83 | +      body.feedback, | 
|  | 84 | +      body.photos, | 
|  | 85 | +    ); | 
|  | 86 | +  } | 
|  | 87 | +} | 
0 commit comments