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

Feature/party url 수정 #104

Merged
merged 4 commits into from
Jan 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ResponseEntity<CommonResponse<PartyResponseDTO>> createParty(
return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.OK.value(), "파티 생성 성공", responseDto));
}

@GetMapping("/{hiveId}/{partyId}")
@GetMapping("/{partyId}/hives/{hiveId}")
public ResponseEntity<CommonResponse<PartyResponseDTO>> getParty(@PathVariable Long hiveId, @PathVariable Long partyId) {

PartyResponseDTO responseDto = partyService.getPartyDto(hiveId, partyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,23 @@ public class PartyService {
private final PartyUserRepository partyUserRepository;


@Transactional
public PartyResponseDTO createParty(Long hiveId, PartyRequestDTO dto, User user) {
// Hive 존재 여부 확인
Hive hive = getHive(hiveId);

// DTO에서 날짜와 시간 정보를 가져와서 LocalDateTime 객체 생성
LocalDateTime dateTime = LocalDateTime.of(dto.getYear(), dto.getMonth(), dto.getDay(), dto.getHours(), dto.getMinutes());

// 현재 시간을 가져옵니다.
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();
}
Expand All @@ -62,8 +68,11 @@ public PartyResponseDTO createParty(Long hiveId, PartyRequestDTO dto, User user)
partyUserRepository.save(partyUser);

// 호스트 정보를 members 목록에 포함하여 PartyResponseDTO 생성
List<MemberResponseDTO> members = Collections.singletonList(new MemberResponseDTO(user.getUsername(), user.getEmail()));
return new PartyResponseDTO(savedParty.getId(), savedParty.getTitle(), savedParty.getUsername(), savedParty.getContent(), savedParty.getDateTime(), savedParty.getCreatedAt(), savedParty.getModifiedAt(), members);
List<MemberResponseDTO> members = Collections.singletonList(
new MemberResponseDTO(user.getUsername(), user.getEmail()));
return new PartyResponseDTO(savedParty.getId(), savedParty.getTitle(),
savedParty.getUsername(), savedParty.getContent(), savedParty.getDateTime(),
savedParty.getCreatedAt(), savedParty.getModifiedAt(), members);
}

//단건 조회
Expand All @@ -72,7 +81,9 @@ public PartyResponseDTO getPartyDto(Long hiveId, Long partyId) {
Party party = getParty(hiveId, partyId);
List<MemberResponseDTO> members = getPartyMembers(partyId);

return new PartyResponseDTO(party.getId(), party.getTitle(), party.getUsername(), party.getContent(), party.getDateTime(), party.getCreatedAt(), party.getModifiedAt(), members);
return new PartyResponseDTO(party.getId(), party.getTitle(),
party.getUsername(), party.getContent(), party.getDateTime(),
party.getCreatedAt(), party.getModifiedAt(), members);
}


Expand Down Expand Up @@ -110,9 +121,32 @@ public PartyResponseDTO updateParty(Long partyId, PartyRequestDTO partyRequestDt
party.setTitle(partyRequestDto.getTitle());
party.setContent(partyRequestDto.getContent());

// DTO에서 날짜와 시간 정보를 가져와 LocalDateTime 객체 생성
LocalDateTime newDateTime = LocalDateTime.of(
partyRequestDto.getYear(),
partyRequestDto.getMonth(),
partyRequestDto.getDay(),
partyRequestDto.getHours(),
partyRequestDto.getMinutes()
);

LocalDateTime now = LocalDateTime.now();

if (newDateTime.isBefore(now)) {
throw new InvalidPartyTimeException();
}

// 파티 날짜 및 시간 업데이트
party.setDateTime(newDateTime);

// 파티 저장
partyRepository.save(party);
Copy link
Contributor

Choose a reason for hiding this comment

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

오 변경감지 사용하지 않고 이렇게 저장해도 잘 반영되는군요!


List<MemberResponseDTO> members = getPartyMembers(partyId);

return new PartyResponseDTO(party.getId(), party.getTitle(), party.getUsername(), party.getContent(), party.getDateTime(), party.getCreatedAt(), party.getModifiedAt(), members);
return new PartyResponseDTO(party.getId(), party.getTitle(),
party.getUsername(), party.getContent(), party.getDateTime(),
party.getCreatedAt(), party.getModifiedAt(), members);
}

@Transactional
Expand Down
Loading