-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
�Feat: ContentCommandImplService 구현 (#24)
* Feat: ContentCommandImplService 구현 * Chore: Content 엔티티의 필드를 int에서 Long으로 변경
- Loading branch information
Showing
8 changed files
with
142 additions
and
49 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
29 changes: 0 additions & 29 deletions
29
src/main/java/beforespring/socialfeed/content/domain/ContentIdTuple.java
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
src/main/java/beforespring/socialfeed/content/domain/ContentRepository.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package beforespring.socialfeed.content.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ContentRepository extends JpaRepository<Content, Long> { | ||
|
||
} |
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
73 changes: 73 additions & 0 deletions
73
src/main/java/beforespring/socialfeed/content/service/ContentCommandImplServiceImpl.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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package beforespring.socialfeed.content.service; | ||
|
||
import beforespring.socialfeed.content.domain.Content; | ||
import beforespring.socialfeed.content.domain.ContentRepository; | ||
import beforespring.socialfeed.content.domain.ContentSourceType; | ||
import beforespring.socialfeed.content.service.dto.ContentSpecificData; | ||
import beforespring.socialfeed.content.service.exception.ContentNotFoundException; | ||
import beforespring.socialfeed.member.domain.Member; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.crossstore.ChangeSetPersister; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.transaction.Transactional; | ||
import java.util.Optional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class ContentCommandImplServiceImpl implements ContentCommandService { | ||
private final ContentRepository contentRepository; | ||
|
||
@Override | ||
public ContentSpecificData getContentSpecific(Long contentId) { | ||
Optional<Content> optionalContent = contentRepository.findById(contentId); | ||
|
||
if (optionalContent.isPresent()) { | ||
Content content = optionalContent.get(); | ||
|
||
content.incrementViewCount(); | ||
|
||
contentRepository.save(content); | ||
|
||
ContentSpecificData contentData = new ContentSpecificData( | ||
contentId, | ||
content.getContentSourceType(), | ||
content.getTitle(), | ||
content.getContent(), | ||
content.getViewCount(), | ||
content.getLikeCount(), | ||
content.getShareCount(), | ||
content.getUpdatedAt(), | ||
content.getCreatedAt() | ||
); | ||
|
||
return contentData; | ||
} else { | ||
throw new ContentNotFoundException(); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public void like(Long contentId, Member member) { | ||
Content content = contentRepository.findById(contentId) | ||
.orElseThrow(() -> new ContentNotFoundException()); | ||
|
||
content.incrementLikeCount(); | ||
|
||
contentRepository.save(content); | ||
} | ||
|
||
@Override | ||
public void share(Long contentId, Member member) { | ||
Content content = contentRepository.findById(contentId) | ||
.orElseThrow(() -> new ContentNotFoundException()); | ||
|
||
content.incrementShareCount(); | ||
|
||
contentRepository.save(content); | ||
} | ||
} | ||
|
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
13 changes: 13 additions & 0 deletions
13
src/main/java/beforespring/socialfeed/content/service/dto/ContentSpecificData.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
7 changes: 7 additions & 0 deletions
7
...main/java/beforespring/socialfeed/content/service/exception/ContentNotFoundException.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package beforespring.socialfeed.content.service.exception; | ||
|
||
public class ContentNotFoundException extends RuntimeException { | ||
public ContentNotFoundException() { | ||
super("Content Not Found"); | ||
} | ||
} |