Skip to content

Commit

Permalink
feat: 내 동네 등록 Controller 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Srltas committed Oct 27, 2024
1 parent 3ef8a43 commit 42dac61
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<Void> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
@UtilityClass
public class UrlConstants {
public final String NEIGHBORHOOD_VERIFICATION = "/neighborhood/verification";
public final String USER_NEIGHBORHOOD_REGISTRATION = "/user-neighborhood";
}
Original file line number Diff line number Diff line change
@@ -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
) {
}
2 changes: 1 addition & 1 deletion src/main/java/com/srltas/runtogether/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class WebConfig {
public FilterRegistrationBean<AuthenticationFilter> sessionFilterRegistration() {
FilterRegistrationBean<AuthenticationFilter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(new AuthenticationFilter(sessionStorage));
registrationBean.addUrlPatterns(NEIGHBORHOOD_VERIFICATION);
registrationBean.addUrlPatterns(NEIGHBORHOOD_VERIFICATION, USER_NEIGHBORHOOD_REGISTRATION);
registrationBean.setOrder(1);
return registrationBean;
}
Expand Down

0 comments on commit 42dac61

Please sign in to comment.