Skip to content
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 @@ -68,4 +68,16 @@ long countActivePartiesByHostId(
@Param("userId") Long userId,
@Param("activeStatuses") List<PartyStatus> activeStatuses
);
}

@Query("SELECT pp FROM PartyParticipant pp " +
"JOIN FETCH pp.party p " +
"JOIN FETCH p.host " +
"WHERE pp.user.userId = :userId " +
"AND p.host.userId != :userId " +
"AND p.status = :partyStatus " +
"AND pp.status = :participantStatus")
List<PartyParticipant> findActivePartiesByUserIdExcludingHost(
@Param("userId") Long userId,
@Param("partyStatus") PartyStatus partyStatus,
@Param("participantStatus") ParticipantStatus participantStatus
);}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;
import java.util.Optional;

import ita.tinybite.domain.party.enums.PartyStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
Expand All @@ -20,5 +21,7 @@ public interface PartyRepository extends JpaRepository<Party, Long> {
List<Party> findByPickupLocation_Place(String place);

List<Party> findByPickupLocation_PlaceAndCategory(String place, PartyCategory category);

List<Party> findByHostUserIdAndStatus(Long userId, PartyStatus partyStatus);
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.ErrorResponse;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down Expand Up @@ -111,19 +112,65 @@ public APIResponse<RejoinValidationResponse> validateRejoin(
return success(response);
}

@Operation(summary = "활성 파티 목록 조회", description = "사용자가 참여 중인 활성 파티 목록을 조회합니다.")
@Operation(
summary = "호스팅 중인 파티 목록 조회",
description = "현재 사용자가 호스트로 있는 활성 파티 목록을 조회합니다."
)
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공",
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PartyCardResponse.class)))),
@ApiResponse(responseCode = "401", description = "인증 실패")
@ApiResponse(
responseCode = "200",
description = "조회 성공",
content = @Content(
array = @ArraySchema(schema = @Schema(implementation = PartyCardResponse.class))
)
),
@ApiResponse(
responseCode = "401",
description = "인증 실패",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
)
})
@GetMapping("/parties/active")
public ResponseEntity<List<PartyCardResponse>> getActiveParties(
@GetMapping("/parties/hosting")
public ResponseEntity<List<PartyCardResponse>> getHostingParties(
@AuthenticationPrincipal Long userId) {
List<PartyCardResponse> response = userService.getActiveParties(userId);
List<PartyCardResponse> response = userService.getHostingParties(userId);
return ResponseEntity.ok(response);
}

@ApiResponses({
@ApiResponse(
responseCode = "200",
description = "조회 성공",
content = @Content(
array = @ArraySchema(schema = @Schema(implementation = PartyCardResponse.class))
)
),
@ApiResponse(
responseCode = "401",
description = "인증 실패",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
)
})
@GetMapping("/parties/participating")
public ResponseEntity<List<PartyCardResponse>> getParticipatingParties(
@AuthenticationPrincipal Long userId) {
List<PartyCardResponse> response = userService.getParticipatingParties(userId);
return ResponseEntity.ok(response);
}

// @Operation(summary = "활성 파티 목록 조회", description = "사용자가 참여 중인 활성 파티 목록을 조회합니다.")
// @ApiResponses({
// @ApiResponse(responseCode = "200", description = "조회 성공",
// content = @Content(array = @ArraySchema(schema = @Schema(implementation = PartyCardResponse.class)))),
// @ApiResponse(responseCode = "401", description = "인증 실패")
// })
// @GetMapping("/parties/active")
// public ResponseEntity<List<PartyCardResponse>> getActiveParties(
// @AuthenticationPrincipal Long userId) {
// List<PartyCardResponse> response = userService.getActiveParties(userId);
// return ResponseEntity.ok(response);
// }

@Operation(summary = "닉네임 중복 확인", description = "닉네임 사용 가능 여부를 확인합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "사용 가능한 닉네임"),
Expand Down
48 changes: 36 additions & 12 deletions src/main/java/ita/tinybite/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ita.tinybite.domain.party.enums.ParticipantStatus;
import ita.tinybite.domain.party.enums.PartyStatus;
import ita.tinybite.domain.party.repository.PartyParticipantRepository;
import ita.tinybite.domain.party.repository.PartyRepository;
import ita.tinybite.domain.user.dto.req.UpdateUserReqDto;
import ita.tinybite.domain.user.dto.res.RejoinValidationResponse;
import ita.tinybite.domain.user.dto.res.UserResDto;
Expand All @@ -19,6 +20,7 @@
import ita.tinybite.global.exception.BusinessException;
import ita.tinybite.global.exception.errorcode.AuthErrorCode;
import ita.tinybite.global.location.LocationService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -29,6 +31,7 @@
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class UserService {

Expand All @@ -37,18 +40,7 @@ public class UserService {
private final LocationService locationService;
private final WithDrawUserRepository withDrawUserRepository;
private final PartyParticipantRepository participantRepository;

public UserService(SecurityProvider securityProvider,
UserRepository userRepository,
LocationService locationService,
PartyParticipantRepository participantRepository,
WithDrawUserRepository withDrawUserRepository) {
this.securityProvider = securityProvider;
this.userRepository = userRepository;
this.locationService = locationService;
this.participantRepository = participantRepository;
this.withDrawUserRepository = withDrawUserRepository;
}
private final PartyRepository partyRepository;

public UserResDto getUser() {
User user = securityProvider.getCurrentUser();
Expand Down Expand Up @@ -183,4 +175,36 @@ public RejoinValidationResponse validateRejoin(String email) {
.build();
}

public List<PartyCardResponse> getHostingParties(Long userId) {
List<Party> parties = partyRepository.findByHostUserIdAndStatus(
userId,
PartyStatus.RECRUITING
);

return parties.stream()
.map(party -> {
int currentParticipants = participantRepository
.countByPartyIdAndStatus(party.getId(), ParticipantStatus.APPROVED);
return PartyCardResponse.from(party, currentParticipants, true, ParticipantStatus.APPROVED);
})
.collect(Collectors.toList());
}

public List<PartyCardResponse> getParticipatingParties(Long userId) {
List<PartyParticipant> participants = participantRepository
.findActivePartiesByUserIdExcludingHost(
userId,
PartyStatus.RECRUITING,
ParticipantStatus.APPROVED
);

return participants.stream()
.map(pp -> {
Party party = pp.getParty();
int currentParticipants = participantRepository
.countByPartyIdAndStatus(party.getId(), ParticipantStatus.APPROVED);
return PartyCardResponse.from(party, currentParticipants, false, pp.getStatus());
})
.collect(Collectors.toList());
}
}