-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature/party 업데이트,조회 수정, 약속 시간 기능 추가 #69
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
|
@@ -35,7 +36,17 @@ public PartyResponseDTO createParty(Long hiveId, PartyRequestDTO dto, User user) | |
Hive hive = hiveRepository.findById(hiveId) | ||
.orElseThrow(NotFoundHiveException::new); | ||
|
||
Party party = new Party(hive, dto, user); | ||
LocalDateTime dateTime = LocalDateTime.of(dto.getYear(), dto.getMonth(), dto.getDay(), dto.getHours(), dto.getMinutes()); | ||
|
||
// 현재 시간을 가져옵니다. | ||
LocalDateTime now = LocalDateTime.now(); | ||
|
||
// 설정하려는 약속 시간이 과거인지 확인합니다. | ||
if (dateTime.isBefore(now)) { | ||
throw new InvalidPartyTimeException(); | ||
} | ||
|
||
Party party = new Party(hive, dto, user, dateTime); | ||
party.setUser(user); | ||
|
||
var saved = partyRepository.save(party); | ||
|
@@ -46,28 +57,33 @@ public PartyResponseDTO createParty(Long hiveId, PartyRequestDTO dto, User user) | |
//단건 조회 | ||
@Transactional | ||
public PartyResponseDTO getPartyDto(Long partyId) { | ||
Party party = partyRepository.findById(partyId).orElseThrow(PartyNotFoundException::new); | ||
Party party = partyRepository.findById(partyId) | ||
.filter(p -> !p.isDeleted()) // 삭제 되지 않은 파티만 필터링 | ||
.orElseThrow(PartyNotFoundException::new); | ||
|
||
List<MemberResponseDTO> members = partyUserRepository.findUsersByPartyId(partyId).stream() | ||
.map(partyUser -> new MemberResponseDTO(partyUser.getUser().getUsername(), partyUser.getUser().getEmail())) | ||
.collect(Collectors.toList()); | ||
|
||
return new PartyResponseDTO(party.getId(), party.getTitle(), party.getUsername(), party.getContent(), party.getCreatedAt(), party.getModifiedAt(), members); | ||
return new PartyResponseDTO(party.getId(), party.getTitle(), party.getUsername(), party.getContent(),party.getDateTime(), party.getCreatedAt(), party.getModifiedAt(), members); | ||
} | ||
|
||
//전체 조회 | ||
@Transactional | ||
public Map<UserInfoResponseDTO, List<PartyResponseDTO>> getUserPartyMap() { | ||
Map<UserInfoResponseDTO, List<PartyResponseDTO>> userPartyMap = new HashMap<>(); | ||
|
||
List<Party> partyList = partyRepository.findAll(Sort.by(Sort.Direction.DESC, "createdAt")); | ||
List<Party> partyList = partyRepository.findAll(Sort.by(Sort.Direction.DESC, "createdAt")).stream() | ||
.filter(p -> !p.isDeleted()) | ||
.collect(Collectors.toList()); | ||
|
||
for (Party party : partyList) { | ||
UserInfoResponseDTO userDto = new UserInfoResponseDTO(party.getUser()); | ||
List<MemberResponseDTO> members = partyUserRepository.findUsersByPartyId(party.getId()).stream() | ||
.map(partyUser -> new MemberResponseDTO(partyUser.getUser().getUsername(), partyUser.getUser().getEmail())) | ||
.collect(Collectors.toList()); | ||
|
||
PartyResponseDTO partyDto = new PartyResponseDTO(party.getId(), party.getTitle(), party.getUsername(), party.getContent(), party.getCreatedAt(), party.getModifiedAt(), members); | ||
PartyResponseDTO partyDto = new PartyResponseDTO(party.getId(), party.getTitle(), party.getUsername(), party.getContent(),party.getDateTime(), party.getCreatedAt(), party.getModifiedAt(), members); | ||
|
||
if (userPartyMap.containsKey(userDto)) { | ||
userPartyMap.get(userDto).add(partyDto); | ||
|
@@ -83,6 +99,10 @@ public Map<UserInfoResponseDTO, List<PartyResponseDTO>> getUserPartyMap() { | |
public PartyResponseDTO updateParty(Long partyId, PartyRequestDTO partyRequestDto, User user) { | ||
Party party = getUserParty(partyId, user); | ||
|
||
if (!party.getHostId().equals(user.getId())) { | ||
throw new UnauthorizedAccessException(); | ||
} | ||
|
||
party.setTitle(partyRequestDto.getTitle()); | ||
party.setContent(partyRequestDto.getContent()); | ||
|
||
|
@@ -92,9 +112,11 @@ public PartyResponseDTO updateParty(Long partyId, PartyRequestDTO partyRequestDt | |
@Transactional | ||
public void deleteParty(Long partyId, User user) { | ||
Party party = getUserParty(partyId, user); | ||
|
||
if (!party.getHostId().equals(user.getId())) { | ||
throw new UnauthorizedAccessException(); | ||
} | ||
|
||
party.setIsDeleted(true); | ||
partyRepository.save(party); | ||
} | ||
|
@@ -108,11 +130,19 @@ private Party getUserParty(Long partyId, User user) { | |
public void joinParty(Long partyId, User user) { | ||
Party party = getUserParty(partyId, user); | ||
|
||
// 현재 날짜를 가져옵니다. | ||
LocalDateTime now = LocalDateTime.now(); | ||
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. 다른 시간대를 다룰 경우를 대비해서 ZonedDateTime 사용은 어떠신가요? |
||
|
||
// 파티 호스트가 파티에 가입하는 것을 방지 | ||
if (party.getHostId().equals(user.getId())) { | ||
throw new PartyHostNotJoinException(); | ||
} | ||
|
||
// 파티 날짜가 현재 날짜보다 이전인 경우, 가입 불가 처리 | ||
if (party.getDateTime().isBefore(now)) { | ||
throw new EndPartyNotJoinException(); | ||
} | ||
|
||
// 중복 가입 검사 | ||
if (partyUserRepository.existsByUserIdAndPartyId(user.getId(), partyId)) { | ||
throw new AlreadyJoinException(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/HHive/hhive/global/exception/party/EndPartyNotJoinException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.HHive.hhive.global.exception.party; | ||
|
||
import com.HHive.hhive.global.exception.common.CustomException; | ||
import com.HHive.hhive.global.exception.common.ErrorCode; | ||
|
||
public class EndPartyNotJoinException extends CustomException { | ||
public EndPartyNotJoinException() { | ||
super(ErrorCode.END_PARTY_NOT_JOIN_EXCEPTION); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/HHive/hhive/global/exception/party/InvalidPartyTimeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.HHive.hhive.global.exception.party; | ||
|
||
import com.HHive.hhive.global.exception.common.CustomException; | ||
import com.HHive.hhive.global.exception.common.ErrorCode; | ||
|
||
public class InvalidPartyTimeException extends CustomException { | ||
public InvalidPartyTimeException() { | ||
super(ErrorCode.INVALID_PARTY_TIME_EXCEPTION); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
getPartyDto메서드와 getUserPartyMap메서드에서 partyUserRepository.findUsersByPartyId를 MemberResponseDTO로 변환하는 로직이 중복되어 있는데, 이걸 메서드로 추출하지 않고 중복으로 사용한 이유가 있을까요?