Skip to content

Commit

Permalink
Merge pull request #104 from H-Hive/feature/party
Browse files Browse the repository at this point in the history
Feature/party url 수정
  • Loading branch information
wkdehdgk159 authored Jan 29, 2024
2 parents 07fa029 + 24ca12c commit 63b9209
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
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);

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

0 comments on commit 63b9209

Please sign in to comment.