From 5833293b2c0f1daf7fe6fa34e98fbb7278bba3f1 Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 06:20:07 +0900 Subject: [PATCH 01/24] =?UTF-8?q?fix=20:=20ManagerAuthInterceptor=20?= =?UTF-8?q?=EB=94=94=EC=BD=94=EB=94=A9=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interceptor/ManagerAuthInterceptor.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/com/now/naaga/auth/presentation/interceptor/ManagerAuthInterceptor.java b/backend/src/main/java/com/now/naaga/auth/presentation/interceptor/ManagerAuthInterceptor.java index 5f9fedd3e..84bde68af 100644 --- a/backend/src/main/java/com/now/naaga/auth/presentation/interceptor/ManagerAuthInterceptor.java +++ b/backend/src/main/java/com/now/naaga/auth/presentation/interceptor/ManagerAuthInterceptor.java @@ -20,7 +20,7 @@ public class ManagerAuthInterceptor implements HandlerInterceptor { public static final int AUTH_HEADER_INFO_SIZE = 2; - public static final String AUTH_HEADER_TYPE = "Basic "; + public static final String AUTH_HEADER_TYPE = "Basic"; @Value("${manager.id}") private String id; @@ -41,12 +41,12 @@ private List extractHeaderInfo(final HttpServletRequest request) { if (header == null) { throw new AuthException(NOT_EXIST_HEADER); } - final String decodedHeader = new String(Base64.getDecoder().decode(header)); - if (!decodedHeader.startsWith(AUTH_HEADER_TYPE)) { + final String[] authHeader = header.split(" "); + if (!AUTH_HEADER_TYPE.equals(authHeader[0])) { throw new AuthException(INVALID_HEADER); } - final String decodedHeaderWithoutType = decodedHeader.replace(AUTH_HEADER_TYPE, ""); - final String[] idAndPassword = decodedHeaderWithoutType.split(":"); + final String decodedHeader = new String(Base64.getDecoder().decode(authHeader[1])); + final String[] idAndPassword = decodedHeader.split(":"); if (idAndPassword.length != AUTH_HEADER_INFO_SIZE) { throw new AuthException(INVALID_HEADER); } From 9b4f610beeacc4f9eb9b4193c211f85aab7b4abe Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 06:30:01 +0900 Subject: [PATCH 02/24] =?UTF-8?q?feat:=20=EC=9D=B8=ED=84=B0=EC=85=89?= =?UTF-8?q?=ED=84=B0=EC=97=90=20=EA=B2=80=EC=88=98=EC=A4=91=20=EC=9E=A5?= =?UTF-8?q?=EC=86=8C=20=EC=A1=B0=ED=9A=8C=20path=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/now/naaga/common/config/WebConfig.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/now/naaga/common/config/WebConfig.java b/backend/src/main/java/com/now/naaga/common/config/WebConfig.java index 551069430..12a7f857b 100644 --- a/backend/src/main/java/com/now/naaga/common/config/WebConfig.java +++ b/backend/src/main/java/com/now/naaga/common/config/WebConfig.java @@ -3,6 +3,7 @@ import com.now.naaga.auth.presentation.argumentresolver.MemberAuthArgumentResolver; import com.now.naaga.auth.presentation.argumentresolver.PlayerArgumentResolver; import com.now.naaga.auth.presentation.interceptor.AuthInterceptor; +import com.now.naaga.auth.presentation.interceptor.ManagerAuthInterceptor; import com.now.naaga.common.presentation.interceptor.RequestMatcherInterceptor; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; @@ -24,15 +25,19 @@ public class WebConfig implements WebMvcConfigurer { private final AuthInterceptor authInterceptor; + private final ManagerAuthInterceptor managerAuthInterceptor; + @Value("${manager.origin-url}") private String managerUriPath; public WebConfig(final PlayerArgumentResolver playerArgumentResolver, final MemberAuthArgumentResolver memberAuthArgumentResolver, - final AuthInterceptor authInterceptor) { + final AuthInterceptor authInterceptor, + final ManagerAuthInterceptor managerAuthInterceptor) { this.playerArgumentResolver = playerArgumentResolver; this.memberAuthArgumentResolver = memberAuthArgumentResolver; this.authInterceptor = authInterceptor; + this.managerAuthInterceptor = managerAuthInterceptor; } @Override @@ -51,7 +56,13 @@ private HandlerInterceptor mapAuthInterceptor() { .excludeRequestPattern("/**/*.gif") .excludeRequestPattern("/**/*.ico") .excludeRequestPattern("/ranks") - .excludeRequestPattern("/**", HttpMethod.OPTIONS); + .excludeRequestPattern("/**", HttpMethod.OPTIONS) + .excludeRequestPattern("/temporary-places", HttpMethod.GET); + } + + private HandlerInterceptor mapManagerAuthInterceptor() { + return new RequestMatcherInterceptor(managerAuthInterceptor) + .includeRequestPattern("/temporary-places", HttpMethod.GET); } @Override From b446c17de8e92808f1921365a43ae788c660d85a Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 06:34:57 +0900 Subject: [PATCH 03/24] =?UTF-8?q?feat:=20=EA=B2=80=EC=88=98=ED=95=A0=20?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20=EB=93=B1=EB=A1=9D=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../naaga/place/application/PlaceService.java | 48 +++-------------- .../application/TemporaryPlaceService.java | 54 +++++++++++++++++++ .../dto/CreateTemporaryPlaceCommand.java | 24 +++++++++ .../domain/TemporaryPlaceCheckService.java} | 10 ++-- 4 files changed, 90 insertions(+), 46 deletions(-) create mode 100644 backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java create mode 100644 backend/src/main/java/com/now/naaga/temporaryplace/application/dto/CreateTemporaryPlaceCommand.java rename backend/src/main/java/com/now/naaga/{place/domain/PlaceCheckService.java => temporaryplace/domain/TemporaryPlaceCheckService.java} (72%) diff --git a/backend/src/main/java/com/now/naaga/place/application/PlaceService.java b/backend/src/main/java/com/now/naaga/place/application/PlaceService.java index 5f33a39c1..e40919316 100644 --- a/backend/src/main/java/com/now/naaga/place/application/PlaceService.java +++ b/backend/src/main/java/com/now/naaga/place/application/PlaceService.java @@ -1,29 +1,22 @@ package com.now.naaga.place.application; -import static com.now.naaga.place.exception.PlaceExceptionType.NO_EXIST; - import com.now.naaga.common.domain.OrderType; -import com.now.naaga.common.infrastructure.FileManager; import com.now.naaga.place.application.dto.CreatePlaceCommand; import com.now.naaga.place.application.dto.FindAllPlaceCommand; import com.now.naaga.place.application.dto.FindPlaceByIdCommand; import com.now.naaga.place.application.dto.RecommendPlaceCommand; import com.now.naaga.place.domain.Place; -import com.now.naaga.place.domain.PlaceCheckService; import com.now.naaga.place.domain.PlaceRecommendService; import com.now.naaga.place.domain.Position; import com.now.naaga.place.domain.SortType; import com.now.naaga.place.exception.PlaceException; import com.now.naaga.place.persistence.repository.PlaceRepository; -import com.now.naaga.player.application.PlayerService; -import com.now.naaga.player.domain.Player; -import java.io.File; -import java.util.List; - -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + +import static com.now.naaga.place.exception.PlaceExceptionType.NO_EXIST; @Transactional @Service @@ -31,24 +24,12 @@ public class PlaceService { private final PlaceRepository placeRepository; - private final PlayerService playerService; - - private final PlaceCheckService placeCheckService; - private final PlaceRecommendService placeRecommendService; - private final FileManager fileManager; - public PlaceService(final PlaceRepository placeRepository, - final PlayerService playerService, - final PlaceCheckService placeCheckService, - final PlaceRecommendService placeRecommendService, - final FileManager fileManager) { + final PlaceRecommendService placeRecommendService) { this.placeRepository = placeRepository; - this.playerService = playerService; - this.placeCheckService = placeCheckService; this.placeRecommendService = placeRecommendService; - this.fileManager = fileManager; } @Transactional(readOnly = true) @@ -73,23 +54,6 @@ public Place recommendPlaceByPosition(final RecommendPlaceCommand recommendPlace } public Place createPlace(final CreatePlaceCommand createPlaceCommand) { - final Position position = createPlaceCommand.position(); - placeCheckService.checkOtherPlaceNearby(position); - final File uploadPath = fileManager.save(createPlaceCommand.imageFile()); - try { - final Long playerId = createPlaceCommand.playerId(); - final Player registeredPlayer = playerService.findPlayerById(playerId); - final Place place = new Place( - createPlaceCommand.name(), - createPlaceCommand.description(), - position, - fileManager.convertToUrlPath(uploadPath), - registeredPlayer); - placeRepository.save(place); - return place; - } catch (final RuntimeException exception) { - uploadPath.delete(); - throw exception; - } + return null; } } diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java b/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java new file mode 100644 index 000000000..f00b82a1c --- /dev/null +++ b/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java @@ -0,0 +1,54 @@ +package com.now.naaga.temporaryplace.application; + +import com.now.naaga.common.infrastructure.FileManager; +import com.now.naaga.place.domain.Position; +import com.now.naaga.player.application.PlayerService; +import com.now.naaga.player.domain.Player; +import com.now.naaga.temporaryplace.application.dto.CreateTemporaryPlaceCommand; +import com.now.naaga.temporaryplace.domain.TemporaryPlace; +import com.now.naaga.temporaryplace.domain.TemporaryPlaceCheckService; +import com.now.naaga.temporaryplace.repository.TemporaryPlaceRepository; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; + +public class TemporaryPlaceService { + + private final TemporaryPlaceRepository temporaryPlaceRepository; + + private final PlayerService playerService; + + private final TemporaryPlaceCheckService temporaryPlaceCheckService; + + private final FileManager fileManager; + + public TemporaryPlaceService(final TemporaryPlaceRepository temporaryPlaceRepository, + final PlayerService playerService, + final TemporaryPlaceCheckService temporaryPlaceCheckService, + final FileManager fileManager) { + this.temporaryPlaceRepository = temporaryPlaceRepository; + this.playerService = playerService; + this.temporaryPlaceCheckService = temporaryPlaceCheckService; + this.fileManager = fileManager; + } + + public TemporaryPlace createTemporaryPlace(final CreateTemporaryPlaceCommand createTemporaryPlaceCommand) { + final Position position = createTemporaryPlaceCommand.position(); + temporaryPlaceCheckService.checkOtherPlaceNearby(position); + final File uploadPath = fileManager.save(createTemporaryPlaceCommand.imageFile()); + try { + final Long playerId = createTemporaryPlaceCommand.playerId(); + final Player registeredPlayer = playerService.findPlayerById(playerId); + final TemporaryPlace temporaryPlace = new TemporaryPlace( + createTemporaryPlaceCommand.name(), + createTemporaryPlaceCommand.description(), + position, + fileManager.convertToUrlPath(uploadPath), + registeredPlayer); + return temporaryPlaceRepository.save(temporaryPlace); + } catch (final RuntimeException exception) { + uploadPath.delete(); + throw exception; + } + } +} diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/application/dto/CreateTemporaryPlaceCommand.java b/backend/src/main/java/com/now/naaga/temporaryplace/application/dto/CreateTemporaryPlaceCommand.java new file mode 100644 index 000000000..d1f77f1b1 --- /dev/null +++ b/backend/src/main/java/com/now/naaga/temporaryplace/application/dto/CreateTemporaryPlaceCommand.java @@ -0,0 +1,24 @@ +package com.now.naaga.temporaryplace.application.dto; + +import com.now.naaga.place.domain.Position; +import com.now.naaga.player.presentation.dto.PlayerRequest; +import com.now.naaga.temporaryplace.presentation.dto.CreateTemporaryPlaceRequest; +import org.springframework.web.multipart.MultipartFile; + +public record CreateTemporaryPlaceCommand(Long playerId, + String name, + String description, + Position position, + MultipartFile imageFile) { + + public static CreateTemporaryPlaceCommand of(final PlayerRequest playerRequest, + final CreateTemporaryPlaceRequest createTemporaryPlaceRequest) { + Position position = Position.of(createTemporaryPlaceRequest.latitude(), createTemporaryPlaceRequest.longitude()); + return new CreateTemporaryPlaceCommand( + playerRequest.playerId(), + createTemporaryPlaceRequest.name(), + createTemporaryPlaceRequest.description(), + position, + createTemporaryPlaceRequest.imageFile()); + } +} diff --git a/backend/src/main/java/com/now/naaga/place/domain/PlaceCheckService.java b/backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlaceCheckService.java similarity index 72% rename from backend/src/main/java/com/now/naaga/place/domain/PlaceCheckService.java rename to backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlaceCheckService.java index 9020f64ec..f20742d84 100644 --- a/backend/src/main/java/com/now/naaga/place/domain/PlaceCheckService.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlaceCheckService.java @@ -1,5 +1,7 @@ -package com.now.naaga.place.domain; +package com.now.naaga.temporaryplace.domain; +import com.now.naaga.place.domain.Place; +import com.now.naaga.place.domain.Position; import com.now.naaga.place.exception.PlaceException; import com.now.naaga.place.exception.PlaceExceptionType; import com.now.naaga.place.persistence.repository.PlaceRepository; @@ -9,18 +11,18 @@ @Transactional @Service -public class PlaceCheckService { +public class TemporaryPlaceCheckService { private final PlaceRepository placeRepository; - public PlaceCheckService(final PlaceRepository placeRepository) { + public TemporaryPlaceCheckService(final PlaceRepository placeRepository) { this.placeRepository = placeRepository; } @Transactional(readOnly = true) public void checkOtherPlaceNearby(final Position position) { List places = placeRepository.findPlaceByPositionAndDistance(position, 0.02); - if (places.size() > 0) { + if (!places.isEmpty()) { throw new PlaceException(PlaceExceptionType.ALREADY_EXIST_NEARBY); } } From 0c13a93888b660d21ba2dc7fc51c5af03d1f92ef Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 06:35:29 +0900 Subject: [PATCH 04/24] =?UTF-8?q?feat:=20=EA=B2=80=EC=88=98=ED=95=A0=20?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20=EB=93=B1=EB=A1=9D=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TemporaryPlaceController.java | 31 +++++++++++++++++ .../dto/CreateTemporaryPlaceRequest.java | 10 ++++++ .../dto/TemporaryPlaceResponse.java | 33 +++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/CreateTemporaryPlaceRequest.java create mode 100644 backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/TemporaryPlaceResponse.java diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java index 366087565..548252e55 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java @@ -1,9 +1,40 @@ package com.now.naaga.temporaryplace.presentation; +import com.now.naaga.auth.presentation.annotation.Auth; +import com.now.naaga.player.presentation.dto.PlayerRequest; +import com.now.naaga.temporaryplace.application.TemporaryPlaceService; +import com.now.naaga.temporaryplace.application.dto.CreateTemporaryPlaceCommand; +import com.now.naaga.temporaryplace.domain.TemporaryPlace; +import com.now.naaga.temporaryplace.presentation.dto.CreateTemporaryPlaceRequest; +import com.now.naaga.temporaryplace.presentation.dto.TemporaryPlaceResponse; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.net.URI; + @RequestMapping("/temporary-places") @RestController public class TemporaryPlaceController { + + private final TemporaryPlaceService temporaryPlaceService; + + public TemporaryPlaceController(final TemporaryPlaceService temporaryPlaceService) { + this.temporaryPlaceService = temporaryPlaceService; + } + + @PostMapping + public ResponseEntity createTemporaryPlace(@Auth final PlayerRequest playerRequest, + @ModelAttribute final CreateTemporaryPlaceRequest createTemporaryPlaceRequest) { + final CreateTemporaryPlaceCommand createTemporaryPlaceCommand = CreateTemporaryPlaceCommand.of(playerRequest, createTemporaryPlaceRequest); + final TemporaryPlace temporaryPlace = temporaryPlaceService.createTemporaryPlace(createTemporaryPlaceCommand); + final TemporaryPlaceResponse response = TemporaryPlaceResponse.from(temporaryPlace); + return ResponseEntity + .status(HttpStatus.CREATED) + .location(URI.create("/temporary-places/" + temporaryPlace.getId())) + .body(response); + } } diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/CreateTemporaryPlaceRequest.java b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/CreateTemporaryPlaceRequest.java new file mode 100644 index 000000000..ed629296e --- /dev/null +++ b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/CreateTemporaryPlaceRequest.java @@ -0,0 +1,10 @@ +package com.now.naaga.temporaryplace.presentation.dto; + +import org.springframework.web.multipart.MultipartFile; + +public record CreateTemporaryPlaceRequest(String name, + String description, + Double latitude, + Double longitude, + MultipartFile imageFile) { +} diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/TemporaryPlaceResponse.java b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/TemporaryPlaceResponse.java new file mode 100644 index 000000000..0e592e01d --- /dev/null +++ b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/TemporaryPlaceResponse.java @@ -0,0 +1,33 @@ +package com.now.naaga.temporaryplace.presentation.dto; + +import com.now.naaga.game.presentation.dto.CoordinateResponse; +import com.now.naaga.temporaryplace.domain.TemporaryPlace; + +import java.util.List; +import java.util.stream.Collectors; + +public record TemporaryPlaceResponse(Long id, + String name, + CoordinateResponse coordinate, + String imageUrl, + String description + +) { + + public static TemporaryPlaceResponse from(final TemporaryPlace savedTemporaryPlace) { + CoordinateResponse coordinateResponse = CoordinateResponse.of(savedTemporaryPlace.getPosition()); + return new TemporaryPlaceResponse( + savedTemporaryPlace.getId(), + savedTemporaryPlace.getName(), + coordinateResponse, + savedTemporaryPlace.getImageUrl(), + savedTemporaryPlace.getDescription() + ); + } + + public static List convertToResponses(final List temporaryPlaces) { + return temporaryPlaces.stream() + .map(TemporaryPlaceResponse::from) + .collect(Collectors.toList()); + } +} From 7a757debbfe09701282ad40135faa722baab07dc Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 06:37:13 +0900 Subject: [PATCH 05/24] =?UTF-8?q?feat:=20=EA=B2=80=EC=88=98=ED=95=A0=20?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../temporaryplace/application/TemporaryPlaceService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java b/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java index f00b82a1c..a7402f72c 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java @@ -11,6 +11,8 @@ import org.springframework.web.multipart.MultipartFile; import java.io.File; +import java.util.Comparator; +import java.util.List; public class TemporaryPlaceService { @@ -51,4 +53,10 @@ public TemporaryPlace createTemporaryPlace(final CreateTemporaryPlaceCommand cre throw exception; } } + + public List findAllPlace() { + final List temporaryPlaces = temporaryPlaceRepository.findAll(); + temporaryPlaces.sort(Comparator.comparing(TemporaryPlace::getCreatedAt)); + return temporaryPlaces; + } } From b9693dc8fadc660f84f0b1655344bacdda305a83 Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 06:37:28 +0900 Subject: [PATCH 06/24] =?UTF-8?q?feat:=20=EA=B2=80=EC=88=98=ED=95=A0=20?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/TemporaryPlaceController.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java index 548252e55..a7eadc52c 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java @@ -9,12 +9,10 @@ import com.now.naaga.temporaryplace.presentation.dto.TemporaryPlaceResponse; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.net.URI; +import java.util.List; @RequestMapping("/temporary-places") @RestController @@ -26,6 +24,15 @@ public TemporaryPlaceController(final TemporaryPlaceService temporaryPlaceServic this.temporaryPlaceService = temporaryPlaceService; } + @GetMapping + public ResponseEntity> findAllTemporaryPlace() { + final List temporaryPlaces = temporaryPlaceService.findAllPlace(); + final List response = TemporaryPlaceResponse.convertToResponses(temporaryPlaces); + return ResponseEntity + .status(HttpStatus.OK) + .body(response); + } + @PostMapping public ResponseEntity createTemporaryPlace(@Auth final PlayerRequest playerRequest, @ModelAttribute final CreateTemporaryPlaceRequest createTemporaryPlaceRequest) { From 29d60040b48d41d9003abb311f9aaaa79fad3fdd Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 08:00:53 +0900 Subject: [PATCH 07/24] =?UTF-8?q?fix:=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EB=B9=88=20=EB=93=B1=EB=A1=9D=20=EB=B0=8F?= =?UTF-8?q?=20=EC=9D=B8=ED=84=B0=EC=85=89=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/now/naaga/common/config/WebConfig.java | 1 + .../temporaryplace/application/TemporaryPlaceService.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/backend/src/main/java/com/now/naaga/common/config/WebConfig.java b/backend/src/main/java/com/now/naaga/common/config/WebConfig.java index 12a7f857b..b9ee75fc9 100644 --- a/backend/src/main/java/com/now/naaga/common/config/WebConfig.java +++ b/backend/src/main/java/com/now/naaga/common/config/WebConfig.java @@ -43,6 +43,7 @@ public WebConfig(final PlayerArgumentResolver playerArgumentResolver, @Override public void addInterceptors(final InterceptorRegistry registry) { registry.addInterceptor(mapAuthInterceptor()); + registry.addInterceptor(mapManagerAuthInterceptor()); } private HandlerInterceptor mapAuthInterceptor() { diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java b/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java index a7402f72c..fcb7fc2b0 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java @@ -8,12 +8,16 @@ import com.now.naaga.temporaryplace.domain.TemporaryPlace; import com.now.naaga.temporaryplace.domain.TemporaryPlaceCheckService; import com.now.naaga.temporaryplace.repository.TemporaryPlaceRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.util.Comparator; import java.util.List; +@Transactional +@Service public class TemporaryPlaceService { private final TemporaryPlaceRepository temporaryPlaceRepository; @@ -54,6 +58,7 @@ public TemporaryPlace createTemporaryPlace(final CreateTemporaryPlaceCommand cre } } + @Transactional(readOnly = true) public List findAllPlace() { final List temporaryPlaces = temporaryPlaceRepository.findAll(); temporaryPlaces.sort(Comparator.comparing(TemporaryPlace::getCreatedAt)); From efbfd65a68238014815b862b168594bb1fb9e956 Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 08:01:48 +0900 Subject: [PATCH 08/24] =?UTF-8?q?test:=20TemporaryPlaceBuilder=20=EB=B0=8F?= =?UTF-8?q?=20TemporaryPlaceFixture=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/builder/TemporaryPlaceBuilder.java | 79 ++++++++++++++++++ .../common/fixture/TemporaryPlaceFixture.java | 18 ++++ ...0\355\204\260\355\232\214\352\264\200.png" | Bin 3 files changed, 97 insertions(+) create mode 100644 backend/src/test/java/com/now/naaga/common/builder/TemporaryPlaceBuilder.java create mode 100644 backend/src/test/java/com/now/naaga/common/fixture/TemporaryPlaceFixture.java rename "backend/src/test/java/com/now/naaga/place/fixture/\353\243\250\355\204\260\355\232\214\352\264\200.png" => "backend/src/test/java/com/now/naaga/temporaryplace/fixture/\353\243\250\355\204\260\355\232\214\352\264\200.png" (100%) diff --git a/backend/src/test/java/com/now/naaga/common/builder/TemporaryPlaceBuilder.java b/backend/src/test/java/com/now/naaga/common/builder/TemporaryPlaceBuilder.java new file mode 100644 index 000000000..9e028f461 --- /dev/null +++ b/backend/src/test/java/com/now/naaga/common/builder/TemporaryPlaceBuilder.java @@ -0,0 +1,79 @@ +package com.now.naaga.common.builder; + +import com.now.naaga.place.domain.Place; +import com.now.naaga.place.domain.Position; +import com.now.naaga.player.domain.Player; +import com.now.naaga.temporaryplace.domain.TemporaryPlace; +import com.now.naaga.temporaryplace.repository.TemporaryPlaceRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Optional; + +import static com.now.naaga.common.fixture.PlaceFixture.*; +import static com.now.naaga.common.fixture.PositionFixture.잠실_루터회관_정문_좌표; + +@Component +public class TemporaryPlaceBuilder { + + @Autowired + private TemporaryPlaceRepository temporaryPlaceRepository; + + @Autowired + private PlayerBuilder playerBuilder; + + private String name; + + private String description; + + private Position position; + + private String imageUrl; + + private Optional registeredPlayer; + + public TemporaryPlaceBuilder init() { + this.name = NAME; + this.description = DESCRIPTION; + this.position = 잠실_루터회관_정문_좌표; + this.imageUrl = IMAGE_URL; + this.registeredPlayer = Optional.empty(); + return this; + } + + public TemporaryPlaceBuilder name(final String name) { + this.name = name; + return this; + } + + public TemporaryPlaceBuilder description(final String description) { + this.description = description; + return this; + } + + public TemporaryPlaceBuilder position(final Position position) { + this.position = position; + return this; + } + + public TemporaryPlaceBuilder imageUrl(final String imageUrl) { + this.imageUrl = imageUrl; + return this; + } + + public TemporaryPlaceBuilder registeredPlayer(final Player persistedPlayer) { + this.registeredPlayer = Optional.ofNullable(persistedPlayer); + return this; + } + + public TemporaryPlace build() { + final Player persistedPlayer = registeredPlayer.orElseGet(this::getPersistedPlayer); + final TemporaryPlace temporaryPlace = new TemporaryPlace(name, description, position, imageUrl, persistedPlayer); + return temporaryPlaceRepository.save(temporaryPlace); + } + + private Player getPersistedPlayer() { + return playerBuilder.init() + .build(); + } +} diff --git a/backend/src/test/java/com/now/naaga/common/fixture/TemporaryPlaceFixture.java b/backend/src/test/java/com/now/naaga/common/fixture/TemporaryPlaceFixture.java new file mode 100644 index 000000000..012710066 --- /dev/null +++ b/backend/src/test/java/com/now/naaga/common/fixture/TemporaryPlaceFixture.java @@ -0,0 +1,18 @@ +package com.now.naaga.common.fixture; + +import com.now.naaga.temporaryplace.domain.TemporaryPlace; + +import static com.now.naaga.common.fixture.PositionFixture.잠실_루터회관_정문_좌표; + +public class TemporaryPlaceFixture { + + public static final String NAME = "temp_place_name"; + + public static final String DESCRIPTION = "temp_place_description"; + + public static final String IMAGE_URL = "temp_place_imageUrl"; + + public static TemporaryPlace TEMPORARY_PLACE() { + return new TemporaryPlace(NAME, DESCRIPTION, 잠실_루터회관_정문_좌표, IMAGE_URL, null); + } +} diff --git "a/backend/src/test/java/com/now/naaga/place/fixture/\353\243\250\355\204\260\355\232\214\352\264\200.png" "b/backend/src/test/java/com/now/naaga/temporaryplace/fixture/\353\243\250\355\204\260\355\232\214\352\264\200.png" similarity index 100% rename from "backend/src/test/java/com/now/naaga/place/fixture/\353\243\250\355\204\260\355\232\214\352\264\200.png" rename to "backend/src/test/java/com/now/naaga/temporaryplace/fixture/\353\243\250\355\204\260\355\232\214\352\264\200.png" From 190a7393b5b17968355ee51b1cdbfa955b89a218 Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 08:21:37 +0900 Subject: [PATCH 09/24] =?UTF-8?q?test:=20ManagerAuthInterceptorTest=20?= =?UTF-8?q?=EB=94=94=EC=BD=94=EB=94=A9=20=EB=AC=B8=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/interceptor/ManagerAuthInterceptorTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/test/java/com/now/naaga/auth/presentation/interceptor/ManagerAuthInterceptorTest.java b/backend/src/test/java/com/now/naaga/auth/presentation/interceptor/ManagerAuthInterceptorTest.java index 80c7eaa6f..ea56e93cd 100644 --- a/backend/src/test/java/com/now/naaga/auth/presentation/interceptor/ManagerAuthInterceptorTest.java +++ b/backend/src/test/java/com/now/naaga/auth/presentation/interceptor/ManagerAuthInterceptorTest.java @@ -36,12 +36,12 @@ class ManagerAuthInterceptorTest { @Test void Auth_헤더를_Base64_헤더를_디코딩해서_관리자_로그인을_처리한다() throws Exception { // given - final String s = "Basic "+id+":"+password; + final String s = id+":"+password; final String authHeader = new String(Base64.getEncoder().encode(s.getBytes())); final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); final Controller controller = Mockito.mock(Controller.class); - request.addHeader("Authorization", authHeader); + request.addHeader("Authorization","Basic "+ authHeader); // when final boolean expected = managerAuthInterceptor.preHandle(request, response, controller); From 85afada2ff63e2fb66aacb0ac32e45d0d766ad6a Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 08:22:59 +0900 Subject: [PATCH 10/24] =?UTF-8?q?feat:=20TemporaryPlace=EC=98=88=EC=99=B8?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../place/exception/PlaceExceptionType.java | 5 -- .../domain/TemporaryPlaceCheckService.java | 9 ++-- .../exception/TemporaryPlaceException.java | 18 +++++++ .../TemporaryPlaceExceptionType.java | 53 +++++++++++++++++++ 4 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceException.java create mode 100644 backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceExceptionType.java diff --git a/backend/src/main/java/com/now/naaga/place/exception/PlaceExceptionType.java b/backend/src/main/java/com/now/naaga/place/exception/PlaceExceptionType.java index 4c1003e49..641cc3edc 100644 --- a/backend/src/main/java/com/now/naaga/place/exception/PlaceExceptionType.java +++ b/backend/src/main/java/com/now/naaga/place/exception/PlaceExceptionType.java @@ -17,11 +17,6 @@ public enum PlaceExceptionType implements BaseExceptionType { "해당 장소가 존재하지 않습니다." ), - ALREADY_EXIST_NEARBY( - 505, - HttpStatus.BAD_REQUEST, - "이미 주변에 장소가 존재합니다." - ), ; private final int errorCode; diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlaceCheckService.java b/backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlaceCheckService.java index f20742d84..028852e2d 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlaceCheckService.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlaceCheckService.java @@ -2,13 +2,14 @@ import com.now.naaga.place.domain.Place; import com.now.naaga.place.domain.Position; -import com.now.naaga.place.exception.PlaceException; -import com.now.naaga.place.exception.PlaceExceptionType; import com.now.naaga.place.persistence.repository.PlaceRepository; -import java.util.List; +import com.now.naaga.temporaryplace.exception.TemporaryPlaceException; +import com.now.naaga.temporaryplace.exception.TemporaryPlaceExceptionType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Transactional @Service public class TemporaryPlaceCheckService { @@ -23,7 +24,7 @@ public TemporaryPlaceCheckService(final PlaceRepository placeRepository) { public void checkOtherPlaceNearby(final Position position) { List places = placeRepository.findPlaceByPositionAndDistance(position, 0.02); if (!places.isEmpty()) { - throw new PlaceException(PlaceExceptionType.ALREADY_EXIST_NEARBY); + throw new TemporaryPlaceException(TemporaryPlaceExceptionType.ALREADY_EXIST_NEARBY); } } } diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceException.java b/backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceException.java new file mode 100644 index 000000000..e724acb21 --- /dev/null +++ b/backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceException.java @@ -0,0 +1,18 @@ +package com.now.naaga.temporaryplace.exception; + +import com.now.naaga.common.exception.BaseException; +import com.now.naaga.common.exception.BaseExceptionType; + +public class TemporaryPlaceException extends BaseException { + + private final TemporaryPlaceExceptionType temporaryPlaceExceptionType; + + public TemporaryPlaceException(final TemporaryPlaceExceptionType temporaryPlaceExceptionType) { + this.temporaryPlaceExceptionType = temporaryPlaceExceptionType; + } + + @Override + public BaseExceptionType exceptionType() { + return temporaryPlaceExceptionType; + } +} diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceExceptionType.java b/backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceExceptionType.java new file mode 100644 index 000000000..d40ef5090 --- /dev/null +++ b/backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceExceptionType.java @@ -0,0 +1,53 @@ +package com.now.naaga.temporaryplace.exception; + +import com.now.naaga.common.exception.BaseExceptionType; +import org.springframework.http.HttpStatus; + +public enum TemporaryPlaceExceptionType implements BaseExceptionType { + + INACCESSIBLE_AUTHENTICATION( + 503, + HttpStatus.FORBIDDEN, + "해당 장소에 대한 접근권한이 없습니다." + ), + + NO_EXIST( + 504, + HttpStatus.NOT_FOUND, + "해당 장소가 존재하지 않습니다." + ), + + ALREADY_EXIST_NEARBY( + 505, + HttpStatus.BAD_REQUEST, + "이미 주변에 장소가 존재합니다." + ), + ; + + private final int errorCode; + private final HttpStatus httpStatus; + private final String errorMessage; + + TemporaryPlaceExceptionType(final int errorCode, + final HttpStatus httpStatus, + final String errorMessage) { + this.errorCode = errorCode; + this.httpStatus = httpStatus; + this.errorMessage = errorMessage; + } + + @Override + public int errorCode() { + return errorCode; + } + + @Override + public HttpStatus httpStatus() { + return httpStatus; + } + + @Override + public String errorMessage() { + return errorMessage; + } +} From a80562e7ccd34d3e5b8b9180146f141319488df3 Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 08:24:01 +0900 Subject: [PATCH 11/24] =?UTF-8?q?test:=20=EA=B2=80=EC=88=98=ED=95=A0=20?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20=EB=93=B1=EB=A1=9D=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/PlaceControllerTest.java | 53 ------ .../TemporaryPlaceControllerTest.java | 175 ++++++++++++++++++ 2 files changed, 175 insertions(+), 53 deletions(-) create mode 100644 backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java diff --git a/backend/src/test/java/com/now/naaga/place/presentation/PlaceControllerTest.java b/backend/src/test/java/com/now/naaga/place/presentation/PlaceControllerTest.java index d2fb2ea80..3ed6030fd 100644 --- a/backend/src/test/java/com/now/naaga/place/presentation/PlaceControllerTest.java +++ b/backend/src/test/java/com/now/naaga/place/presentation/PlaceControllerTest.java @@ -9,10 +9,8 @@ import com.now.naaga.common.CommonControllerTest; import com.now.naaga.common.builder.PlaceBuilder; import com.now.naaga.common.builder.PlayerBuilder; -import com.now.naaga.common.exception.ExceptionResponse; import com.now.naaga.common.infrastructure.FileManager; import com.now.naaga.place.domain.Place; -import com.now.naaga.place.exception.PlaceExceptionType; import com.now.naaga.place.presentation.dto.PlaceResponse; import com.now.naaga.player.domain.Player; import io.restassured.builder.MultiPartSpecBuilder; @@ -35,7 +33,6 @@ import java.util.List; import static com.now.naaga.common.fixture.PlaceFixture.PLACE; -import static com.now.naaga.common.fixture.PositionFixture.서울_좌표; import static io.restassured.RestAssured.given; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.ArgumentMatchers.any; @@ -116,56 +113,6 @@ protected void setUp() { } - @Test - void 장소_추가_요청_시_주변_20미터_내에_이미_등록된_목적지가_있다면_예외를_응답한다() throws FileNotFoundException { - //given - final Player player = playerBuilder.init() - .build(); - - placeBuilder.init() - .registeredPlayer(player) - .position(서울_좌표) - .build(); - - final Place seoulPlace = PLACE(); - - final AuthToken generate = authTokenGenerator.generate(player.getMember(), 1L, AuthType.KAKAO); - final String accessToken = generate.getAccessToken(); - - //when - final ExtractableResponse extract = given() - .log().all() - .multiPart(new MultiPartSpecBuilder(seoulPlace.getName()).controlName("name").charset(StandardCharsets.UTF_8).build()) - .multiPart(new MultiPartSpecBuilder(seoulPlace.getDescription()).controlName("description").charset(StandardCharsets.UTF_8).build()) - .multiPart( - new MultiPartSpecBuilder(seoulPlace.getPosition().getLatitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName("latitude").charset(StandardCharsets.UTF_8) - .build()) - .multiPart( - new MultiPartSpecBuilder(seoulPlace.getPosition().getLongitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName("longitude").charset(StandardCharsets.UTF_8) - .build()) - .multiPart(new MultiPartSpecBuilder(new FileInputStream(new File("src/test/java/com/now/naaga/place/fixture/루터회관.png"))).controlName("imageFile").charset(StandardCharsets.UTF_8) - .fileName("src/test/java/com/now/naaga/place/fixture/루터회관.png") - .mimeType("image/png").build()) - .header("Authorization", "Bearer " + accessToken) - .when() - .post("/places") - .then() - .log().all() - .extract(); - final int statusCode = extract.statusCode(); - final ExceptionResponse actual = extract.as(ExceptionResponse.class); - PlaceExceptionType exceptionType = PlaceExceptionType.ALREADY_EXIST_NEARBY; - ExceptionResponse expected = new ExceptionResponse(exceptionType.errorCode(), exceptionType.errorMessage()); - - //then - assertSoftly(softAssertions -> { - softAssertions.assertThat(statusCode).isEqualTo(HttpStatus.BAD_REQUEST.value()); - softAssertions.assertThat(expected) - .usingRecursiveComparison() - .isEqualTo(actual); - }); - } - @Test void 장소를_아이디로_조회한다() { //given diff --git a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java new file mode 100644 index 000000000..b4e970a6b --- /dev/null +++ b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java @@ -0,0 +1,175 @@ +package com.now.naaga.temporaryplace.presentation; + +import com.now.naaga.auth.domain.AuthToken; +import com.now.naaga.auth.infrastructure.AuthType; +import com.now.naaga.auth.infrastructure.jwt.AuthTokenGenerator; +import com.now.naaga.common.CommonControllerTest; +import com.now.naaga.common.builder.PlayerBuilder; +import com.now.naaga.common.builder.TemporaryPlaceBuilder; +import com.now.naaga.common.exception.ExceptionResponse; +import com.now.naaga.common.infrastructure.FileManager; +import com.now.naaga.place.domain.Place; +import com.now.naaga.player.domain.Player; +import com.now.naaga.temporaryplace.domain.TemporaryPlace; +import com.now.naaga.temporaryplace.exception.TemporaryPlaceException; +import com.now.naaga.temporaryplace.exception.TemporaryPlaceExceptionType; +import com.now.naaga.temporaryplace.presentation.dto.TemporaryPlaceResponse; +import io.restassured.builder.MultiPartSpecBuilder; +import io.restassured.response.ExtractableResponse; +import io.restassured.response.Response; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.DisplayNameGenerator; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.HttpStatus; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.math.RoundingMode; +import java.nio.charset.StandardCharsets; + +import static com.now.naaga.common.fixture.PlaceFixture.PLACE; +import static com.now.naaga.common.fixture.PositionFixture.서울_좌표; +import static com.now.naaga.common.fixture.PositionFixture.잠실_루터회관_정문_좌표; +import static com.now.naaga.common.fixture.TemporaryPlaceFixture.TEMPORARY_PLACE; +import static io.restassured.RestAssured.given; +import static org.assertj.core.api.SoftAssertions.assertSoftly; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +@ActiveProfiles("test") +@SuppressWarnings("NonAsciiCharacters") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +class TemporaryPlaceControllerTest extends CommonControllerTest { + + @Autowired + private TemporaryPlaceBuilder temporaryPlaceBuilder; + + @Autowired + private PlayerBuilder playerBuilder; + + @Autowired + private AuthTokenGenerator authTokenGenerator; + + @MockBean + private FileManager fileManager; + + @Value("${manager.id}") + private String id; + + @Value("${manager.password}") + private String password; + + @Test + void 검수할_장소_등록_요청을_받으면_추가된_검수할_장소_정보를_응답한다() throws FileNotFoundException { + //given + final Player player = playerBuilder.init() + .build(); + final AuthToken generate = authTokenGenerator.generate(player.getMember(), 1L, AuthType.KAKAO); + final String accessToken = generate.getAccessToken(); + final TemporaryPlace temporaryPlace = TEMPORARY_PLACE(); + + when(fileManager.save(any())).thenReturn(new File("/임시경로", "이미지.png")); + + //when + final ExtractableResponse extract = given() + .log().all() + .multiPart(new MultiPartSpecBuilder(temporaryPlace.getName()).controlName("name").charset(StandardCharsets.UTF_8).build()) + .multiPart(new MultiPartSpecBuilder(temporaryPlace.getDescription()).controlName("description").charset(StandardCharsets.UTF_8).build()) + .multiPart( + new MultiPartSpecBuilder(temporaryPlace.getPosition().getLatitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName( + "latitude").charset(StandardCharsets.UTF_8).build()) + .multiPart( + new MultiPartSpecBuilder(temporaryPlace.getPosition().getLongitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName( + "longitude").charset(StandardCharsets.UTF_8).build()) + .multiPart(new MultiPartSpecBuilder(new FileInputStream(new File("src/test/java/com/now/naaga/temporaryplace/fixture/루터회관.png"))).controlName( + "imageFile").charset(StandardCharsets.UTF_8) + .fileName( + "src/test/java/com/now/naaga/temporaryplace/fixture/루터회관.png") + .mimeType( + "image/png") + .build()) + .header("Authorization", "Bearer " + accessToken) + .when() + .post("/temporary-places") + .then() + .log().all() + .extract(); + final int statusCode = extract.statusCode(); + final String location = extract.header("Location"); + final TemporaryPlaceResponse actual = extract.as(TemporaryPlaceResponse.class); + final TemporaryPlaceResponse expected = TemporaryPlaceResponse.from(temporaryPlace); + + //then + assertSoftly(softAssertions -> { + softAssertions.assertThat(statusCode).isEqualTo(HttpStatus.CREATED.value()); + softAssertions.assertThat(location).isEqualTo("/temporary-places/" + actual.id()); + softAssertions.assertThat(actual) + .usingRecursiveComparison() + .ignoringFields("id", "imageUrl") + .isEqualTo(expected); + }); + + } + + @Test + void 검수할_장소_추가_요청_시_주변_20미터_내에_이미_등록된_목적지가_있다면_예외를_응답한다() throws FileNotFoundException { + //given + final Player player = playerBuilder.init() + .build(); + final AuthToken generate = authTokenGenerator.generate(player.getMember(), 1L, AuthType.KAKAO); + final String accessToken = generate.getAccessToken(); + final TemporaryPlace temporaryPlace = TEMPORARY_PLACE(); + + when(fileManager.save(any())).thenReturn(new File("/임시경로", "이미지.png")); + + temporaryPlaceBuilder.init() + .position(잠실_루터회관_정문_좌표) + .build(); + final Place seoulPlace = PLACE(); + + //when + //when + final ExtractableResponse extract = given() + .log().all() + .multiPart(new MultiPartSpecBuilder(temporaryPlace.getName()).controlName("name").charset(StandardCharsets.UTF_8).build()) + .multiPart(new MultiPartSpecBuilder(temporaryPlace.getDescription()).controlName("description").charset(StandardCharsets.UTF_8).build()) + .multiPart( + new MultiPartSpecBuilder(temporaryPlace.getPosition().getLatitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName( + "latitude").charset(StandardCharsets.UTF_8).build()) + .multiPart( + new MultiPartSpecBuilder(temporaryPlace.getPosition().getLongitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName( + "longitude").charset(StandardCharsets.UTF_8).build()) + .multiPart(new MultiPartSpecBuilder(new FileInputStream(new File("src/test/java/com/now/naaga/temporaryplace/fixture/루터회관.png"))).controlName( + "imageFile").charset(StandardCharsets.UTF_8) + .fileName( + "src/test/java/com/now/naaga/temporaryplace/fixture/루터회관.png") + .mimeType( + "image/png") + .build()) + .header("Authorization", "Bearer " + accessToken) + .when() + .post("/temporary-places") + .then() + .log().all() + .extract(); + + final int statusCode = extract.statusCode(); + final ExceptionResponse actual = extract.as(ExceptionResponse.class); + TemporaryPlaceExceptionType exceptionType = TemporaryPlaceExceptionType.ALREADY_EXIST_NEARBY; + ExceptionResponse expected = new ExceptionResponse(exceptionType.errorCode(), exceptionType.errorMessage()); + + //then + assertSoftly(softAssertions -> { + softAssertions.assertThat(statusCode).isEqualTo(HttpStatus.BAD_REQUEST.value()); + softAssertions.assertThat(expected) + .usingRecursiveComparison() + .isEqualTo(actual); + }); + } +} From 3cd65624cc6ba5a93925ca5aad7518d7bc433b62 Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 08:27:10 +0900 Subject: [PATCH 12/24] =?UTF-8?q?test:=20=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/PlaceControllerTest.java | 54 ------------------- .../TemporaryPlaceControllerTest.java | 8 +-- 2 files changed, 4 insertions(+), 58 deletions(-) diff --git a/backend/src/test/java/com/now/naaga/place/presentation/PlaceControllerTest.java b/backend/src/test/java/com/now/naaga/place/presentation/PlaceControllerTest.java index 3ed6030fd..a3ec685b0 100644 --- a/backend/src/test/java/com/now/naaga/place/presentation/PlaceControllerTest.java +++ b/backend/src/test/java/com/now/naaga/place/presentation/PlaceControllerTest.java @@ -59,60 +59,6 @@ protected void setUp() { super.setUp(); } - @Test - void 장소_추가_요청을_받으면_추가된_장소_정보를_응답한다() throws FileNotFoundException { - //given - final Player player = playerBuilder.init() - .build(); - - final Place place = PLACE(); - - when(fileManager.save(any())).thenReturn(new File("/임시경로", "이미지.png")); - - final AuthToken generate = authTokenGenerator.generate(player.getMember(), 1L, AuthType.KAKAO); - final String accessToken = generate.getAccessToken(); - - //when - final ExtractableResponse extract = given() - .log().all() - .multiPart(new MultiPartSpecBuilder(place.getName()).controlName("name").charset(StandardCharsets.UTF_8).build()) - .multiPart(new MultiPartSpecBuilder(place.getDescription()).controlName("description").charset(StandardCharsets.UTF_8).build()) - .multiPart( - new MultiPartSpecBuilder(place.getPosition().getLatitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName( - "latitude").charset(StandardCharsets.UTF_8).build()) - .multiPart( - new MultiPartSpecBuilder(place.getPosition().getLongitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName( - "longitude").charset(StandardCharsets.UTF_8).build()) - .multiPart(new MultiPartSpecBuilder(new FileInputStream(new File("src/test/java/com/now/naaga/place/fixture/루터회관.png"))).controlName( - "imageFile").charset(StandardCharsets.UTF_8) - .fileName( - "src/test/java/com/now/naaga/place/fixture/루터회관.png") - .mimeType( - "image/png") - .build()) - .header("Authorization", "Bearer " + accessToken) - .when() - .post("/places") - .then() - .log().all() - .extract(); - final int statusCode = extract.statusCode(); - final String location = extract.header("Location"); - final PlaceResponse actual = extract.as(PlaceResponse.class); - final PlaceResponse expected = PlaceResponse.from(place); - - //then - assertSoftly(softAssertions -> { - softAssertions.assertThat(statusCode).isEqualTo(HttpStatus.CREATED.value()); - softAssertions.assertThat(location).isEqualTo("/places/" + actual.id()); - softAssertions.assertThat(expected) - .usingRecursiveComparison() - .ignoringFields("id", "imageUrl") - .isEqualTo(actual); - }); - - } - @Test void 장소를_아이디로_조회한다() { //given diff --git a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java index b4e970a6b..ad290f870 100644 --- a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java +++ b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java @@ -122,16 +122,16 @@ class TemporaryPlaceControllerTest extends CommonControllerTest { //given final Player player = playerBuilder.init() .build(); + temporaryPlaceBuilder.init() + .position(잠실_루터회관_정문_좌표) + .build(); + final AuthToken generate = authTokenGenerator.generate(player.getMember(), 1L, AuthType.KAKAO); final String accessToken = generate.getAccessToken(); final TemporaryPlace temporaryPlace = TEMPORARY_PLACE(); when(fileManager.save(any())).thenReturn(new File("/임시경로", "이미지.png")); - temporaryPlaceBuilder.init() - .position(잠실_루터회관_정문_좌표) - .build(); - final Place seoulPlace = PLACE(); //when //when From 96a2a9351b928aa074b64678f18fc9a415eccfbb Mon Sep 17 00:00:00 2001 From: dooboocookie Date: Wed, 4 Oct 2023 09:12:16 +0900 Subject: [PATCH 13/24] =?UTF-8?q?test:=2020=EB=AF=B8=ED=84=B0=EC=97=90=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=20=EB=93=B1=EB=A1=9D=EB=90=9C=20=EB=AA=A9?= =?UTF-8?q?=EC=A0=81=EC=A7=80=EA=B0=80=20=EC=9E=88=EB=8B=A4=EB=A9=B4=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EC=9D=91=EB=8B=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TemporaryPlaceControllerTest.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java index ad290f870..2331e0c59 100644 --- a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java +++ b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java @@ -4,6 +4,7 @@ import com.now.naaga.auth.infrastructure.AuthType; import com.now.naaga.auth.infrastructure.jwt.AuthTokenGenerator; import com.now.naaga.common.CommonControllerTest; +import com.now.naaga.common.builder.PlaceBuilder; import com.now.naaga.common.builder.PlayerBuilder; import com.now.naaga.common.builder.TemporaryPlaceBuilder; import com.now.naaga.common.exception.ExceptionResponse; @@ -50,6 +51,9 @@ class TemporaryPlaceControllerTest extends CommonControllerTest { @Autowired private TemporaryPlaceBuilder temporaryPlaceBuilder; + @Autowired + private PlaceBuilder placeBuilder; + @Autowired private PlayerBuilder playerBuilder; @@ -122,28 +126,25 @@ class TemporaryPlaceControllerTest extends CommonControllerTest { //given final Player player = playerBuilder.init() .build(); - temporaryPlaceBuilder.init() + final Place place = placeBuilder.init() .position(잠실_루터회관_정문_좌표) .build(); + final TemporaryPlace temporaryPlace = TEMPORARY_PLACE(); final AuthToken generate = authTokenGenerator.generate(player.getMember(), 1L, AuthType.KAKAO); final String accessToken = generate.getAccessToken(); - final TemporaryPlace temporaryPlace = TEMPORARY_PLACE(); - when(fileManager.save(any())).thenReturn(new File("/임시경로", "이미지.png")); - - //when //when final ExtractableResponse extract = given() .log().all() .multiPart(new MultiPartSpecBuilder(temporaryPlace.getName()).controlName("name").charset(StandardCharsets.UTF_8).build()) .multiPart(new MultiPartSpecBuilder(temporaryPlace.getDescription()).controlName("description").charset(StandardCharsets.UTF_8).build()) .multiPart( - new MultiPartSpecBuilder(temporaryPlace.getPosition().getLatitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName( + new MultiPartSpecBuilder(place.getPosition().getLatitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName( "latitude").charset(StandardCharsets.UTF_8).build()) .multiPart( - new MultiPartSpecBuilder(temporaryPlace.getPosition().getLongitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName( + new MultiPartSpecBuilder(place.getPosition().getLongitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName( "longitude").charset(StandardCharsets.UTF_8).build()) .multiPart(new MultiPartSpecBuilder(new FileInputStream(new File("src/test/java/com/now/naaga/temporaryplace/fixture/루터회관.png"))).controlName( "imageFile").charset(StandardCharsets.UTF_8) @@ -161,8 +162,8 @@ class TemporaryPlaceControllerTest extends CommonControllerTest { final int statusCode = extract.statusCode(); final ExceptionResponse actual = extract.as(ExceptionResponse.class); - TemporaryPlaceExceptionType exceptionType = TemporaryPlaceExceptionType.ALREADY_EXIST_NEARBY; - ExceptionResponse expected = new ExceptionResponse(exceptionType.errorCode(), exceptionType.errorMessage()); + final TemporaryPlaceExceptionType exceptionType = TemporaryPlaceExceptionType.ALREADY_EXIST_NEARBY; + final ExceptionResponse expected = new ExceptionResponse(exceptionType.errorCode(), exceptionType.errorMessage()); //then assertSoftly(softAssertions -> { From 4fa26c4449e22c94f65c8e5a39f1d1fd636011ab Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 12:40:47 +0900 Subject: [PATCH 14/24] =?UTF-8?q?refactor:=20=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/TemporaryPlaceService.java | 6 --- .../exception/TemporaryPlaceException.java | 18 ------- .../TemporaryPlaceExceptionType.java | 53 ------------------- 3 files changed, 77 deletions(-) delete mode 100644 backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceException.java delete mode 100644 backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceExceptionType.java diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java b/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java index fcb7fc2b0..ff37a1910 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java @@ -6,7 +6,6 @@ import com.now.naaga.player.domain.Player; import com.now.naaga.temporaryplace.application.dto.CreateTemporaryPlaceCommand; import com.now.naaga.temporaryplace.domain.TemporaryPlace; -import com.now.naaga.temporaryplace.domain.TemporaryPlaceCheckService; import com.now.naaga.temporaryplace.repository.TemporaryPlaceRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -24,23 +23,18 @@ public class TemporaryPlaceService { private final PlayerService playerService; - private final TemporaryPlaceCheckService temporaryPlaceCheckService; - private final FileManager fileManager; public TemporaryPlaceService(final TemporaryPlaceRepository temporaryPlaceRepository, final PlayerService playerService, - final TemporaryPlaceCheckService temporaryPlaceCheckService, final FileManager fileManager) { this.temporaryPlaceRepository = temporaryPlaceRepository; this.playerService = playerService; - this.temporaryPlaceCheckService = temporaryPlaceCheckService; this.fileManager = fileManager; } public TemporaryPlace createTemporaryPlace(final CreateTemporaryPlaceCommand createTemporaryPlaceCommand) { final Position position = createTemporaryPlaceCommand.position(); - temporaryPlaceCheckService.checkOtherPlaceNearby(position); final File uploadPath = fileManager.save(createTemporaryPlaceCommand.imageFile()); try { final Long playerId = createTemporaryPlaceCommand.playerId(); diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceException.java b/backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceException.java deleted file mode 100644 index e724acb21..000000000 --- a/backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceException.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.now.naaga.temporaryplace.exception; - -import com.now.naaga.common.exception.BaseException; -import com.now.naaga.common.exception.BaseExceptionType; - -public class TemporaryPlaceException extends BaseException { - - private final TemporaryPlaceExceptionType temporaryPlaceExceptionType; - - public TemporaryPlaceException(final TemporaryPlaceExceptionType temporaryPlaceExceptionType) { - this.temporaryPlaceExceptionType = temporaryPlaceExceptionType; - } - - @Override - public BaseExceptionType exceptionType() { - return temporaryPlaceExceptionType; - } -} diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceExceptionType.java b/backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceExceptionType.java deleted file mode 100644 index d40ef5090..000000000 --- a/backend/src/main/java/com/now/naaga/temporaryplace/exception/TemporaryPlaceExceptionType.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.now.naaga.temporaryplace.exception; - -import com.now.naaga.common.exception.BaseExceptionType; -import org.springframework.http.HttpStatus; - -public enum TemporaryPlaceExceptionType implements BaseExceptionType { - - INACCESSIBLE_AUTHENTICATION( - 503, - HttpStatus.FORBIDDEN, - "해당 장소에 대한 접근권한이 없습니다." - ), - - NO_EXIST( - 504, - HttpStatus.NOT_FOUND, - "해당 장소가 존재하지 않습니다." - ), - - ALREADY_EXIST_NEARBY( - 505, - HttpStatus.BAD_REQUEST, - "이미 주변에 장소가 존재합니다." - ), - ; - - private final int errorCode; - private final HttpStatus httpStatus; - private final String errorMessage; - - TemporaryPlaceExceptionType(final int errorCode, - final HttpStatus httpStatus, - final String errorMessage) { - this.errorCode = errorCode; - this.httpStatus = httpStatus; - this.errorMessage = errorMessage; - } - - @Override - public int errorCode() { - return errorCode; - } - - @Override - public HttpStatus httpStatus() { - return httpStatus; - } - - @Override - public String errorMessage() { - return errorMessage; - } -} From 421daa03c0b13ac0be2f4a40d31512559d09d83a Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 12:41:36 +0900 Subject: [PATCH 15/24] =?UTF-8?q?refactor:=20PlaceCheckService=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/PlaceCheckService.java} | 14 ++++++-------- .../naaga/place/exception/PlaceExceptionType.java | 6 ++++++ 2 files changed, 12 insertions(+), 8 deletions(-) rename backend/src/main/java/com/now/naaga/{temporaryplace/domain/TemporaryPlaceCheckService.java => place/domain/PlaceCheckService.java} (54%) diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlaceCheckService.java b/backend/src/main/java/com/now/naaga/place/domain/PlaceCheckService.java similarity index 54% rename from backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlaceCheckService.java rename to backend/src/main/java/com/now/naaga/place/domain/PlaceCheckService.java index 028852e2d..b44b9ac6e 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlaceCheckService.java +++ b/backend/src/main/java/com/now/naaga/place/domain/PlaceCheckService.java @@ -1,10 +1,8 @@ -package com.now.naaga.temporaryplace.domain; +package com.now.naaga.place.domain; -import com.now.naaga.place.domain.Place; -import com.now.naaga.place.domain.Position; +import com.now.naaga.place.exception.PlaceException; +import com.now.naaga.place.exception.PlaceExceptionType; import com.now.naaga.place.persistence.repository.PlaceRepository; -import com.now.naaga.temporaryplace.exception.TemporaryPlaceException; -import com.now.naaga.temporaryplace.exception.TemporaryPlaceExceptionType; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -12,11 +10,11 @@ @Transactional @Service -public class TemporaryPlaceCheckService { +public class PlaceCheckService { private final PlaceRepository placeRepository; - public TemporaryPlaceCheckService(final PlaceRepository placeRepository) { + public PlaceCheckService(final PlaceRepository placeRepository) { this.placeRepository = placeRepository; } @@ -24,7 +22,7 @@ public TemporaryPlaceCheckService(final PlaceRepository placeRepository) { public void checkOtherPlaceNearby(final Position position) { List places = placeRepository.findPlaceByPositionAndDistance(position, 0.02); if (!places.isEmpty()) { - throw new TemporaryPlaceException(TemporaryPlaceExceptionType.ALREADY_EXIST_NEARBY); + throw new PlaceException(PlaceExceptionType.ALREADY_EXIST_NEARBY); } } } diff --git a/backend/src/main/java/com/now/naaga/place/exception/PlaceExceptionType.java b/backend/src/main/java/com/now/naaga/place/exception/PlaceExceptionType.java index 641cc3edc..c8fb4ca22 100644 --- a/backend/src/main/java/com/now/naaga/place/exception/PlaceExceptionType.java +++ b/backend/src/main/java/com/now/naaga/place/exception/PlaceExceptionType.java @@ -17,6 +17,12 @@ public enum PlaceExceptionType implements BaseExceptionType { "해당 장소가 존재하지 않습니다." ), + ALREADY_EXIST_NEARBY( + 505, + HttpStatus.BAD_REQUEST, + "이미 주변에 장소가 존재합니다." + ), + ; private final int errorCode; From 01ebc2c5f13e3a6fdb2e9525c8c9f0166d05912f Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 12:42:17 +0900 Subject: [PATCH 16/24] =?UTF-8?q?test:=20=EA=B2=80=EC=88=98=ED=95=A0=20?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TemporaryPlaceControllerTest.java | 65 +++++++------------ 1 file changed, 23 insertions(+), 42 deletions(-) diff --git a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java index 2331e0c59..e076f8a90 100644 --- a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java +++ b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java @@ -1,5 +1,8 @@ package com.now.naaga.temporaryplace.presentation; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import com.now.naaga.auth.domain.AuthToken; import com.now.naaga.auth.infrastructure.AuthType; import com.now.naaga.auth.infrastructure.jwt.AuthTokenGenerator; @@ -7,17 +10,14 @@ import com.now.naaga.common.builder.PlaceBuilder; import com.now.naaga.common.builder.PlayerBuilder; import com.now.naaga.common.builder.TemporaryPlaceBuilder; -import com.now.naaga.common.exception.ExceptionResponse; import com.now.naaga.common.infrastructure.FileManager; -import com.now.naaga.place.domain.Place; import com.now.naaga.player.domain.Player; import com.now.naaga.temporaryplace.domain.TemporaryPlace; -import com.now.naaga.temporaryplace.exception.TemporaryPlaceException; -import com.now.naaga.temporaryplace.exception.TemporaryPlaceExceptionType; import com.now.naaga.temporaryplace.presentation.dto.TemporaryPlaceResponse; import io.restassured.builder.MultiPartSpecBuilder; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; @@ -33,10 +33,8 @@ import java.io.FileNotFoundException; import java.math.RoundingMode; import java.nio.charset.StandardCharsets; +import java.util.List; -import static com.now.naaga.common.fixture.PlaceFixture.PLACE; -import static com.now.naaga.common.fixture.PositionFixture.서울_좌표; -import static com.now.naaga.common.fixture.PositionFixture.잠실_루터회관_정문_좌표; import static com.now.naaga.common.fixture.TemporaryPlaceFixture.TEMPORARY_PLACE; import static io.restassured.RestAssured.given; import static org.assertj.core.api.SoftAssertions.assertSoftly; @@ -60,6 +58,9 @@ class TemporaryPlaceControllerTest extends CommonControllerTest { @Autowired private AuthTokenGenerator authTokenGenerator; + @Autowired + private ObjectMapper objectMapper; + @MockBean private FileManager fileManager; @@ -69,8 +70,13 @@ class TemporaryPlaceControllerTest extends CommonControllerTest { @Value("${manager.password}") private String password; + @BeforeEach + void setup() { + super.setUp(); + } + @Test - void 검수할_장소_등록_요청을_받으면_추가된_검수할_장소_정보를_응답한다() throws FileNotFoundException { + void 검수할_장소_등록_요청을_받으면_201_상태코드와_함께_추가된_검수할_장소_정보를_응답한다() throws FileNotFoundException { //given final Player player = playerBuilder.init() .build(); @@ -118,56 +124,31 @@ class TemporaryPlaceControllerTest extends CommonControllerTest { .ignoringFields("id", "imageUrl") .isEqualTo(expected); }); - } @Test - void 검수할_장소_추가_요청_시_주변_20미터_내에_이미_등록된_목적지가_있다면_예외를_응답한다() throws FileNotFoundException { + void 검수할_장소_목록_조회_요청을_받으면_200_상태코드와_함께_검수할_장소_목록을_응답한다() throws FileNotFoundException, JsonProcessingException { //given - final Player player = playerBuilder.init() + final TemporaryPlace temporaryPlace = temporaryPlaceBuilder.init() .build(); - final Place place = placeBuilder.init() - .position(잠실_루터회관_정문_좌표) - .build(); - final TemporaryPlace temporaryPlace = TEMPORARY_PLACE(); - - final AuthToken generate = authTokenGenerator.generate(player.getMember(), 1L, AuthType.KAKAO); - final String accessToken = generate.getAccessToken(); - when(fileManager.save(any())).thenReturn(new File("/임시경로", "이미지.png")); //when final ExtractableResponse extract = given() .log().all() - .multiPart(new MultiPartSpecBuilder(temporaryPlace.getName()).controlName("name").charset(StandardCharsets.UTF_8).build()) - .multiPart(new MultiPartSpecBuilder(temporaryPlace.getDescription()).controlName("description").charset(StandardCharsets.UTF_8).build()) - .multiPart( - new MultiPartSpecBuilder(place.getPosition().getLatitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName( - "latitude").charset(StandardCharsets.UTF_8).build()) - .multiPart( - new MultiPartSpecBuilder(place.getPosition().getLongitude().setScale(6, RoundingMode.HALF_DOWN).doubleValue()).controlName( - "longitude").charset(StandardCharsets.UTF_8).build()) - .multiPart(new MultiPartSpecBuilder(new FileInputStream(new File("src/test/java/com/now/naaga/temporaryplace/fixture/루터회관.png"))).controlName( - "imageFile").charset(StandardCharsets.UTF_8) - .fileName( - "src/test/java/com/now/naaga/temporaryplace/fixture/루터회관.png") - .mimeType( - "image/png") - .build()) - .header("Authorization", "Bearer " + accessToken) + .auth().preemptive().basic(id, password) .when() - .post("/temporary-places") + .get("/temporary-places") .then() .log().all() .extract(); - final int statusCode = extract.statusCode(); - final ExceptionResponse actual = extract.as(ExceptionResponse.class); - final TemporaryPlaceExceptionType exceptionType = TemporaryPlaceExceptionType.ALREADY_EXIST_NEARBY; - final ExceptionResponse expected = new ExceptionResponse(exceptionType.errorCode(), exceptionType.errorMessage()); - + final String jsonResponse = extract.body().asString(); + final List actual = objectMapper.readValue(jsonResponse, new TypeReference>() { + }); + final List expected = TemporaryPlaceResponse.convertToResponses(List.of(temporaryPlace)); //then assertSoftly(softAssertions -> { - softAssertions.assertThat(statusCode).isEqualTo(HttpStatus.BAD_REQUEST.value()); + softAssertions.assertThat(statusCode).isEqualTo(HttpStatus.OK.value()); softAssertions.assertThat(expected) .usingRecursiveComparison() .isEqualTo(actual); From 884e107d2eb69cfa7dac456ad09449b5ab92dc56 Mon Sep 17 00:00:00 2001 From: zillionme Date: Wed, 4 Oct 2023 12:43:18 +0900 Subject: [PATCH 17/24] =?UTF-8?q?refactor:=20=EC=BD=98=EC=86=94=20?= =?UTF-8?q?=EB=A1=9C=EA=B9=85=20=EB=94=94=EB=B2=84=EA=B7=B8=20=EB=A0=88?= =?UTF-8?q?=EB=B2=A8=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/main/resources/logback-spring.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/resources/logback-spring.xml b/backend/src/main/resources/logback-spring.xml index 06a184653..d479e6c24 100644 --- a/backend/src/main/resources/logback-spring.xml +++ b/backend/src/main/resources/logback-spring.xml @@ -28,7 +28,7 @@ value="/home/ubuntu/logs"/> - + From 890d08071b7458fb4a6ac657b77a265d541cb960 Mon Sep 17 00:00:00 2001 From: zillionme Date: Thu, 5 Oct 2023 11:00:47 +0900 Subject: [PATCH 18/24] =?UTF-8?q?refactor:=20TemporaryPlace=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=A1=B0=ED=9A=8C=20=EC=BF=BC=EB=A6=AC=20n+1?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../naaga/temporaryplace/domain/TemporaryPlace.java | 11 +++-------- .../repository/TemporaryPlaceRepository.java | 7 +++++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlace.java b/backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlace.java index ac27689a2..e05972d08 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlace.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/domain/TemporaryPlace.java @@ -3,13 +3,8 @@ import com.now.naaga.common.domain.BaseEntity; import com.now.naaga.place.domain.Position; import com.now.naaga.player.domain.Player; -import jakarta.persistence.Embedded; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; +import jakarta.persistence.*; + import java.util.Objects; @Entity @@ -28,7 +23,7 @@ public class TemporaryPlace extends BaseEntity { private String imageUrl; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "player_id") private Player registeredPlayer; diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/repository/TemporaryPlaceRepository.java b/backend/src/main/java/com/now/naaga/temporaryplace/repository/TemporaryPlaceRepository.java index 6616c94a4..d9a4a1faf 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/repository/TemporaryPlaceRepository.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/repository/TemporaryPlaceRepository.java @@ -3,6 +3,13 @@ import com.now.naaga.temporaryplace.domain.TemporaryPlace; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; public interface TemporaryPlaceRepository extends JpaRepository { + + @Override + @Query("SELECT tp FROM TemporaryPlace tp JOIN FETCH tp.registeredPlayer") + List findAll(); } From 2df21000bf7f29af6758f9a7738b5ee1e7b8b7a3 Mon Sep 17 00:00:00 2001 From: zillionme Date: Thu, 5 Oct 2023 11:07:19 +0900 Subject: [PATCH 19/24] =?UTF-8?q?refactor:=20TemporaryPlaceResponse?= =?UTF-8?q?=EC=97=90=20=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/dto/TemporaryPlaceResponse.java | 6 ++++-- .../naaga/common/fixture/TemporaryPlaceFixture.java | 3 ++- .../presentation/TemporaryPlaceControllerTest.java | 12 ++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/TemporaryPlaceResponse.java b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/TemporaryPlaceResponse.java index 0e592e01d..bd524da73 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/TemporaryPlaceResponse.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/TemporaryPlaceResponse.java @@ -10,7 +10,8 @@ public record TemporaryPlaceResponse(Long id, String name, CoordinateResponse coordinate, String imageUrl, - String description + String description, + Long playerId ) { @@ -21,7 +22,8 @@ public static TemporaryPlaceResponse from(final TemporaryPlace savedTemporaryPla savedTemporaryPlace.getName(), coordinateResponse, savedTemporaryPlace.getImageUrl(), - savedTemporaryPlace.getDescription() + savedTemporaryPlace.getDescription(), + savedTemporaryPlace.getRegisteredPlayer().getId() ); } diff --git a/backend/src/test/java/com/now/naaga/common/fixture/TemporaryPlaceFixture.java b/backend/src/test/java/com/now/naaga/common/fixture/TemporaryPlaceFixture.java index 012710066..906f53597 100644 --- a/backend/src/test/java/com/now/naaga/common/fixture/TemporaryPlaceFixture.java +++ b/backend/src/test/java/com/now/naaga/common/fixture/TemporaryPlaceFixture.java @@ -2,6 +2,7 @@ import com.now.naaga.temporaryplace.domain.TemporaryPlace; +import static com.now.naaga.common.fixture.PlayerFixture.PLAYER; import static com.now.naaga.common.fixture.PositionFixture.잠실_루터회관_정문_좌표; public class TemporaryPlaceFixture { @@ -13,6 +14,6 @@ public class TemporaryPlaceFixture { public static final String IMAGE_URL = "temp_place_imageUrl"; public static TemporaryPlace TEMPORARY_PLACE() { - return new TemporaryPlace(NAME, DESCRIPTION, 잠실_루터회관_정문_좌표, IMAGE_URL, null); + return new TemporaryPlace(NAME, DESCRIPTION, 잠실_루터회관_정문_좌표, IMAGE_URL, PLAYER()); } } diff --git a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java index e076f8a90..1fd716955 100644 --- a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java +++ b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java @@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.http.HttpStatus; import org.springframework.test.context.ActiveProfiles; import org.springframework.web.multipart.MultipartFile; @@ -39,7 +39,7 @@ import static io.restassured.RestAssured.given; import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.doReturn; @ActiveProfiles("test") @SuppressWarnings("NonAsciiCharacters") @@ -61,7 +61,7 @@ class TemporaryPlaceControllerTest extends CommonControllerTest { @Autowired private ObjectMapper objectMapper; - @MockBean + @SpyBean private FileManager fileManager; @Value("${manager.id}") @@ -84,8 +84,8 @@ void setup() { final String accessToken = generate.getAccessToken(); final TemporaryPlace temporaryPlace = TEMPORARY_PLACE(); - when(fileManager.save(any())).thenReturn(new File("/임시경로", "이미지.png")); - + doReturn(new File("/임시경로", "이미지.png")).when(fileManager) + .save(any()); //when final ExtractableResponse extract = given() .log().all() @@ -121,7 +121,7 @@ void setup() { softAssertions.assertThat(location).isEqualTo("/temporary-places/" + actual.id()); softAssertions.assertThat(actual) .usingRecursiveComparison() - .ignoringFields("id", "imageUrl") + .ignoringFields("id", "imageUrl", "playerId") .isEqualTo(expected); }); } From 0cdae6210ed6ecc498458ab0e06ea7743a30bbea Mon Sep 17 00:00:00 2001 From: zillionme Date: Thu, 5 Oct 2023 11:07:27 +0900 Subject: [PATCH 20/24] =?UTF-8?q?chore:=20=EA=B0=9C=ED=96=89=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/now/naaga/place/exception/PlaceExceptionType.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/main/java/com/now/naaga/place/exception/PlaceExceptionType.java b/backend/src/main/java/com/now/naaga/place/exception/PlaceExceptionType.java index c8fb4ca22..4c1003e49 100644 --- a/backend/src/main/java/com/now/naaga/place/exception/PlaceExceptionType.java +++ b/backend/src/main/java/com/now/naaga/place/exception/PlaceExceptionType.java @@ -22,7 +22,6 @@ public enum PlaceExceptionType implements BaseExceptionType { HttpStatus.BAD_REQUEST, "이미 주변에 장소가 존재합니다." ), - ; private final int errorCode; From 0b6542599dbeeb85b0fd2c83753c23b9551877b6 Mon Sep 17 00:00:00 2001 From: zillionme Date: Thu, 5 Oct 2023 11:11:50 +0900 Subject: [PATCH 21/24] =?UTF-8?q?test:=20TemporaryPlaceControllerTest=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/TemporaryPlaceControllerTest.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java index 1fd716955..e53d15de3 100644 --- a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java +++ b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java @@ -15,6 +15,7 @@ import com.now.naaga.temporaryplace.domain.TemporaryPlace; import com.now.naaga.temporaryplace.presentation.dto.TemporaryPlaceResponse; import io.restassured.builder.MultiPartSpecBuilder; +import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import org.junit.jupiter.api.BeforeEach; @@ -44,7 +45,7 @@ @ActiveProfiles("test") @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -class TemporaryPlaceControllerTest extends CommonControllerTest { +class TemporaryPlaceCon정trollerTest extends CommonControllerTest { @Autowired private TemporaryPlaceBuilder temporaryPlaceBuilder; @@ -58,9 +59,6 @@ class TemporaryPlaceControllerTest extends CommonControllerTest { @Autowired private AuthTokenGenerator authTokenGenerator; - @Autowired - private ObjectMapper objectMapper; - @SpyBean private FileManager fileManager; @@ -142,8 +140,7 @@ void setup() { .log().all() .extract(); final int statusCode = extract.statusCode(); - final String jsonResponse = extract.body().asString(); - final List actual = objectMapper.readValue(jsonResponse, new TypeReference>() { + final List actual = extract.as(new TypeRef<>() { }); final List expected = TemporaryPlaceResponse.convertToResponses(List.of(temporaryPlace)); //then From c70ae347c19583893828b990b5b04ba85f5a506a Mon Sep 17 00:00:00 2001 From: zillionme Date: Thu, 5 Oct 2023 11:20:19 +0900 Subject: [PATCH 22/24] =?UTF-8?q?refactor:=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../naaga/temporaryplace/application/TemporaryPlaceService.java | 2 +- .../application/dto/CreateTemporaryPlaceCommand.java | 2 +- .../temporaryplace/presentation/TemporaryPlaceController.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java b/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java index ff37a1910..f15196c25 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java @@ -53,7 +53,7 @@ public TemporaryPlace createTemporaryPlace(final CreateTemporaryPlaceCommand cre } @Transactional(readOnly = true) - public List findAllPlace() { + public List findAllTemporaryPlace() { final List temporaryPlaces = temporaryPlaceRepository.findAll(); temporaryPlaces.sort(Comparator.comparing(TemporaryPlace::getCreatedAt)); return temporaryPlaces; diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/application/dto/CreateTemporaryPlaceCommand.java b/backend/src/main/java/com/now/naaga/temporaryplace/application/dto/CreateTemporaryPlaceCommand.java index d1f77f1b1..db00148f3 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/application/dto/CreateTemporaryPlaceCommand.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/application/dto/CreateTemporaryPlaceCommand.java @@ -9,7 +9,7 @@ public record CreateTemporaryPlaceCommand(Long playerId, String name, String description, Position position, - MultipartFile imageFile) { + MultipartFile imageFile) { public static CreateTemporaryPlaceCommand of(final PlayerRequest playerRequest, final CreateTemporaryPlaceRequest createTemporaryPlaceRequest) { diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java index a7eadc52c..9028e80ec 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceController.java @@ -26,7 +26,7 @@ public TemporaryPlaceController(final TemporaryPlaceService temporaryPlaceServic @GetMapping public ResponseEntity> findAllTemporaryPlace() { - final List temporaryPlaces = temporaryPlaceService.findAllPlace(); + final List temporaryPlaces = temporaryPlaceService.findAllTemporaryPlace(); final List response = TemporaryPlaceResponse.convertToResponses(temporaryPlaces); return ResponseEntity .status(HttpStatus.OK) From 3057dba79fe21e7fbe6bbd89c035fa79e5853d38 Mon Sep 17 00:00:00 2001 From: zillionme Date: Thu, 5 Oct 2023 11:23:45 +0900 Subject: [PATCH 23/24] =?UTF-8?q?refactor:=20TemporaryPlaceResponse=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/dto/TemporaryPlaceResponse.java | 2 +- .../presentation/TemporaryPlaceControllerTest.java | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/TemporaryPlaceResponse.java b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/TemporaryPlaceResponse.java index bd524da73..2730c3832 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/TemporaryPlaceResponse.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/presentation/dto/TemporaryPlaceResponse.java @@ -11,7 +11,7 @@ public record TemporaryPlaceResponse(Long id, CoordinateResponse coordinate, String imageUrl, String description, - Long playerId + Long registeredPlayerId ) { diff --git a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java index e53d15de3..2a4a92df7 100644 --- a/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java +++ b/backend/src/test/java/com/now/naaga/temporaryplace/presentation/TemporaryPlaceControllerTest.java @@ -1,8 +1,6 @@ package com.now.naaga.temporaryplace.presentation; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; import com.now.naaga.auth.domain.AuthToken; import com.now.naaga.auth.infrastructure.AuthType; import com.now.naaga.auth.infrastructure.jwt.AuthTokenGenerator; @@ -45,7 +43,7 @@ @ActiveProfiles("test") @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -class TemporaryPlaceCon정trollerTest extends CommonControllerTest { +class TemporaryPlaceControllerTest extends CommonControllerTest { @Autowired private TemporaryPlaceBuilder temporaryPlaceBuilder; @@ -119,7 +117,7 @@ void setup() { softAssertions.assertThat(location).isEqualTo("/temporary-places/" + actual.id()); softAssertions.assertThat(actual) .usingRecursiveComparison() - .ignoringFields("id", "imageUrl", "playerId") + .ignoringFields("id", "imageUrl", "registeredPlayerId") .isEqualTo(expected); }); } From 2be9c53b60b22aceab52cb1938a8692e582ed8c2 Mon Sep 17 00:00:00 2001 From: zillionme Date: Thu, 5 Oct 2023 11:33:06 +0900 Subject: [PATCH 24/24] =?UTF-8?q?refactor:=20=EA=B2=80=EC=88=98=ED=95=A0?= =?UTF-8?q?=20=EC=9E=A5=EC=86=8C=20=EC=A1=B0=ED=9A=8C=20=EC=98=A4=EB=9E=98?= =?UTF-8?q?=EB=90=9C=20=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EC=A0=95=EB=A0=AC=20?= =?UTF-8?q?=EC=88=9C=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../naaga/temporaryplace/application/TemporaryPlaceService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java b/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java index f15196c25..368296126 100644 --- a/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java +++ b/backend/src/main/java/com/now/naaga/temporaryplace/application/TemporaryPlaceService.java @@ -55,7 +55,7 @@ public TemporaryPlace createTemporaryPlace(final CreateTemporaryPlaceCommand cre @Transactional(readOnly = true) public List findAllTemporaryPlace() { final List temporaryPlaces = temporaryPlaceRepository.findAll(); - temporaryPlaces.sort(Comparator.comparing(TemporaryPlace::getCreatedAt)); + temporaryPlaces.sort(Comparator.comparing(TemporaryPlace::getCreatedAt).reversed()); return temporaryPlaces; } }