Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ public ResponseEntity<ApiResponse<Map<Long, String>>> getSeries() {
return ResponseEntity.ok(ApiResponse.onSuccess(seriesMap));
}

@GetMapping("/series/{user_id}")
@Operation(summary = "다른 사람 Series 조회 API", description = "다른 사람의 Series List를 조회합니다.")
@ApiErrorCodeExamples({
ErrorStatus.USER_NOT_FOUND
})
public ResponseEntity<ApiResponse<Map<Long, String>>> getSeries(@PathVariable("user_id") Long userId) {
Map<Long, String> seriesMap = feedQueryService.getOtherSeries(userId);
return ResponseEntity.ok(ApiResponse.onSuccess(seriesMap));
}

@GetMapping("/likes")
@Operation(summary = "좋아요(공감)한 피드 조회", description = "현재 사용자가 공감한 Feed 리스트를 페이징으로 조회합니다.")
public ResponseEntity<ApiResponse<Map<String, Object>>> getSavedFeeds(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface FeedQueryService {
// FeedResponseDto.FeedPreviewList searchByUserIdByKeyword(Long userId, Long nextCursor, int pageSize);
UserMyPageResponseDto getFeeds(Long nextCursor, int pageSize, Long seriesId);
Map<Long, String> getMySeries();
Map<Long, String> getOtherSeries(Long userId);
Long getLikeCount(Long feedId);
Feed getFeedByFeedId(Long feedId);
Map<String, Object> getLikedFeedsWithPaging(int page, int size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,21 @@ public Map<Long, String> getMySeries() {
));
}

@Override
public Map<Long, String> getOtherSeries(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new UserHandler(ErrorStatus.USER_NOT_FOUND));

List<Series> userSeriesList = seriesRepository.findAllByUser(user);

return userSeriesList.stream()
.collect(Collectors.toMap(
Series::getSeriesId,
Series::getComment
));
}


@Override
public Map<String, Object> getLikedFeedsWithPaging(int page, int size) {
User user = authService.getCurrentUser(); // 인증 필요
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ResponseEntity<ApiResponse<List<PotMemberAppealResponseDto>>> addPotMembe
return ResponseEntity.ok(ApiResponse.onSuccess(response));
}

@Operation(summary = "팟 어필 API")
@Operation(summary = "여기서 저는요 작성 및 수정 API")
@PatchMapping("/appeal")
public ResponseEntity<ApiResponse<String>> updateAppealContent(
@PathVariable("pot_id") Long potId,
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/stackpot/stackpot/pot/repository/PotRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import stackpot.stackpot.pot.entity.Pot;
import stackpot.stackpot.user.entity.enums.Role;

Expand Down Expand Up @@ -56,9 +57,9 @@ public interface PotRepository extends JpaRepository<Pot, Long> {
@Modifying
@Query("DELETE FROM Pot f WHERE f.user.id = :userId")
void deleteByUserId(@Param("userId") Long userId);
@Modifying
@Query("DELETE FROM Pot p WHERE p.user.id = :userId AND p.potId IN :potIds AND p.potStatus = 'RECRUITING'")
void deleteByUserIdAndPotIds(@Param("userId") Long userId, @Param("potIds") List<Long> potIds);
// @Modifying
// @Query("DELETE FROM Pot p WHERE p.user.id = :userId AND p.potId IN :potIds AND p.potStatus = 'RECRUITING'")
// void deleteByUserIdAndPotIds(@Param("userId") Long userId, @Param("potIds") List<Long> potIds);
boolean existsByUserId(Long userId);

// 지원자 수 기준으로 모든 Pot 정렬
Expand All @@ -85,4 +86,13 @@ List<Long> findIdsByUserIdAndStatus(@Param("userId") Long userId,
@Query("select p.potId from Pot p where p.user.id = :userId and p.potStatus not in :statuses")
List<Long> findIdsByUserIdAndStatusNotIn(@Param("userId") Long userId,
@Param("statuses") List<String> statuses);

@Modifying @Transactional
@Query("""
delete from Pot p
where p.user.id = :userId
and p.potId in :potIds
and p.potStatus = 'RECRUITING'
""")
void deleteByUserIdAndPotIds(@Param("userId") Long userId, @Param("potIds") List<Long> potIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,12 @@ default Map<Long, Integer> countSavesByPotIds(List<Long> potIds) {
void deleteAllByUserAndPots(@Param("user") User user, @Param("pots") List<Pot> pots);

List<PotSave> findByUser(User user);

@Modifying
@Transactional
void deleteByUser(User user);

@Modifying @Transactional
@Query("delete from PotSave ps where ps.pot.potId in :potIds")
int deleteByPotIds(@Param("potIds") List<Long> potIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import stackpot.stackpot.pot.repository.PotApplicationRepository;
import stackpot.stackpot.pot.repository.PotCommentRepository;
import stackpot.stackpot.pot.repository.PotRepository;
import stackpot.stackpot.pot.repository.PotSaveRepository;
import stackpot.stackpot.user.entity.User;
import stackpot.stackpot.user.repository.UserRepository;

Expand All @@ -35,6 +36,7 @@ public class PotApplicationQueryServiceImpl implements PotApplicationQueryServic
private final PotApplicationConverter potApplicationConverter;
private final PotDetailConverter potDetailConverter;
private final AuthService authService;
private final PotSaveRepository potSaveRepository;

@Override
@Transactional(readOnly = true)
Expand Down Expand Up @@ -63,13 +65,15 @@ public PotDetailWithApplicantsResponseDto getPotDetailsAndApplicants(Long potId)
boolean isApplied = pot.getPotApplication().stream()
.anyMatch(application -> application.getUser().getId().equals(user.getId()));

boolean isSaved = potSaveRepository.existsByUserAndPot_PotId(user, potId);

String recruitmentDetails = pot.getRecruitmentDetails().stream()
.map(rd -> RoleNameMapper.mapRoleName(rd.getRecruitmentRole().name()) + "(" + rd.getRecruitmentCount() + ")")
.collect(Collectors.joining(", "));

Long commentCount = potCommentRepository.countByPotId(potId);

PotDetailResponseDto potDetailDto = potDetailConverter.toPotDetailResponseDto(pot.getUser(), pot, recruitmentDetails, isOwner, isApplied, null, commentCount);
PotDetailResponseDto potDetailDto = potDetailConverter.toPotDetailResponseDto(pot.getUser(), pot, recruitmentDetails, isOwner, isApplied, isSaved, commentCount);

List<PotApplicationResponseDto> applicants = Collections.emptyList();
if (isOwner && "RECRUITING".equals(pot.getPotStatus())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ public List<PotMemberAppealResponseDto> addMembersToPot(Long potId, PotMemberReq
@Transactional
@Override
public void updateAppealContent(Long potId, String appealContent) {
String email = authService.getCurrentUserEmail();
User user = authService.getCurrentUser();

PotMember potMember = potMemberRepository.findByPot_PotIdAndUser_Email(potId, email)
PotMember potMember = potMemberRepository.findByPotPotIdAndUser(potId, user)
.orElseThrow(() -> new PotHandler(ErrorStatus.POT_MEMBER_NOT_FOUND));

potMember.setAppealContent(appealContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import stackpot.stackpot.user.repository.TempUserRepository;

import java.time.LocalDateTime;
Expand All @@ -15,7 +16,8 @@ public class TempUserCleanupScheduler {

private final TempUserRepository tempUserRepository;

@Scheduled(cron = "0 0 * * * *") // 매 정시
@Scheduled(cron = "0 0 * * * *")
@Transactional// 매 정시
public void deleteOldTempUsers() {
LocalDateTime oneHourAgo = LocalDateTime.now().minusHours(1);
int deletedCount = tempUserRepository.deleteByCreatedAtBefore(oneHourAgo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ public void handleCreatorPotDeletion(User user) {
// PotApplication 삭제
potApplicationRepository.deleteByPotIds(recruitingPotIds);
potRepository.deleteByUserIdAndPotIds(userId, recruitingPotIds);
potSaveRepository.deleteByPotIds(recruitingPotIds);

potRepository.deleteByUserIdAndPotIds(userId, recruitingPotIds);
}


Expand Down Expand Up @@ -470,7 +473,7 @@ public void deletePotAndRelatedData(Pot pot) {
potApplicationRepository.deleteByPotId(pot.getPotId());

potRecruitmentDetailsRepository.deleteByPot_PotId(pot.getPotId());

potSaveRepository.deleteByPotIds(List.of(pot.getPotId()));
// Pot 삭제
potRepository.delete(pot);

Expand Down