Skip to content

Commit

Permalink
refactor: 장소 생성 요청 DTO 네이밍 변경 #52
Browse files Browse the repository at this point in the history
  • Loading branch information
koomchang committed Nov 6, 2024
1 parent 787844c commit e20fb19
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'class-validator';
import { Place } from '../place.entity';

export class CreatePlaceDto {
export class CreatePlaceRequest {
@IsString()
@IsNotEmpty()
googlePlaceId: string;
Expand Down
4 changes: 2 additions & 2 deletions backend/src/place/place.controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common';
import { PlaceService } from './place.service';
import { CreatePlaceDto } from './dto/CreatePlaceDto';
import { CreatePlaceRequest } from './dto/CreatePlaceRequest';

@Controller('places')
export class PlaceController {
constructor(private readonly placeService: PlaceService) {}

@Post()
async addPlace(@Body() createPlaceDto: CreatePlaceDto) {
async addPlace(@Body() createPlaceDto: CreatePlaceRequest) {
return this.placeService.addPlace(createPlaceDto);
}

Expand Down
8 changes: 4 additions & 4 deletions backend/src/place/place.service.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Injectable } from '@nestjs/common';
import { PlaceRepository } from './place.repository';
import { CreatePlaceDto } from './dto/CreatePlaceDto';
import { CreatePlaceRequest } from './dto/CreatePlaceRequest';
import { PlaceNotFoundException } from './exception/PlaceNotFoundException';
import { PlaceAlreadyExistsException } from './exception/PlaceAlreadyExistsException';

@Injectable()
export class PlaceService {
constructor(private readonly placeRepository: PlaceRepository) {}

async addPlace(createPlaceDto: CreatePlaceDto) {
const { googlePlaceId } = createPlaceDto;
async addPlace(createPlaceRequest: CreatePlaceRequest) {
const { googlePlaceId } = createPlaceRequest;
if (await this.placeRepository.findByGooglePlaceId(googlePlaceId)) {
throw new PlaceAlreadyExistsException();
}

const place = createPlaceDto.toEntity();
const place = createPlaceRequest.toEntity();
const savedPlace = await this.placeRepository.save(place);
return { id: savedPlace.id };
}
Expand Down

0 comments on commit e20fb19

Please sign in to comment.