diff --git a/backend/src/map/dto/UpdateMapInfoRequest.ts b/backend/src/map/dto/UpdateMapInfoRequest.ts new file mode 100644 index 00000000..852264c8 --- /dev/null +++ b/backend/src/map/dto/UpdateMapInfoRequest.ts @@ -0,0 +1,10 @@ +import { IsString, IsNotEmpty } from 'class-validator'; + +export class UpdateMapInfoRequest { + @IsString() + @IsNotEmpty() + title: string; + + @IsString() + description?: string; +} diff --git a/backend/src/map/map.controller.ts b/backend/src/map/map.controller.ts index f7872e60..37bec0e1 100644 --- a/backend/src/map/map.controller.ts +++ b/backend/src/map/map.controller.ts @@ -7,8 +7,10 @@ import { Delete, Param, } from '@nestjs/common'; +import { Controller, Get, Post, Body, Query, Delete, Param, Patch } from '@nestjs/common'; import { MapService } from './map.service'; import { CreateMapRequest } from './dto/CreateMapRequest'; +import { UpdateMapInfoRequest } from './dto/UpdateMapInfoRequest'; @Controller('/maps') export class MapController { @@ -40,4 +42,10 @@ export class MapController { async deleteMap(@Param('id') id: number) { return await this.appService.deleteMap(id); } + + @Patch('/:id/info') + async updateMapInfo(@Param('id') id: number, @Body() updateMapForm: UpdateMapInfoRequest) { + await this.appService.updateMapInfo(id, updateMapForm); + return { id, ...updateMapForm }; + } } diff --git a/backend/src/map/map.service.ts b/backend/src/map/map.service.ts index 4cf9c0b7..31898f53 100644 --- a/backend/src/map/map.service.ts +++ b/backend/src/map/map.service.ts @@ -7,6 +7,7 @@ import { Repository } from 'typeorm'; import { MapListResponse } from './dto/MapListResponse'; import { MapDetailResponse } from './dto/MapDetailResponse'; import { MapNotFoundException } from './exception/MapNotFoundException'; +import { UpdateMapInfoRequest } from './dto/UpdateMapInfoRequest'; @Injectable() export class MapService { @@ -45,11 +46,7 @@ export class MapService { where: { user: { id: userId } }, }); - const ownMaps = await this.mapRepository.findByUserId( - userId, - page, - pageSize, - ); + const ownMaps = await this.mapRepository.findByUserId(userId, page, pageSize); return { maps: await Promise.all(ownMaps.map(MapListResponse.from)), @@ -73,7 +70,19 @@ export class MapService { } async deleteMap(id: number) { + await this.checkExists(id); + await this.mapRepository.softDelete(id); return { id }; } + + async updateMapInfo(id: number, updateMapForm: UpdateMapInfoRequest) { + await this.checkExists(id); + + const { title, description } = updateMapForm; + return this.mapRepository.update(id, { title, description }); + } + private async checkExists(id: number) { + if (!(await this.mapRepository.existById(id))) throw new MapNotFoundException(id); + } }