From 42dac617e2738d82312ad49c3c493a82027d4596 Mon Sep 17 00:00:00 2001 From: Srltas Date: Sun, 27 Oct 2024 15:58:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=82=B4=20=EB=8F=99=EB=84=A4=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20Controller=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../in/UserNeighborhoodController.java | 44 +++++++++++++++++++ .../adapter/in/web/common/UrlConstants.java | 1 + .../web/dto/AddUserNeighborhoodRequest.java | 11 +++++ .../srltas/runtogether/config/WebConfig.java | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/srltas/runtogether/adapter/in/UserNeighborhoodController.java create mode 100644 src/main/java/com/srltas/runtogether/adapter/in/web/dto/AddUserNeighborhoodRequest.java diff --git a/src/main/java/com/srltas/runtogether/adapter/in/UserNeighborhoodController.java b/src/main/java/com/srltas/runtogether/adapter/in/UserNeighborhoodController.java new file mode 100644 index 0000000..fd5f054 --- /dev/null +++ b/src/main/java/com/srltas/runtogether/adapter/in/UserNeighborhoodController.java @@ -0,0 +1,44 @@ +package com.srltas.runtogether.adapter.in; + +import static com.srltas.runtogether.adapter.in.web.common.SessionAttribute.*; +import static com.srltas.runtogether.adapter.in.web.common.UrlConstants.*; +import static org.springframework.http.HttpStatus.*; + +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 com.srltas.runtogether.adapter.in.web.dto.AddUserNeighborhoodRequest; +import com.srltas.runtogether.adapter.out.session.UserSessionDTO; +import com.srltas.runtogether.application.port.in.AddUserNeighborhood; +import com.srltas.runtogether.application.port.in.AddUserNeighborhoodCommand; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpSession; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; + +@Tag(name = "내 동네 API", description = "내 동네 API") +@RestController +@RequiredArgsConstructor +public class UserNeighborhoodController { + + private final AddUserNeighborhood addUserNeighborhood; + + @Operation( + summary = "내 동네 등록", + description = "사용자가 특정 동네를 자신의 동네로 등록합니다." + ) + @ApiResponse(responseCode = "200", description = "내 동네 등록 성공") + @PostMapping(USER_NEIGHBORHOOD_REGISTRATION) + public ResponseEntity addUserNeighborhood( + @RequestBody @Valid AddUserNeighborhoodRequest request, HttpSession session) { + UserSessionDTO userSession = (UserSessionDTO)session.getAttribute(USER_SESSION); + addUserNeighborhood.addNeighborhood( + new AddUserNeighborhoodCommand(userSession.userId(), request.neighborhoodId())); + return new ResponseEntity<>(CREATED); + } +} diff --git a/src/main/java/com/srltas/runtogether/adapter/in/web/common/UrlConstants.java b/src/main/java/com/srltas/runtogether/adapter/in/web/common/UrlConstants.java index 46ec48a..187a0b9 100644 --- a/src/main/java/com/srltas/runtogether/adapter/in/web/common/UrlConstants.java +++ b/src/main/java/com/srltas/runtogether/adapter/in/web/common/UrlConstants.java @@ -5,4 +5,5 @@ @UtilityClass public class UrlConstants { public final String NEIGHBORHOOD_VERIFICATION = "/neighborhood/verification"; + public final String USER_NEIGHBORHOOD_REGISTRATION = "/user-neighborhood"; } diff --git a/src/main/java/com/srltas/runtogether/adapter/in/web/dto/AddUserNeighborhoodRequest.java b/src/main/java/com/srltas/runtogether/adapter/in/web/dto/AddUserNeighborhoodRequest.java new file mode 100644 index 0000000..384c393 --- /dev/null +++ b/src/main/java/com/srltas/runtogether/adapter/in/web/dto/AddUserNeighborhoodRequest.java @@ -0,0 +1,11 @@ +package com.srltas.runtogether.adapter.in.web.dto; + +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.PositiveOrZero; + +public record AddUserNeighborhoodRequest( + @NotNull + @PositiveOrZero(message = "동네 ID는 0 이상의 값이어야 합니다.") + int neighborhoodId +) { +} diff --git a/src/main/java/com/srltas/runtogether/config/WebConfig.java b/src/main/java/com/srltas/runtogether/config/WebConfig.java index 5af7f46..0db05c5 100644 --- a/src/main/java/com/srltas/runtogether/config/WebConfig.java +++ b/src/main/java/com/srltas/runtogether/config/WebConfig.java @@ -21,7 +21,7 @@ public class WebConfig { public FilterRegistrationBean sessionFilterRegistration() { FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); registrationBean.setFilter(new AuthenticationFilter(sessionStorage)); - registrationBean.addUrlPatterns(NEIGHBORHOOD_VERIFICATION); + registrationBean.addUrlPatterns(NEIGHBORHOOD_VERIFICATION, USER_NEIGHBORHOOD_REGISTRATION); registrationBean.setOrder(1); return registrationBean; }