This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from FinFellows/develop
allowedHeaders 주석처리(test)
- Loading branch information
Showing
9 changed files
with
262 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
200 changes: 100 additions & 100 deletions
200
src/main/java/com/finfellows/domain/educontent/application/EduContentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,100 @@ | ||
package com.finfellows.domain.educontent.application; | ||
|
||
import com.finfellows.domain.bookmark.domain.repository.EduContentBookmarkRepository; | ||
import com.finfellows.domain.educontent.domain.EduContent; | ||
import com.finfellows.domain.educontent.domain.repository.EduContentRepository; | ||
import com.finfellows.domain.educontent.dto.request.EduContentRequest; | ||
import com.finfellows.domain.educontent.dto.response.EduContentResponse; | ||
import com.finfellows.domain.post.domain.Post; | ||
import com.finfellows.domain.post.domain.repository.PostRepository; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class EduContentService { | ||
private final EduContentRepository eduContentRepository; | ||
private final PostRepository postRepository; | ||
private final EduContentBookmarkRepository eduContentBookmarkRepository; | ||
|
||
@Transactional | ||
public EduContent createEduContent(EduContentRequest request) { | ||
Post post = new Post(); | ||
postRepository.save(post); | ||
|
||
// 빌더 패턴을 사용하여 EduContent 생성하면서 Post 엔터티를 설정 | ||
EduContent eduContent = EduContent.builder() | ||
.title(request.getTitle()) | ||
.content(request.getContent()) | ||
.post(post) // Post 엔터티를 설정 | ||
.build(); | ||
|
||
// EduContent 저장 | ||
EduContent savedContent = eduContentRepository.save(eduContent); | ||
return savedContent; | ||
} | ||
|
||
public Page<EduContentResponse> getAllEduContents(Long userId, Pageable pageable) { | ||
Page<EduContent> eduContentPage = eduContentRepository.findAll(pageable); | ||
|
||
List<EduContentResponse> eduContentResponses = eduContentPage.getContent().stream() | ||
.map(eduContent -> EduContentResponse.builder() | ||
.id(eduContent.getId()) | ||
.title(eduContent.getTitle()) | ||
.content(eduContent.getContent()) | ||
.bookmarked(checkBookmarked(userId, eduContent.getId())) | ||
.build()) | ||
.collect(Collectors.toList()); | ||
|
||
return new PageImpl<>(eduContentResponses, pageable, eduContentPage.getTotalElements()); | ||
} | ||
|
||
public EduContentResponse getEduContent(Long id) { | ||
EduContent eduContent = eduContentRepository.findById(id) | ||
.orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id)); | ||
|
||
return EduContentResponse.builder() | ||
.id(eduContent.getId()) | ||
.title(eduContent.getTitle()) | ||
.content(eduContent.getContent()) | ||
.build(); | ||
} | ||
|
||
@Transactional | ||
public void deleteEduContent(Long id) { | ||
EduContent eduContent = eduContentRepository.findById(id) | ||
.orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id)); | ||
|
||
eduContentRepository.delete(eduContent); | ||
} | ||
|
||
@Transactional | ||
public EduContentResponse updateEduContent(Long id, EduContentRequest request) { | ||
EduContent eduContent = eduContentRepository.findById(id) | ||
.orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id)); | ||
|
||
eduContent.updateContent(request.getTitle(), request.getContent()); | ||
|
||
EduContent updatedContent = eduContentRepository.save(eduContent); | ||
|
||
return EduContentResponse.builder() | ||
.id(updatedContent.getId()) | ||
.title(updatedContent.getTitle()) | ||
.content(updatedContent.getContent()) | ||
.build(); | ||
} | ||
|
||
|
||
private boolean checkBookmarked(Long userId, Long eduContentId) { | ||
return eduContentBookmarkRepository.existsByUser_IdAndEduContent_Id(userId, eduContentId); | ||
} | ||
} | ||
package com.finfellows.domain.educontent.application; | ||
|
||
import com.finfellows.domain.bookmark.domain.repository.EduContentBookmarkRepository; | ||
import com.finfellows.domain.educontent.domain.EduContent; | ||
import com.finfellows.domain.educontent.domain.repository.EduContentRepository; | ||
import com.finfellows.domain.educontent.dto.request.EduContentRequest; | ||
import com.finfellows.domain.educontent.dto.response.EduContentResponse; | ||
import com.finfellows.domain.post.domain.Post; | ||
import com.finfellows.domain.post.domain.repository.PostRepository; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class EduContentService { | ||
private final EduContentRepository eduContentRepository; | ||
private final PostRepository postRepository; | ||
private final EduContentBookmarkRepository eduContentBookmarkRepository; | ||
|
||
@Transactional | ||
public EduContent createEduContent(EduContentRequest request) { | ||
Post post = new Post(); | ||
postRepository.save(post); | ||
|
||
// 빌더 패턴을 사용하여 EduContent 생성하면서 Post 엔터티를 설정 | ||
EduContent eduContent = EduContent.builder() | ||
.title(request.getTitle()) | ||
.content(request.getContent()) | ||
.post(post) // Post 엔터티를 설정 | ||
.build(); | ||
|
||
// EduContent 저장 | ||
EduContent savedContent = eduContentRepository.save(eduContent); | ||
return savedContent; | ||
} | ||
|
||
public Page<EduContentResponse> getAllEduContents(Long userId, Pageable pageable) { | ||
Page<EduContent> eduContentPage = eduContentRepository.findAll(pageable); | ||
|
||
List<EduContentResponse> eduContentResponses = eduContentPage.getContent().stream() | ||
.map(eduContent -> EduContentResponse.builder() | ||
.id(eduContent.getId()) | ||
.title(eduContent.getTitle()) | ||
.content(eduContent.getContent()) | ||
.bookmarked(checkBookmarked(userId, eduContent.getId())) | ||
.build()) | ||
.collect(Collectors.toList()); | ||
|
||
return new PageImpl<>(eduContentResponses, pageable, eduContentPage.getTotalElements()); | ||
} | ||
|
||
public EduContentResponse getEduContent(Long id) { | ||
EduContent eduContent = eduContentRepository.findById(id) | ||
.orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id)); | ||
|
||
return EduContentResponse.builder() | ||
.id(eduContent.getId()) | ||
.title(eduContent.getTitle()) | ||
.content(eduContent.getContent()) | ||
.build(); | ||
} | ||
|
||
@Transactional | ||
public void deleteEduContent(Long id) { | ||
EduContent eduContent = eduContentRepository.findById(id) | ||
.orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id)); | ||
|
||
eduContentRepository.delete(eduContent); | ||
} | ||
|
||
@Transactional | ||
public EduContentResponse updateEduContent(Long id, EduContentRequest request) { | ||
EduContent eduContent = eduContentRepository.findById(id) | ||
.orElseThrow(() -> new EntityNotFoundException("EduContent not found with id: " + id)); | ||
|
||
eduContent.updateContent(request.getTitle(), request.getContent()); | ||
|
||
EduContent updatedContent = eduContentRepository.save(eduContent); | ||
|
||
return EduContentResponse.builder() | ||
.id(updatedContent.getId()) | ||
.title(updatedContent.getTitle()) | ||
.content(updatedContent.getContent()) | ||
.build(); | ||
} | ||
|
||
|
||
private boolean checkBookmarked(Long userId, Long eduContentId) { | ||
return eduContentBookmarkRepository.existsByUser_IdAndEduContent_Id(userId, eduContentId); | ||
} | ||
} |
Oops, something went wrong.