-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] 방 수정 기능 & 스케줄러 부분 분리 및 리팩토링(#605) #606
Changes from 1 commit
4a27da8
85b9f11
adb297b
e05bc8a
38a083b
e5264b8
800c48b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,8 @@ | |
import corea.auth.annotation.AccessedMember; | ||
import corea.auth.annotation.LoginMember; | ||
import corea.auth.domain.AuthInfo; | ||
import corea.matchresult.dto.MatchResultResponses; | ||
import corea.matchresult.service.MatchResultService; | ||
import corea.room.domain.RoomStatus; | ||
import corea.room.dto.RoomCreateRequest; | ||
import corea.room.dto.RoomParticipantResponses; | ||
import corea.room.dto.RoomResponse; | ||
import corea.room.dto.RoomResponses; | ||
import corea.room.dto.*; | ||
import corea.room.service.RoomService; | ||
import corea.scheduler.service.AutomaticMatchingService; | ||
import corea.scheduler.service.AutomaticUpdateService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
@@ -25,16 +17,18 @@ | |
public class RoomController implements RoomControllerSpecification { | ||
|
||
private final RoomService roomService; | ||
private final MatchResultService matchResultService; | ||
private final AutomaticUpdateService automaticUpdateService; | ||
private final AutomaticMatchingService automaticMatchingService; | ||
|
||
@PostMapping | ||
public ResponseEntity<RoomResponse> create(@LoginMember AuthInfo authInfo, @RequestBody RoomCreateRequest request) { | ||
RoomResponse response = roomService.create(authInfo.getId(), request); | ||
|
||
automaticMatchingService.matchOnRecruitmentDeadline(response); | ||
automaticUpdateService.updateAtReviewDeadline(response); | ||
return ResponseEntity.created(URI.create(String.format("/rooms/%d", response.id()))) | ||
.body(response); | ||
} | ||
|
||
@PutMapping | ||
public ResponseEntity<RoomResponse> update(@LoginMember AuthInfo authInfo, @RequestBody RoomUpdateRequest request) { | ||
RoomResponse response = roomService.update(authInfo.getId(), request); | ||
|
||
return ResponseEntity.created(URI.create(String.format("/rooms/%d", response.id()))) | ||
.body(response); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update 응답 |
||
|
@@ -52,55 +46,16 @@ public ResponseEntity<RoomParticipantResponses> participants(@PathVariable long | |
return ResponseEntity.ok(response); | ||
} | ||
|
||
@GetMapping("/{id}/reviewers") | ||
public ResponseEntity<MatchResultResponses> reviewers(@PathVariable long id, @LoginMember AuthInfo authInfo) { | ||
MatchResultResponses response = matchResultService.findReviewers(authInfo.getId(), id); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@GetMapping("/{id}/reviewees") | ||
public ResponseEntity<MatchResultResponses> reviewees(@PathVariable long id, @LoginMember AuthInfo authInfo) { | ||
MatchResultResponses response = matchResultService.findReviewees(authInfo.getId(), id); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@GetMapping("/participated") | ||
public ResponseEntity<RoomResponses> participatedRooms(@LoginMember AuthInfo authInfo) { | ||
RoomResponses response = roomService.findParticipatedRooms(authInfo.getId()); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@GetMapping("/opened") | ||
public ResponseEntity<RoomResponses> openedRooms(@AccessedMember AuthInfo authInfo, | ||
@RequestParam(defaultValue = "0") int page, | ||
@RequestParam(value = "classification", defaultValue = "all") String expression) { | ||
RoomResponses response = roomService.findRoomsWithRoomStatus(authInfo.getId(), page, expression, RoomStatus.OPEN); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@GetMapping("/progress") | ||
public ResponseEntity<RoomResponses> progressRooms(@AccessedMember AuthInfo authInfo, | ||
@RequestParam(defaultValue = "0") int page, | ||
@RequestParam(value = "classification", defaultValue = "all") String expression) { | ||
RoomResponses response = roomService.findRoomsWithRoomStatus(authInfo.getId(), page, expression, RoomStatus.PROGRESS); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@GetMapping("/closed") | ||
public ResponseEntity<RoomResponses> closedRooms(@AccessedMember AuthInfo authInfo, | ||
@RequestParam(defaultValue = "0") int page, | ||
@RequestParam(value = "classification", defaultValue = "all") String expression) { | ||
RoomResponses response = roomService.findRoomsWithRoomStatus(authInfo.getId(), page, expression, RoomStatus.CLOSE); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> delete(@PathVariable long id, @LoginMember AuthInfo authInfo) { | ||
roomService.delete(id, authInfo.getId()); | ||
|
||
automaticMatchingService.cancel(id); | ||
automaticUpdateService.cancel(id); | ||
|
||
return ResponseEntity.noContent() | ||
.build(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package corea.room.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import corea.member.domain.Member; | ||
import corea.room.domain.Room; | ||
import corea.room.domain.RoomClassification; | ||
import corea.room.domain.RoomStatus; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Schema(description = "방 수정 요청") | ||
public record RoomUpdateRequest( | ||
@Schema(description = "방 ID", example = "99") | ||
@NotBlank | ||
long roomId, | ||
|
||
@Schema(description = "방 제목", example = "MVC를 아시나요?") | ||
@NotBlank | ||
String title, | ||
|
||
@Schema(description = "방 내용", example = "MVC 패턴을 아시나요?") | ||
String content, | ||
|
||
@Schema(description = "repository 링크", example = "https://github.com/example/java-racingcar") | ||
@NotBlank | ||
String repositoryLink, | ||
|
||
@Schema(description = "썸네일 링크", example = "https://gongu.copyright.or.kr/gongu/wrt/cmmn/wrtFileImageView.do?wrtSn=13301655&filePath=L2Rpc2sxL25ld2RhdGEvMjAyMS8yMS9DTFMxMDAwNC8xMzMwMTY1NV9XUlRfMjFfQ0xTMTAwMDRfMjAyMTEyMTNfMQ==&thumbAt=Y&thumbSe=b_tbumb&wrtTy=10004") | ||
String thumbnailLink, | ||
|
||
@Schema(description = "상호 리뷰 인원", example = "2") | ||
@NotNull | ||
int matchingSize, | ||
|
||
@Schema(description = "중심으로 리뷰하면 좋은 키워드", example = "[\"TDD\", \"클린코드\"]") | ||
List<String> keywords, | ||
|
||
@Schema(description = "제한 참여 인원", example = "200") | ||
@NotNull | ||
int limitedParticipants, | ||
|
||
@Schema(description = "모집 마감일", example = "2024-07-30 15:00") | ||
@NotNull | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm") | ||
LocalDateTime recruitmentDeadline, | ||
|
||
@Schema(description = "리뷰 마감일", example = "2024-08-10 23:59") | ||
@NotNull | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm") | ||
LocalDateTime reviewDeadline, | ||
|
||
@Schema(description = "방이 속하는 분야", example = "BE") | ||
@NotNull | ||
RoomClassification classification | ||
) { | ||
|
||
private static final int INITIAL_PARTICIPANTS_SIZE = 1; | ||
private static final RoomStatus INITIAL_ROOM_STATUS = RoomStatus.OPEN; | ||
|
||
public Room toEntity(Member manager) { | ||
return new Room( | ||
roomId, | ||
title, content, | ||
matchingSize, repositoryLink, | ||
thumbnailLink, keywords, | ||
INITIAL_PARTICIPANTS_SIZE, limitedParticipants, | ||
manager, recruitmentDeadline, | ||
reviewDeadline, classification, | ||
INITIAL_ROOM_STATUS | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,23 @@ public RoomResponse create(long memberId, RoomCreateRequest request) { | |
return RoomResponse.of(room, participation.getMemberRole(), ParticipationStatus.MANAGER); | ||
} | ||
|
||
@Transactional | ||
public RoomResponse update(long memberId, RoomUpdateRequest request) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P5
방을 업데이트하는 로직인데 참여 여부를 확인하고 있는 것도 살짝 어색하게 느껴지고요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
�우선, 저는 방장이 무조건 리뷰어로 참여만 하는거 자체를 경계하고 있습니다.
위의 관점도 그렇고, 명확하게 |
||
Room room = getRoom(request.roomId()); | ||
if (room.isNotMatchingManager(memberId)) { | ||
throw new CoreaException(ExceptionType.MEMBER_IS_NOT_MANAGER); | ||
} | ||
Member member = memberRepository.findById(memberId) | ||
.orElseThrow(() -> new CoreaException(ExceptionType.MEMBER_NOT_FOUND)); | ||
|
||
Room updateRoom = roomRepository.save(request.toEntity(member)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P5사소하긴 한데 |
||
Participation participation = participationRepository.findByRoomIdAndMemberId(updateRoom.getId(), memberId) | ||
.orElseThrow(() -> new CoreaException(ExceptionType.NOT_ALREADY_APPLY)); | ||
|
||
roomAutomaticService.updateTime(updateRoom); | ||
return RoomResponse.of(updateRoom, participation.getMemberRole(), ParticipationStatus.MANAGER); | ||
} | ||
|
||
private void validateDeadLine(LocalDateTime recruitmentDeadline, LocalDateTime reviewDeadline) { | ||
LocalDateTime currentDateTime = LocalDateTime.now(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
명세서 있는 건가요?