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
2 changes: 1 addition & 1 deletion src/main/java/com/example/prdoit/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.nio.file.Watchable;

@Configuration
public class WebConfig implements WebMvcConfigurer {
public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ public class ContentController {
@GetMapping()
public ResponseEntity<Object> getAllContent(@RequestParam(value = "query", required = false, defaultValue = "all") String query,
@RequestParam(value = "level", required = false, defaultValue = "-1") int level,
@RequestParam(value = "userId", required = false, defaultValue = "") String userId,
@RequestParam(value = "size", required = false, defaultValue = "5") int size,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
try{
if(level == -1){
return ResponseEntity.ok(contentService.getContentQuery(query, size, page));
} else {
} else if(userId.isEmpty()){
return ResponseEntity.ok(contentService.getContentQueryWithLevel(query, level, size, page));
} else {
return ResponseEntity.ok(contentService.getContentWithUserId(userId));
}
} catch (CustomException e) {
log.error("[getAllContent] 컨텐츠 조회 실패", e);
Expand Down Expand Up @@ -78,4 +81,5 @@ public ResponseEntity<Object> getContentDetail(@PathVariable String contentId) {
return ResponseEntity.internalServerError().body("컨텐츠 상세 조회에 실패했습니다.");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.example.prdoit.dto.project.burndown.BurndownListDto;
import com.example.prdoit.model.BacklogTable;
import com.example.prdoit.model.ProjectLevelContentTable;
import com.example.prdoit.model.ProjectTable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ public interface ContentTableRepository extends JpaRepository<ContentTable, Stri
"ORDER BY (c.contentView * 0.33) + (c.contentLike * 0.33) + (COUNT(cc.commentId) * 0.33) DESC " +
"LIMIT :size OFFSET :offset")
List<ContentResponseDto> findAllByContentLevel(@Param("level") int level, @Param("size") int size, @Param("offset") int offset);

@Query("SELECT new com.example.prdoit.dto.content.ContentResponseDto" +
"(c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel, c.userId.nickname) " +
"FROM ContentTable c WHERE c.userId.id = :userId")
List<ContentResponseDto> findAllByUserId(@Param("userId") String userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface ContentService {

List<ContentResponseDto> getContentQueryWithLevel(String query, int level, int size, int page);

List<ContentResponseDto> getContentWithUserId(String userId);

void updateContent(ContentUpdateDto contentUpdateDto);

void postContent(ContentRequestDto contentRequestDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,25 @@ public List<ContentResponseDto> getContentQueryWithLevel(String query, int level
}

@Override
public void postContent(ContentRequestDto contentRequestDto){
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;
}
} catch (Exception e) {
log.error("[getContentWithUserId] 사용자별 컨텐츠 조회 실패");
throw new RuntimeException("사용자별 컨텐츠 조회에 실패했습니다.");
}
}

IdTable idTable = IdTableRepository.findById(contentRequestDto.getUserId()).orElseThrow(() -> new RuntimeException("존재하지 않는 사용자입니다."));
@Override
public void postContent(ContentRequestDto contentRequestDto){
IdTable idTable = IdTableRepository.findById(contentRequestDto.getUserId()).orElseThrow
(() -> new RuntimeException("존재하지 않는 사용자입니다."));
log.info("[postContent] 컨텐츠 등록 로직 시작");
try {
ContentTable contentTable = ContentTable.builder()
Expand All @@ -107,7 +123,8 @@ public void postContent(ContentRequestDto contentRequestDto){
public void updateContent(ContentUpdateDto contentUpdateDto){
log.info("[updateContent] 컨텐츠 수정 로직 시작");
try {
ContentTable contentTable = contentRepository.findById(contentUpdateDto.getContentId()).orElseThrow(() -> new RuntimeException("존재하지 않는 컨텐츠입니다."));
ContentTable contentTable = contentRepository.findById(contentUpdateDto.getContentId()).orElseThrow
(() -> new RuntimeException("존재하지 않는 컨텐츠입니다."));
contentTable.setContentTitle(contentUpdateDto.getContentTitle());
contentTable.setContentContent(contentUpdateDto.getContentContent());
contentTable.setContentLevel(contentUpdateDto.getContentLevel());
Expand All @@ -123,7 +140,8 @@ public void updateContent(ContentUpdateDto contentUpdateDto){
public ContentDetailDto getContentDetail(String contentId){
log.info("[getContentDetail] 컨텐츠 상세 조회 로직 시작");
try {
ContentTable contentTable = contentRepository.findById(contentId).orElseThrow(() -> new RuntimeException("존재하지 않는 컨텐츠입니다."));
ContentTable contentTable = contentRepository.findById(contentId).orElseThrow
(() -> new RuntimeException("존재하지 않는 컨텐츠입니다."));
contentTable.setContentView(contentTable.getContentView() + 1);
contentRepository.save(contentTable);
return ContentDetailDto.builder()
Expand All @@ -141,4 +159,5 @@ public ContentDetailDto getContentDetail(String contentId){
throw new RuntimeException(e.getMessage());
}
}

}