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 @@ -25,7 +25,7 @@ public ResponseEntity<Object> getAllContent(@RequestParam(value = "query", requi
@RequestParam(value = "size", required = false, defaultValue = "5") int size,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
try{
if(level == -1){
if(level == -1 && userId.isEmpty()){
return ResponseEntity.ok(contentService.getContentQuery(query, size, page));
} else if(userId.isEmpty()){
return ResponseEntity.ok(contentService.getContentQueryWithLevel(query, level, size, page));
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/example/prdoit/model/CommentTable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.prdoit.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.annotation.Nullable;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
Expand All @@ -8,6 +9,7 @@
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

@Entity
@Data
Expand All @@ -34,4 +36,8 @@ public class CommentTable {
@JoinColumn(name = "communityId", nullable = true)
private CommunityTable communityId;

@OneToMany(mappedBy = "commentId")
@JsonIgnore
private List<CommentCommentTable> commentCommentTable;

}
7 changes: 7 additions & 0 deletions src/main/java/com/example/prdoit/model/ContentTable.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.example.prdoit.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.*;

import java.util.List;

@Data
@Entity
@AllArgsConstructor
Expand All @@ -28,4 +31,8 @@ public class ContentTable {
@ManyToOne
@JoinColumn(name = "userId")
private IdTable userId;

@OneToMany(mappedBy = "contentId", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.EAGER)
@JsonIgnore
private List<CommentTable> commentTable;
}
3 changes: 3 additions & 0 deletions src/main/java/com/example/prdoit/model/IdTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ public class IdTable {
@JsonIgnore
private List<CommunityTable> communityTable;

@OneToMany(mappedBy = "userId", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.EAGER)
@JsonIgnore
private List<ContentTable> contentTable;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.prdoit.repository;

import com.example.prdoit.model.CommentCommentTable;
import com.example.prdoit.model.CommentTable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentCommentTableRepository extends JpaRepository<CommentCommentTable, Integer> {
List<CommentCommentTable> findAllByCommentId(CommentTable commentId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.prdoit.repository;

import com.example.prdoit.model.CommentTable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CommentTableRepository extends JpaRepository<CommentTable, Integer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,23 @@ public List<ContentResponseDto> getContentQueryWithLevel(String query, int level

@Override
public List<ContentResponseDto> getContentWithUserId(String userId){
log.info("[getContentWithUserId] 사용자별 컨텐츠 조회 로직 시작");
try {
List<ContentResponseDto> contentResponseDtoList = contentRepository.findAllByUserId(userId);
if(contentResponseDtoList.isEmpty()){
throw new RuntimeException("등록된 컨텐츠가 없습니다.");
} else {
return contentResponseDtoList;
}
IdTable idTable = IdTableRepository.findById(userId).orElseThrow
(() -> new RuntimeException("존재하지 않는 사용자입니다."));
if(idTable.getContentTable().isEmpty()) {
throw new RuntimeException("등록된 컨텐츠가 없습니다.");
}
try{
return idTable.getContentTable().stream().map(contentTable -> ContentResponseDto.builder()
.contentId(contentTable.getContentId())
.contentTitle(contentTable.getContentTitle())
.contentView(contentTable.getContentView())
.contentLike(contentTable.getContentLike())
.contentLevel(contentTable.getContentLevel())
.writer(contentTable.getUserId().getNickname())
.build()).toList();
} catch (Exception e) {
log.error("[getContentWithUserId] 사용자별 컨텐츠 조회 실패");
throw new RuntimeException("사용자별 컨텐츠 조회에 실패했습니다.");
log.error(e.getMessage());
throw new RuntimeException("쿼리 조회에 실패했습니다.");
}
}

Expand Down