-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/srltas/runtogether/adapter/in/NeighborhoodVerificationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.srltas.runtogether.adapter.in; | ||
|
||
import static com.srltas.runtogether.adapter.in.web.dto.mapper.NeighborhoodVerificationMapper.*; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.SessionAttribute; | ||
|
||
import com.srltas.runtogether.adapter.in.web.dto.NeighborhoodVerificationRequest; | ||
import com.srltas.runtogether.application.port.in.NeighborhoodVerificationCommand; | ||
import com.srltas.runtogether.application.port.in.NeighborhoodVerificationResponse; | ||
import com.srltas.runtogether.application.port.in.NeighborhoodVerificationUseCase; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class NeighborhoodVerificationController { | ||
|
||
private final NeighborhoodVerificationUseCase neighborhoodVerificationUseCase; | ||
|
||
@PostMapping("/neighborhood/verification") | ||
public ResponseEntity<NeighborhoodVerificationResponse> verifyNeighborhood( | ||
@RequestBody @Valid NeighborhoodVerificationRequest neighborhoodVerificationRequest, | ||
@SessionAttribute(name = "login_user_id", required = false) Long userId) { | ||
NeighborhoodVerificationCommand neighborhoodVerificationCommand = toCommand(neighborhoodVerificationRequest); | ||
|
||
NeighborhoodVerificationResponse response = neighborhoodVerificationUseCase.verifyAndRegisterNeighborhood( | ||
userId, neighborhoodVerificationCommand); | ||
|
||
return ResponseEntity.ok(response); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/srltas/runtogether/adapter/in/web/dto/NeighborhoodVerificationRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
package com.srltas.runtogether.adapter.in.web.dto; | ||
|
||
import org.hibernate.validator.constraints.Range; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.PositiveOrZero; | ||
|
||
public record NeighborhoodVerificationRequest( | ||
|
||
@NotNull | ||
@Range(min = -90, max = 90, message="위도는 -90에서 90 사이여야 합니다.") | ||
double latitude, | ||
|
||
@NotNull | ||
@Range(min = -180, max = 180, message="경도는 -180에서 180 사이여야 합니다.") | ||
double longitude, | ||
|
||
@NotNull | ||
@PositiveOrZero(message = "동네 ID는 0 이상의 값이어야 합니다.") | ||
int neighborhoodId | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ain/java/com/srltas/runtogether/application/port/in/NeighborhoodVerificationResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.srltas.runtogether.application.port.in; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record NeighborhoodVerificationResponse( | ||
String verifyId, | ||
boolean verified, | ||
String verificationTime | ||
) { | ||
} |
3 changes: 2 additions & 1 deletion
3
...main/java/com/srltas/runtogether/application/port/in/NeighborhoodVerificationUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.srltas.runtogether.application.port.in; | ||
|
||
public interface NeighborhoodVerificationUseCase { | ||
void verifyAndRegisterNeighborhood(long userId, NeighborhoodVerificationCommand neighborhoodVerificationCommand); | ||
NeighborhoodVerificationResponse verifyAndRegisterNeighborhood(long userId, | ||
NeighborhoodVerificationCommand neighborhoodVerificationCommand); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/java/com/srltas/runtogether/domain/model/user/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/java/com/srltas/runtogether/adapter/in/NeighborhoodVerificationControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.srltas.runtogether.adapter.in; | ||
|
||
import static org.hamcrest.MatcherAssert.*; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.mockito.BDDMockito.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import com.srltas.runtogether.adapter.in.web.dto.NeighborhoodVerificationRequest; | ||
import com.srltas.runtogether.application.port.in.NeighborhoodVerificationCommand; | ||
import com.srltas.runtogether.application.port.in.NeighborhoodVerificationResponse; | ||
import com.srltas.runtogether.application.port.in.NeighborhoodVerificationUseCase; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class NeighborhoodVerificationControllerTest { | ||
|
||
@Mock | ||
private NeighborhoodVerificationUseCase neighborhoodVerificationUseCase; | ||
|
||
@InjectMocks | ||
private NeighborhoodVerificationController neighborhoodVerificationController; | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideNeighborhoodVerificationRequests") | ||
@DisplayName("verifyNeighborhood 메서드에 대한 Parameterized 테스트") | ||
void verifyNeighborhood_ShouldReturnOkResponse(NeighborhoodVerificationRequest request, Long userId) { | ||
// given | ||
NeighborhoodVerificationCommand command = new NeighborhoodVerificationCommand(request.latitude(), | ||
request.longitude(), request.neighborhoodId()); | ||
NeighborhoodVerificationResponse expectedResponse = new NeighborhoodVerificationResponse( | ||
UUID.randomUUID().toString(), true, LocalDateTime.now().toString()); | ||
|
||
given(neighborhoodVerificationUseCase.verifyAndRegisterNeighborhood(userId, command)).willReturn( | ||
expectedResponse); | ||
|
||
// when | ||
ResponseEntity<NeighborhoodVerificationResponse> response = neighborhoodVerificationController.verifyNeighborhood( | ||
request, userId); | ||
|
||
// then | ||
verify(neighborhoodVerificationUseCase).verifyAndRegisterNeighborhood(userId, command); | ||
assertThat(response.getStatusCode(), is(HttpStatus.OK)); | ||
assertThat(response.getBody(), is(expectedResponse)); | ||
} | ||
|
||
static Stream<Arguments> provideNeighborhoodVerificationRequests() { | ||
return Stream.of( | ||
Arguments.of(new NeighborhoodVerificationRequest(37.579617, 126.977041, 1), 100L), | ||
Arguments.of(new NeighborhoodVerificationRequest(37.556201, 126.972286, 2), 101L), | ||
Arguments.of(new NeighborhoodVerificationRequest(37.497911, 127.027618, 3), 102L)); | ||
} | ||
} |