Skip to content
Merged
3 changes: 3 additions & 0 deletions src/main/java/stackpot/mongo/ChatRepository.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stackpot.mongo;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -27,4 +28,6 @@ public interface ChatRepository extends MongoRepository<Chat, String> {
int countByChatRoomIdAndIdGreaterThan(Long chatRoomId, Long lastReadChatId);

void deleteByUserIdAndChatRoomId(Long userId, Long chatRoomId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public enum ErrorStatus implements BaseErrorCode {
// Pot 관련 에러
POT_NOT_FOUND(HttpStatus.NOT_FOUND, "POT4004", "팟이 존재하지 않습니다."),
POT_FORBIDDEN(HttpStatus.FORBIDDEN, "POT4003", "팟 생성자가 아닙니다."),
POT_OWNERSHIP_TRANSFER_REQUIRED(HttpStatus.CONFLICT, "POT4005", "권한을 위임해 주세요."),

// Pot Comment 관련 에러
POT_COMMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "POTCOMMENT4001", "Pot Comment를 찾을 수 없습니다"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package stackpot.stackpot.chat.repository;

import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.repository.query.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import stackpot.stackpot.chat.entity.ChatRoomInfo;

import java.util.List;
Expand All @@ -27,4 +28,10 @@ public interface ChatRoomInfoRepository extends JpaRepository<ChatRoomInfo, Long
@Modifying
@Query("delete from ChatRoomInfo cri where cri.potMember.potMemberId in :potMemberIds")
void deleteByPotMemberIdIn(@Param("potMemberIds") List<Long> potMemberIds);

@Modifying
@Transactional
@Query("DELETE FROM ChatRoomInfo cri WHERE cri.potMember.potMemberId = :potMemberId AND cri.chatRoom.id IN :chatRoomIds")
void deleteByPotMemberIdAndChatRoomIds(@Param("potMemberId") Long potMemberId, @Param("chatRoomIds") List<Long> chatRoomIds);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import org.springframework.data.jpa.repository.Query;
import stackpot.stackpot.chat.dto.ChatRoomDto;
import stackpot.stackpot.chat.entity.ChatRoom;
import stackpot.stackpot.user.entity.User;

import java.util.List;
import java.util.Optional;

public interface ChatRoomRepository extends JpaRepository<ChatRoom, Long> {
Expand All @@ -26,4 +28,11 @@ public interface ChatRoomRepository extends JpaRepository<ChatRoom, Long> {
@Modifying
@Query("delete from ChatRoom c where c.pot.potId = :potId")
void deleteByPotId(@Param("potId") Long potId);



@Query("select cr.id from ChatRoom cr where cr.pot.potId in :potIds")
List<Long> findIdsByPotIdIn(@Param("potIds") List<Long> potIds);


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public class ChatSendService {
public void sendMessage(Chat chat, Long chatRoomId) {
messagingTemplate.convertAndSend(CHAT_SUB_URL + chatRoomId, chatConverter.toChatDto(chat));
}
public void deleteMessage(Long chatRoomId, Long chatId) {
messagingTemplate.convertAndSend(CHAT_SUB_URL + chatRoomId, "DELETE_" + chatId); // DELETE_<chatId> 형식으로 클라이언트에게 삭제 알림
}
}
22 changes: 19 additions & 3 deletions src/main/java/stackpot/stackpot/feed/converter/FeedConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public class FeedConverter{
public FeedResponseDto.FeedDto feedDto(Feed feed, Boolean isOwner, Boolean isLiked, Boolean isSaved, long saveCount) {

Long commentCount = feedCommentRepository.countByFeedId(feed.getFeedId());
String writerNickname = getWriterNickname(feed.getUser());

return FeedResponseDto.FeedDto.builder()
.feedId(feed.getFeedId())
.writerId(feed.getUser().getId())
.writer(feed.getUser().getNickname() + " 새싹")
.writer(writerNickname)
.writerRole(feed.getUser().getRole())
.title(feed.getTitle())
.content(feed.getContent())
Expand All @@ -55,6 +57,8 @@ public FeedResponseDto.CreatedFeedDto createFeedDto(Feed feed) {
"comment", feed.getSeries().getComment()
);
}
Long commentCount = feedCommentRepository.countByFeedId(feed.getFeedId());


return FeedResponseDto.CreatedFeedDto.builder()
.feedId(feed.getFeedId())
Expand Down Expand Up @@ -106,11 +110,11 @@ public FeedResponseDto.AuthorizedFeedDto toAuthorizedFeedDto(Feed feed, boolean
"comment", feed.getSeries().getComment()
);
}

String writerNickname = getWriterNickname(feed.getUser());
FeedResponseDto.CreatedFeedDto createdDto = FeedResponseDto.CreatedFeedDto.builder()
.feedId(feed.getFeedId())
.writerId(feed.getUser().getId())
.writer(feed.getUser().getNickname()+" 새싹")
.writer(writerNickname)
.writerRole(feed.getUser().getRole())
.title(feed.getTitle())
.content(feed.getContent())
Expand Down Expand Up @@ -163,6 +167,18 @@ public FeedCacheDto toFeedCacheDto(Feed feed) {
.createdAt(feed.getCreatedAt().toString())
.build();
}
public String getWriterNickname(User user) {
String writerNickname = user.getNickname();

// 사용자가 탈퇴한 경우 "새싹"을 제거
if (user.isDeleted()) {
writerNickname = writerNickname; // 탈퇴한 경우 "새싹" 제거
} else {
writerNickname += " 새싹"; // 탈퇴하지 않은 경우 "새싹" 추가
}

return writerNickname;
}


}
2 changes: 1 addition & 1 deletion src/main/java/stackpot/stackpot/pot/entity/Pot.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Pot extends BaseEntity {
@JoinColumn(name = "user_id", nullable = false)
private User user;

@OneToMany(mappedBy = "pot")
@OneToMany(mappedBy = "pot",cascade = CascadeType.ALL, orphanRemoval = true)
private List<PotRecruitmentDetails> recruitmentDetails;

@OneToMany(mappedBy = "pot", cascade = CascadeType.REMOVE, orphanRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package stackpot.stackpot.pot.repository;

import jakarta.persistence.QueryHint;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;
import org.springframework.data.repository.query.Param;
import stackpot.stackpot.pot.entity.mapping.PotApplication;

Expand All @@ -22,4 +24,10 @@ public interface PotApplicationRepository extends JpaRepository<PotApplication,
@Query("DELETE FROM PotApplication f WHERE f.pot.potId = :potId")
void deleteByPotId(@Param("potId") Long potId);

@Modifying
@Query("DELETE FROM PotApplication pa WHERE pa.pot.potId IN :potIds")
@QueryHints({ @QueryHint(name = "javax.persistence.query.timeout", value = "5000") })
void deleteByPotIds(@Param("potIds") List<Long> potIds);


}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface PotMemberRepository extends JpaRepository<PotMember, Long> {

boolean existsByPotAndUser(Pot pot, User user);

// 특정 Pot에 속한 사용자(userId)의 역할(Role) 찾기
// 특정 Pot에 속한 사용자(userId)의 역할(Role) 찾기
@Query("SELECT pm.roleName FROM PotMember pm WHERE pm.pot.potId = :potId AND pm.user.id = :userId")
Optional<Role> findRoleByUserId(@Param("potId") Long potId, @Param("userId") Long userId);

Expand Down Expand Up @@ -89,4 +89,9 @@ public interface PotMemberRepository extends JpaRepository<PotMember, Long> {

@Query("SELECT pm.pot.potId FROM PotMember pm WHERE pm.user.id = :userId AND pm.pot.potId IN :potIds")
Set<Long> findPotIdsByUserIdAndPotIds(@Param("userId") Long userId, @Param("potIds") List<Long> potIds);


@Modifying
@Query("DELETE FROM PotMember pm WHERE pm.pot.potId IN :potIds AND pm.user.id = :userId")
void deleteByUserIdAndPotIdIn(@Param("userId") Long userId, @Param("potIds") List<Long> potIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
import org.springframework.data.repository.query.Param;
import stackpot.stackpot.pot.entity.PotRecruitmentDetails;

import java.util.List;

public interface PotRecruitmentDetailsRepository extends JpaRepository<PotRecruitmentDetails, Long> {
@Modifying
@Transactional
@Query("DELETE FROM PotRecruitmentDetails r WHERE r.pot.potId = :potId")
void deleteByPot_PotId(@Param("potId") Long potId);


@Modifying
@Transactional
@Query("DELETE FROM PotRecruitmentDetails prd WHERE prd.pot.potId IN :potIds")
void deleteByPotIds(@Param("potIds") List<Long> potIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,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);
boolean existsByUserId(Long userId);

// 지원자 수 기준으로 모든 Pot 정렬
Expand All @@ -76,5 +78,11 @@ public interface PotRepository extends JpaRepository<Pot, Long> {

List<Pot> findByPotMembers_UserIdOrderByCreatedAtDesc(Long userId);

@Query("select p.potId from Pot p where p.user.id = :userId and p.potStatus = :status")
List<Long> findIdsByUserIdAndStatus(@Param("userId") Long userId,
@Param("status") String status);

@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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import stackpot.stackpot.pot.entity.Pot;
import stackpot.stackpot.pot.entity.PotRecruitmentDetails;
import stackpot.stackpot.pot.entity.mapping.PotSave;
import stackpot.stackpot.user.entity.User;

Expand Down Expand Up @@ -47,4 +46,12 @@ default Map<Long, Integer> countSavesByPotIds(List<Long> potIds) {

@Query("SELECT ps.pot FROM PotSave ps WHERE ps.user.id = :userId")
Page<Pot> findSavedPotsByUserId(@Param("userId") Long userId, Pageable pageable);

@Modifying
@Transactional
@Query("DELETE FROM PotSave ps WHERE ps.user = :user AND ps.pot IN :pots")
void deleteAllByUserAndPots(@Param("user") User user, @Param("pots") List<Pot> pots);

List<PotSave> findByUser(User user);
void deleteByUser(User user);
}
3 changes: 3 additions & 0 deletions src/main/java/stackpot/stackpot/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public void deleteUser() {
}
this.interests = new ArrayList<>(); // 새로운 관심사 목록 생성
this.interests.add("UNKNOWN"); // "UNKNOWN"을 관심사 목록에 추가
if (this.seriesList != null) {
this.seriesList.clear(); // 연관된 시리즈 비우기
}

this.userTemperature = null;
this.email = null;
Expand Down
Loading