Skip to content

Commit

Permalink
feat: 지도 정보 수정 API 구현 #13
Browse files Browse the repository at this point in the history
  • Loading branch information
Miensoap committed Nov 6, 2024
1 parent eea199a commit b2adcdb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
10 changes: 10 additions & 0 deletions backend/src/map/dto/UpdateMapInfoRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IsString, IsNotEmpty } from 'class-validator';

export class UpdateMapInfoRequest {
@IsString()
@IsNotEmpty()
title: string;

@IsString()
description?: string;
}
8 changes: 8 additions & 0 deletions backend/src/map/map.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 };
}
}
19 changes: 14 additions & 5 deletions backend/src/map/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)),
Expand All @@ -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);
}
}

0 comments on commit b2adcdb

Please sign in to comment.