Skip to content

Commit

Permalink
style: 개행 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsu5582 committed Jul 18, 2024
1 parent f837f9b commit 1909dd2
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 24 deletions.
2 changes: 2 additions & 0 deletions backend/src/main/java/corea/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {

private final LoginMemberArgumentResolver loginMemberArgumentResolver;

@Override
Expand All @@ -22,6 +23,7 @@ public void addCorsMappings(CorsRegistry registry) {
.allowCredentials(true)
.maxAge(3000);
}

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(loginMemberArgumentResolver);
Expand Down
5 changes: 3 additions & 2 deletions backend/src/main/java/corea/auth/RequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

@Component
public class RequestHandler {

private static final String AUTHORIZATION_HEADER = "Authorization";
public String extract(HttpServletRequest request){

public String extract(HttpServletRequest request) {
return request.getHeader(AUTHORIZATION_HEADER);
}

}
1 change: 1 addition & 0 deletions backend/src/main/java/corea/auth/domain/AuthInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@RequiredArgsConstructor
@Getter
public class AuthInfo {

private final Long id;

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@Component
@RequiredArgsConstructor
public class LoginMemberArgumentResolver implements HandlerMethodArgumentResolver {

private final RequestHandler requestHandler;
private final MemberRepository memberRepository;

Expand All @@ -32,7 +33,6 @@ public AuthInfo resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest,
WebDataBinderFactory binderFactory) {

HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();
Member member = memberRepository.findByEmail(requestHandler.extract(request))
.orElseThrow(()-> new CoreaException(ExceptionType.AUTHORIZATION_ERROR));
Expand Down
13 changes: 7 additions & 6 deletions backend/src/main/java/corea/exception/CoreaException.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import org.springframework.http.HttpStatus;

public class CoreaException extends RuntimeException {

private final ExceptionType exceptionType;
public CoreaException(ExceptionType exceptionType){

public CoreaException(ExceptionType exceptionType) {
super(exceptionType.getMessage());
this.exceptionType = exceptionType;
}

public CoreaException(ExceptionType exceptionType,String message) {
public CoreaException(ExceptionType exceptionType, String message) {
super(message);
this.exceptionType = exceptionType;
}
Expand All @@ -19,13 +21,12 @@ public CoreaException(ExceptionType exceptionType, Throwable cause) {
this.exceptionType = exceptionType;
}

public HttpStatus getHttpStatus(){
public HttpStatus getHttpStatus() {
return exceptionType.getHttpStatus();
}

@Override
public String getMessage(){
public String getMessage() {
return exceptionType.getMessage();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ public class ExceptionResponseHandler {

@ExceptionHandler(CoreaException.class)
public ResponseEntity<ErrorResponse> handleCoreaException(final CoreaException e) {
log.debug("Corea exception [statusCode = {}, errorMessage = {}, cause = {}]", e.getHttpStatus(), e.getMessage(),e.getCause());
log.debug("Corea exception [statusCode = {}, errorMessage = {}, cause = {}]", e.getHttpStatus(), e.getMessage(), e.getCause());
return ResponseEntity.status(e.getHttpStatus())
.body(new ErrorResponse(e.getMessage()));
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleException(final Exception e) {
log.debug("Server exception [errorMessage = {}, cause = {}]", e.getMessage(),e.getCause());
log.debug("Server exception [errorMessage = {}, cause = {}]", e.getMessage(), e.getCause());
return ResponseEntity.internalServerError()
.body(new ErrorResponse(e.getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
@RequestMapping("/participate")
@RequiredArgsConstructor
public class ParticipateController implements ParticipationControllerSpecification {

private final ParticipationService participationService;

@PostMapping("/{id}")
public ResponseEntity<Void> participate(@PathVariable long id, @LoginUser AuthInfo authInfo) {
participationService.participate(new ParticipationRequest(id,authInfo.getId()));
participationService.participate(new ParticipationRequest(id, authInfo.getId()));
return ResponseEntity.ok()
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.List;

public interface ParticipationRepository extends JpaRepository<Participation, Long> {

List<Participation> findAllByRoomId(long roomId);

boolean existsByRoomIdAndMemberId(long roomId, long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import corea.matching.domain.Participation;
import corea.matching.dto.ParticipationRequest;
import corea.matching.dto.ParticipationResponse;
import corea.member.repository.MemberRepository;
import corea.matching.repository.ParticipationRepository;
import corea.member.repository.MemberRepository;
import corea.room.repository.RoomRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -30,12 +30,12 @@ public ParticipationResponse participate(final ParticipationRequest request) {

private void validateIdExist(final long roomId, final long memberId) {
if (!roomRepository.existsById(roomId)) {
throw new CoreaException(ExceptionType.NOT_FOUND_ERROR,String.format("%d에 해당하는 방이 없습니다.",roomId));
throw new CoreaException(ExceptionType.NOT_FOUND_ERROR, String.format("%d에 해당하는 방이 없습니다.", roomId));
}
if (!memberRepository.existsById(memberId)) {
throw new CoreaException(ExceptionType.NOT_FOUND_ERROR,String.format("%d에 해당하는 멤버가 없습니다.",memberId));
throw new CoreaException(ExceptionType.NOT_FOUND_ERROR, String.format("%d에 해당하는 멤버가 없습니다.", memberId));
}
if(participationRepository.existsByRoomIdAndMemberId(roomId, memberId)) {
if (participationRepository.existsByRoomIdAndMemberId(roomId, memberId)) {
throw new CoreaException(ExceptionType.ALREADY_APPLY);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import corea.room.service.RoomService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rooms")
Expand All @@ -14,15 +17,12 @@ public class RoomController {

private final RoomService roomService;


@GetMapping("/{id}")
public ResponseEntity<RoomResponse> room(@PathVariable final long id) {
final RoomResponse response = roomService.findOne(id);
return ResponseEntity.ok(response);
}



@GetMapping
public ResponseEntity<RoomResponses> rooms() {
final RoomResponses response = roomService.findAll();
Expand Down
4 changes: 2 additions & 2 deletions backend/src/main/java/corea/room/dto/RoomResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static RoomResponse of(final Room room) {
return new RoomResponse(
room.getId(), room.getTitle(), room.getContent(), room.getManager().getEmail(),
room.getRepositoryLink(), room.getThumbnailLink(), room.getMatchingSize(), List.of(room.getKeyword()),
room.getCurrentParticipantsSize(),room.getLimitedParticipantsSize(),room.getRecruitmentDeadline(),room.getReviewDeadline()
);
room.getCurrentParticipantsSize(), room.getLimitedParticipantsSize(), room.getRecruitmentDeadline(), room.getReviewDeadline()
);
}
}
1 change: 1 addition & 0 deletions backend/src/test/java/config/TestExecutionListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Optional;

public class TestExecutionListener extends AbstractTestExecutionListener {

@Override
public void beforeTestClass(final TestContext testContext) {
RestAssured.port = Optional.ofNullable(testContext.getApplicationContext()
Expand Down
4 changes: 3 additions & 1 deletion backend/src/test/java/corea/fixture/MemberFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import corea.member.domain.Member;

public class MemberFixture {

public static Member MEMBER_DOMAIN() {
return new Member(
"youngsu5582",
Expand All @@ -13,7 +14,8 @@ public static Member MEMBER_DOMAIN() {
36.5f
);
}
public static Member MEMBER_MANAGER(){

public static Member MEMBER_MANAGER() {
return new Member(
"joyson5582",
"https://avatars.githubusercontent.com/u/98307410?v=4",
Expand Down
1 change: 1 addition & 0 deletions backend/src/test/java/corea/fixture/RoomFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.time.LocalDateTime;

public class RoomFixture {

public static Room ROOM_DOMAIN(final Member member) {
return new Room(
"자바 레이싱 카 - MVC",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void participate() {

Member member = memberRepository.save(MemberFixture.MEMBER_DOMAIN());
//@formatter:off
RestAssured.given().header(new Header("Authorization",member.getEmail())).contentType(ContentType.JSON)
RestAssured.given().header(new Header("Authorization", member.getEmail())).contentType(ContentType.JSON)
.when().post("/participate/"+room.getId())
.then().assertThat().statusCode(200);
//@formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

@ServiceTest
class ParticipationServiceTest {

@Autowired
private ParticipationService sut;

Expand Down

0 comments on commit 1909dd2

Please sign in to comment.