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: userId로 가입한 파티 조회 기능 구현 #84

Merged
merged 2 commits into from
Jan 21, 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 @@ -88,5 +88,15 @@ public ResponseEntity<CommonResponse<String>> resignParty(@PathVariable Long par
return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.OK.value(), "파티 탈퇴 성공", null));
}

@GetMapping("/users/{userId}")
public ResponseEntity<CommonResponse<List<PartyResponseDTO>>> getPartiesByUserId(
@PathVariable Long userId, @AuthenticationPrincipal UserDetailsImpl userDetails) {

List<PartyResponseDTO> response = partyService.getPartiesByUserId(userId);

return ResponseEntity.ok().body(CommonResponse.of(HttpStatus.OK.value(),
"유저의 파티 조회 성공", response));
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,11 @@ private List<MemberResponseDTO> getPartyMembers(Long partyId) {
.collect(Collectors.toList());
}

public List<PartyResponseDTO> getPartiesByUserId(Long userId) {

return partyUserRepository.findPartiesByUserId(userId).stream().map(party ->
new PartyResponseDTO(party.getId(), party.getTitle(), party.getUsername(),
party.getContent(), party.getDateTime(), party.getCreatedAt(),
party.getModifiedAt(), getPartyMembers(party.getId()))).toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.HHive.hhive.domain.relationship.partyuser.repository;

import com.HHive.hhive.domain.party.entity.Party;
import com.HHive.hhive.domain.relationship.partyuser.entity.PartyUser;
import com.HHive.hhive.domain.relationship.partyuser.pk.PartyUserPK;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -14,4 +15,7 @@ public interface PartyUserRepository extends JpaRepository<PartyUser, PartyUserP
boolean existsByUserIdAndPartyId(Long id, Long partyId);

boolean existsByPartyUserPK_UserIdAndPartyUserPK_PartyId(Long id, Long id1);

@Query("SELECT pu.party FROM PartyUser pu WHERE pu.user.id = :userId")
List<Party> findPartiesByUserId(Long userId);
}
Loading