diff --git a/BE/src/postings/posting.swagger.ts b/BE/src/postings/posting.swagger.ts index 629d835..3501dcf 100644 --- a/BE/src/postings/posting.swagger.ts +++ b/BE/src/postings/posting.swagger.ts @@ -135,11 +135,7 @@ export const search_OK = [ export const create_OK = { id: 'c89f207a-f528-4d53-8ac2-1356fa22eb21' }; -export const update_OK = { - generatedMaps: [], - raw: [], - affected: 1, -}; +export const update_OK = { id: '4d365e7c-3e82-472d-bf87-7faf65d9377d' }; export const remove_OK = { title: 'bread lover', @@ -167,11 +163,7 @@ export const remove_OK = { reports: [], }; -export const like_OK = { - posting: 'c89f207a-f528-4d53-8ac2-1356fa22eb21', - user: '123456789012345678901234567890123456', - isDeleted: false, -}; +export const like_OK = { isLiked: false }; export const report_OK = { posting: 'c0265845-4991-4f04-a5c3-4cf12207d675', diff --git a/BE/src/postings/postings.controller.ts b/BE/src/postings/postings.controller.ts index 5f2e025..46931fd 100644 --- a/BE/src/postings/postings.controller.ts +++ b/BE/src/postings/postings.controller.ts @@ -20,8 +20,8 @@ import { ApiBadRequestResponse, ApiBearerAuth, ApiConflictResponse, - ApiConsumes, ApiCreatedResponse, + ApiForbiddenResponse, ApiNotFoundResponse, ApiOkResponse, ApiOperation, @@ -140,6 +140,15 @@ export class PostingsController { description: 'id 값에 해당되는 게시글을 반환합니다.', }) @ApiOkResponse({ schema: { example: findOne_OK } }) + @ApiForbiddenResponse({ + schema: { + example: { + message: '차단된 게시글입니다.', + error: 'Forbidden', + statusCode: 403, + }, + }, + }) async findOne(@Req() request, @Param('id', ParseUUIDPipe) id: string) { const userId = request['user'].id; const posting = await this.postingsService.findOne(id); @@ -159,15 +168,24 @@ export class PostingsController { summary: '게시글 수정', description: 'id 값에 해당되는 게시글을 수정합니다.', }) - @ApiConsumes('application/x-www-form-urlencoded') @ApiOkResponse({ schema: { example: update_OK } }) + @ApiForbiddenResponse({ + schema: { + example: { + message: '본인이 작성한 게시글만 수정할 수 있습니다.', + error: 'Forbidden', + statusCode: 403, + }, + }, + }) async update( @Req() request, @Param('id', ParseUUIDPipe) id: string, @Body() updatePostingDto: UpdatePostingDto ) { const userId = request['user'].id; - return this.postingsService.update(id, userId, updatePostingDto); + await this.postingsService.update(id, userId, updatePostingDto); + return { id }; } @Delete(':id') @@ -176,6 +194,15 @@ export class PostingsController { description: 'id 값에 해당되는 게시글을 삭제합니다.', }) @ApiOkResponse({ schema: { example: remove_OK } }) + @ApiForbiddenResponse({ + schema: { + example: { + message: '본인이 작성한 게시글만 삭제할 수 있습니다.', + error: 'Forbidden', + statusCode: 403, + }, + }, + }) async remove( @Req() request, @Param('id', ParseUUIDPipe) id: string @@ -189,7 +216,7 @@ export class PostingsController { summary: '게시글 좋아요 토글', description: 'id 값에 해당하는 게시글에 좋아요가 추가되거나 삭제됩니다.', }) - @ApiOkResponse({ schema: { examples: [update_OK, like_OK] } }) + @ApiOkResponse({ schema: { example: like_OK } }) async toggleLike(@Req() request, @Param('id', ParseUUIDPipe) id: string) { const userId = request['user'].id; return this.postingsService.toggleLike(id, userId); diff --git a/BE/src/postings/postings.service.ts b/BE/src/postings/postings.service.ts index a86e560..0405838 100644 --- a/BE/src/postings/postings.service.ts +++ b/BE/src/postings/postings.service.ts @@ -126,13 +126,15 @@ export class PostingsService { const liked = await this.likedsRepository.findOne(postingId, userId); if (liked) { - return this.likedsRepository.toggle(postingId, userId, liked.isDeleted); + await this.likedsRepository.toggle(postingId, userId, liked.isDeleted); + return { isLiked: liked.isDeleted }; } const newLiked = new Liked(); newLiked.posting = postingId; newLiked.user = userId; - return this.likedsRepository.save(newLiked); + await this.likedsRepository.save(newLiked); + return { isLiked: true }; } async report(postingId: string, userId: string) { diff --git a/BE/src/timelines/timelines.module.ts b/BE/src/timelines/timelines.module.ts index 22c4a9c..7a0490c 100644 --- a/BE/src/timelines/timelines.module.ts +++ b/BE/src/timelines/timelines.module.ts @@ -1,4 +1,5 @@ import { Module } from '@nestjs/common'; +import { HttpModule } from '@nestjs/axios'; import { TimelinesService } from './timelines.service'; import { TimelinesController } from './timelines.controller'; import { timelinesProviders } from './timelines.providers'; @@ -14,7 +15,13 @@ import { postingsProviders } from '../postings/postings.providers'; import { StorageModule } from '../storage/storage.module'; @Module({ - imports: [DatabaseModule, PostingsModule, UsersModule, StorageModule], + imports: [ + DatabaseModule, + PostingsModule, + UsersModule, + StorageModule, + HttpModule, + ], controllers: [TimelinesController], providers: [ ...timelinesProviders, diff --git a/BE/src/timelines/timelines.service.ts b/BE/src/timelines/timelines.service.ts index f10a095..b93349b 100644 --- a/BE/src/timelines/timelines.service.ts +++ b/BE/src/timelines/timelines.service.ts @@ -3,7 +3,8 @@ import { ForbiddenException, NotFoundException, } from '@nestjs/common'; -import axios from 'axios'; +import { firstValueFrom } from 'rxjs'; +import { HttpService } from '@nestjs/axios'; import { CreateTimelineDto } from './dto/create-timeline.dto'; import { UpdateTimelineDto } from './dto/update-timeline.dto'; import { TimelinesRepository } from './timelines.repository'; @@ -19,7 +20,8 @@ export class TimelinesService { private readonly timelinesRepository: TimelinesRepository, private readonly postingsRepository: PostingsRepository, private readonly postingsService: PostingsService, - private readonly storageService: StorageService + private readonly storageService: StorageService, + private readonly httpService: HttpService ) {} async create( @@ -151,9 +153,11 @@ export class TimelinesService { const url = `${KAKAO_KEYWORD_SEARCH}?query=${place}&page=${offset}&size=${limit}`; const { data: { documents }, - } = await axios.get(url, { - headers: { Authorization: `KakaoAK ${process.env.KAKAO_REST_API_KEY}` }, - }); + } = await firstValueFrom( + this.httpService.get(url, { + headers: { Authorization: `KakaoAK ${process.env.KAKAO_REST_API_KEY}` }, + }) + ); return documents; }