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; }