Skip to content
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] feat: 모집 중인 방 리스트 API 구현(#30) #68

Merged
merged 6 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions backend/src/main/java/corea/room/domain/Classification.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package corea.room.domain;

import corea.exception.CoreaException;
import corea.exception.ExceptionType;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;

import static java.util.stream.Collectors.toMap;

public enum Classification {

ALL("all"),
ANDROID("an"),
BACKEND("be"),
FRONTEND("fe");

private static final Map<String, Classification> CACHED_CLASSIFICATIONS = Arrays.stream(values())
.collect(toMap(classification -> classification.expression, Function.identity()));
Comment on lines +12 to +20
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Classification을 조회하려는 경우가 많을 것 같아 미리 캐싱하여 사용하도록 해보았는데, 괜츈나요??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

누군가의 발표가 생각나네요 👍


private final String expression;

Classification(String expression) {
this.expression = expression;
}

public static Classification from(String expression) {
if (CACHED_CLASSIFICATIONS.containsKey(expression)) {
return CACHED_CLASSIFICATIONS.get(expression);
}
throw new CoreaException(ExceptionType.NOT_FOUND_ERROR);
}

public boolean isAll() {
return this == ALL;
}
}
20 changes: 17 additions & 3 deletions backend/src/main/java/corea/room/domain/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,29 @@ public class Room {
private int limitedParticipantsSize;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "manager_id",foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@JoinColumn(name = "manager_id", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Member manager;

private LocalDateTime recruitmentDeadline;

private LocalDateTime reviewDeadline;

public Room(String title, String content, int matchingSize, String repositoryLink, String thumbnailLink, String keyword, int currentParticipantsSize, int limitedParticipantsSize, Member manager, LocalDateTime recruitmentDeadline, LocalDateTime reviewDeadline) {
this(null, title, content, matchingSize, repositoryLink, thumbnailLink, keyword, currentParticipantsSize, limitedParticipantsSize, manager, recruitmentDeadline, reviewDeadline);
@Enumerated(value = EnumType.STRING)
private Classification classification;

/**
* RoomStatus가 변경될 수 있는 경우 (OPENED -> CLOSED)
* 1. 방장이 모집 마감을 한 경우
* 2. 제한 인원이 다 찼을 경우 (방에 참여할 때 같이 검증)
* 3. 모집 기간이 끝난 경우
*
* 1, 2의 경우 때문에 방 상태를 가지는 필드를 가져야 될듯.
* **/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Enumerated(value = EnumType.STRING)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

괜찮은듯.
방장이 시간 전 종료하고 싶을 수도 있으니

private RoomStatus status;

public Room(String title, String content, int matchingSize, String repositoryLink, String thumbnailLink, String keyword, int currentParticipantsSize, int limitedParticipantsSize, Member manager, LocalDateTime recruitmentDeadline, LocalDateTime reviewDeadline, Classification classification, RoomStatus status) {
this(null, title, content, matchingSize, repositoryLink, thumbnailLink, keyword, currentParticipantsSize, limitedParticipantsSize, manager, recruitmentDeadline, reviewDeadline, classification, status);
}
}

6 changes: 6 additions & 0 deletions backend/src/main/java/corea/room/domain/RoomStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package corea.room.domain;

public enum RoomStatus {

OPENED, CLOSED
}
9 changes: 7 additions & 2 deletions backend/src/main/java/corea/room/dto/RoomCreateRequest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package corea.room.dto;

import corea.member.domain.Member;
import corea.room.domain.Classification;
import corea.room.domain.Room;
import corea.room.domain.RoomStatus;

import java.time.LocalDateTime;

Expand All @@ -16,13 +18,16 @@ public record RoomCreateRequest(
int currentParticipantsSize,
int limitedParticipantsSize,
LocalDateTime recruitmentDeadline,
LocalDateTime reviewDeadline
LocalDateTime reviewDeadline,
Classification classification,
RoomStatus status
) {

public Room toEntity() {
return new Room(title, content, matchingSize,
repositoryLink, thumbnailLink, keyword,
currentParticipantsSize, limitedParticipantsSize, manager,
recruitmentDeadline, reviewDeadline);
recruitmentDeadline, reviewDeadline, classification,
status);
}
}
6 changes: 5 additions & 1 deletion backend/src/test/java/corea/fixture/RoomFixture.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package corea.fixture;

import corea.member.domain.Member;
import corea.room.domain.Classification;
import corea.room.domain.Room;
import corea.room.domain.RoomStatus;

import java.time.LocalDateTime;

Expand All @@ -20,7 +22,9 @@ public static Room ROOM_DOMAIN(final Member member) {
member,
LocalDateTime.now(),
LocalDateTime.now()
.plusDays(14)
.plusDays(14),
Classification.BACKEND,
RoomStatus.OPENED
);
}
}
7 changes: 6 additions & 1 deletion backend/src/test/java/corea/room/fixture/RoomFixture.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package corea.room.fixture;

import corea.member.domain.Member;
import corea.room.domain.Classification;
import corea.room.domain.RoomStatus;
import corea.room.dto.RoomCreateRequest;

import java.time.LocalDateTime;
Expand All @@ -19,6 +21,9 @@ public static RoomCreateRequest ROOM_CREATE_REQUEST(Member member) {
15,
20,
LocalDateTime.of(2024, 12, 25, 12, 0),
LocalDateTime.of(2024, 12, 30, 12, 0));
LocalDateTime.of(2024, 12, 30, 12, 0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now + plusDay 로 하지 않고
지정한 이유가 있는지?

Classification.BACKEND,
RoomStatus.OPENED
);
}
}