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: 방 상세 정보 페이지 구현(#33, #36) #78

Merged
merged 14 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 8 additions & 7 deletions backend/src/main/java/corea/DataInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Profile("test")
@Component
Expand Down Expand Up @@ -53,49 +54,49 @@ public void run(ApplicationArguments args) {

Room room1 = roomRepository.save(
new Room("방 제목 1", "방 설명 1", 3,
null, null, "TDD",
null, null, List.of("TDD", "클린코드"),
1, 20, member1,
LocalDateTime.of(2024, 12, 25, 12, 0),
LocalDateTime.of(2024, 12, 30, 12, 0),
Classification.BACKEND, RoomStatus.OPENED));
Room room2 = roomRepository.save(
new Room("방 제목 2", "방 설명 2", 3,
null, null, "TDD",
null, null, List.of("TDD"),
1, 20, member2,
LocalDateTime.of(2024, 12, 25, 12, 0),
LocalDateTime.of(2024, 12, 30, 12, 0),
Classification.BACKEND, RoomStatus.OPENED));
Room room3 = roomRepository.save(
new Room("방 제목 3", "방 설명 3", 3,
null, null, "TDD",
null, null, List.of("TDD"),
1, 20, member3,
LocalDateTime.of(2024, 12, 25, 12, 0),
LocalDateTime.of(2024, 12, 30, 12, 0),
Classification.ANDROID, RoomStatus.OPENED));
Room room4 = roomRepository.save(
new Room("방 제목 4", "방 설명 4", 3,
null, null, "TDD",
null, null, List.of("TDD"),
1, 20, member4,
LocalDateTime.of(2024, 12, 25, 12, 0),
LocalDateTime.of(2024, 12, 30, 12, 0),
Classification.ANDROID, RoomStatus.OPENED));
Room room5 = roomRepository.save(
new Room("방 제목 5", "방 설명 5", 3,
null, null, "TDD",
null, null, List.of("TDD"),
1, 20, member5,
LocalDateTime.of(2024, 12, 25, 12, 0),
LocalDateTime.of(2024, 12, 30, 12, 0),
Classification.FRONTEND, RoomStatus.OPENED));
Room room6 = roomRepository.save(
new Room("방 제목 6", "방 설명 6", 3,
null, null, "TDD",
null, null, List.of("TDD"),
1, 20, member6,
LocalDateTime.of(2024, 12, 25, 12, 0),
LocalDateTime.of(2024, 12, 30, 12, 0),
Classification.FRONTEND, RoomStatus.OPENED));
Room room7 = roomRepository.save(
new Room("방 제목 7", "방 설명 7", 3,
null, null, "TDD",
null, null, List.of("TDD"),
1, 20, member7,
LocalDateTime.of(2024, 12, 25, 12, 0),
LocalDateTime.of(2024, 12, 30, 12, 0),
Expand Down
15 changes: 13 additions & 2 deletions backend/src/main/java/corea/auth/domain/AuthInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@
@Getter
public class AuthInfo {

private final Long id;
private static final long NOT_EXIST_ID = -1L;
public static final AuthInfo ANONYMOUS = new AuthInfo(NOT_EXIST_ID, "", "");

private final long id;
private final String name;
private final String email;

public static AuthInfo from(Member member){
public static AuthInfo from(Member member) {
return new AuthInfo(member.getId(), member.getUserName(), member.getEmail());
}

public boolean isAnonymous() {
return id == NOT_EXIST_ID;
}

public boolean isNotAnonymous() {
return id == NOT_EXIST_ID;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import corea.auth.RequestHandler;
import corea.auth.annotation.AccessedMember;
import corea.auth.domain.AuthInfo;
import corea.member.domain.Member;
import corea.member.repository.MemberRepository;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -26,11 +27,11 @@ public boolean supportsParameter(MethodParameter parameter) {
}

@Override
public Member resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
public AuthInfo resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();

return memberRepository.findByEmail(requestHandler.extract(request))
Member member = memberRepository.findByEmail(requestHandler.extract(request))
.orElse(null);
return member == null ? AuthInfo.ANONYMOUS : AuthInfo.from(member);
}
}
11 changes: 5 additions & 6 deletions backend/src/main/java/corea/room/controller/RoomController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import corea.auth.annotation.AccessedMember;
import corea.auth.annotation.LoginMember;
import corea.auth.domain.AuthInfo;
import corea.member.domain.Member;
import corea.room.dto.RoomResponse;
import corea.room.dto.RoomResponses;
import corea.room.service.RoomService;
Expand All @@ -19,8 +18,8 @@ public class RoomController {
private final RoomService roomService;

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

Expand All @@ -37,14 +36,14 @@ public ResponseEntity<RoomResponses> participatedRooms(@LoginMember AuthInfo aut
}

@GetMapping("/opened")
public ResponseEntity<RoomResponses> openedRooms(@AccessedMember Member member,
public ResponseEntity<RoomResponses> openedRooms(@AccessedMember AuthInfo authInfo,
@RequestParam(value = "classification", defaultValue = "all") String expression,
@RequestParam(defaultValue = "0") int page) {
if (member == null) {
if (authInfo.isAnonymous()) {
RoomResponses response = roomService.findOpenedRoomsWithoutMember(expression, page);
return ResponseEntity.ok(response);
}
RoomResponses response = roomService.findOpenedRoomsWithMember(member.getId(), expression, page);
RoomResponses response = roomService.findOpenedRoomsWithMember(authInfo.getId(), expression, page);
return ResponseEntity.ok(response);
}
}
19 changes: 15 additions & 4 deletions backend/src/main/java/corea/room/domain/Room.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package corea.room.domain;

import corea.member.domain.Member;
import corea.util.StringToListConverter;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

import static jakarta.persistence.GenerationType.IDENTITY;

Expand All @@ -33,7 +35,8 @@ public class Room {
@Column(length = 32768)
private String thumbnailLink;

private String keyword;
@Convert(converter = StringToListConverter.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

private List<String> keyword;

private int currentParticipantsSize;

Expand All @@ -55,14 +58,22 @@ public class Room {
* 1. 방장이 모집 마감을 한 경우
* 2. 제한 인원이 다 찼을 경우 (방에 참여할 때 같이 검증)
* 3. 모집 기간이 끝난 경우
*
* <p>
* 1, 2의 경우 때문에 방 상태를 가지는 필드를 가져야 될듯.
* **/
**/
@Enumerated(value = EnumType.STRING)
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) {
public Room(String title, String content, int matchingSize, String repositoryLink, String thumbnailLink, List<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);
}

public boolean isOpen() {
return status.isOpen();
}

public boolean isClosed() {
return status.isClosed();
}
Comment on lines +70 to +77
Copy link
Contributor

Choose a reason for hiding this comment

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

isOpen 과 isClosed 를 분리한 이유가 궁금합니다!

status ENUM 에서 OPENED 와 CLOSED 만 존재한다면, 둘 중 하나만 남겨둬도 될 것 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

앞에 ! 를 붙히기 싫어서 둘다 했고, isOpen 이나 isClosed 말고 추가적인 상태가 생길수도 있어서 둘다 남겼습니다!

}

10 changes: 9 additions & 1 deletion backend/src/main/java/corea/room/domain/RoomStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@

public enum RoomStatus {

OPENED, CLOSED
OPENED, CLOSED;

public boolean isOpen() {
return this == OPENED;
}

public boolean isClosed() {
return this == CLOSED;
}
}
3 changes: 2 additions & 1 deletion backend/src/main/java/corea/room/dto/RoomCreateRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import corea.room.domain.RoomStatus;

import java.time.LocalDateTime;
import java.util.List;

public record RoomCreateRequest(
String title,
Expand All @@ -14,7 +15,7 @@ public record RoomCreateRequest(
String repositoryLink,
String thumbnailLink,
int matchingSize,
String keyword,
List<String> keyword,
int currentParticipantsSize,
int limitedParticipantsSize,
LocalDateTime recruitmentDeadline,
Expand Down
31 changes: 27 additions & 4 deletions backend/src/main/java/corea/room/dto/RoomResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ public record RoomResponse(
long currentParticipants,
long limitedParticipants,
LocalDateTime recruitmentDeadline,
LocalDateTime reviewDeadline
LocalDateTime reviewDeadline,
boolean isParticipated,
boolean isClosed
) {

public static RoomResponse from(Room room) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

해당 코드에서
배열 상세 조회에서 isParticipated 찾는 부분이 아직 구현 안되어서
from 메소드 하나 더 만들어서 기본으로 false 들어가게 했습니다.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

return new RoomResponse(
room.getId(),
Expand All @@ -29,11 +30,33 @@ public static RoomResponse from(Room room) {
room.getRepositoryLink(),
room.getThumbnailLink(),
room.getMatchingSize(),
List.of(room.getKeyword()),
room.getKeyword(),
room.getCurrentParticipantsSize(),
room.getLimitedParticipantsSize(),
room.getRecruitmentDeadline(),
room.getReviewDeadline(),
false,
room.isOpen()
);
}

public static RoomResponse from(Room room, boolean isParticipated) {
return new RoomResponse(
room.getId(),
room.getTitle(),
room.getContent(),
room.getManager()
.getName(),
room.getRepositoryLink(),
room.getThumbnailLink(),
room.getMatchingSize(),
room.getKeyword(),
room.getCurrentParticipantsSize(),
room.getLimitedParticipantsSize(),
room.getRecruitmentDeadline(),
room.getReviewDeadline()
room.getReviewDeadline(),
isParticipated,
room.isClosed()
);
}
}
8 changes: 6 additions & 2 deletions backend/src/main/java/corea/room/service/RoomService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package corea.room.service;

import corea.auth.domain.AuthInfo;
import corea.exception.CoreaException;
import corea.exception.ExceptionType;
import corea.matching.domain.Participation;
Expand Down Expand Up @@ -37,8 +38,11 @@ public RoomResponse create(RoomCreateRequest request) {
return RoomResponse.from(room);
}

public RoomResponse findOne(long id) {
Room room = getRoom(id);
public RoomResponse findOne(long roomId, AuthInfo authInfo) {
Room room = getRoom(roomId);
if (authInfo.isNotAnonymous() && participationRepository.existsByRoomIdAndMemberId(roomId, authInfo.getId())) {
return RoomResponse.from(room, true);
}
return RoomResponse.from(room);
}

Expand Down
24 changes: 24 additions & 0 deletions backend/src/main/java/corea/util/StringToListConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package corea.util;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

import java.util.Arrays;
import java.util.List;

@Converter
public class StringToListConverter implements AttributeConverter<List<String>, String> {

private static final String DELIMITER = ", ";

@Override
public String convertToDatabaseColumn(List<String> source) {
return String.join(DELIMITER, source);
}

@Override
public List<String> convertToEntityAttribute(String source) {
return Arrays.stream(source.split(DELIMITER))
.toList();
}
}
5 changes: 3 additions & 2 deletions backend/src/test/java/corea/fixture/RoomFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
import corea.room.domain.RoomStatus;

import java.time.LocalDateTime;
import java.util.List;

public class RoomFixture {

public static Room ROOM_DOMAIN(final Member member) {
public static Room ROOM_DOMAIN(Member member) {
return new Room(
"자바 레이싱 카 - MVC",
"MVC 패턴을 아시나요?",
4,
"https://github.com/example/java-racingcar",
"https://gongu.copyright.or.kr/gongu/wrt/cmmn/wrtFileImageView.do?wrtSn=13301655&filePath=L2Rpc2sxL25ld2RhdGEvMjAyMS8yMS9DTFMxMDAwNC8xMzMwMTY1NV9XUlRfMjFfQ0xTMTAwMDRfMjAyMTEyMTNfMQ==&thumbAt=Y&thumbSe=b_tbumb&wrtTy=10004",
"TDD,클린코드,자바",
List.of("TDD, 클린코드,자바"),
17,
30,
member,
Expand Down
14 changes: 0 additions & 14 deletions backend/src/test/java/corea/room/fixture/MemberFixture.java

This file was deleted.

29 changes: 0 additions & 29 deletions backend/src/test/java/corea/room/fixture/RoomFixture.java

This file was deleted.

Loading
Loading