-
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 #38 from goalSetter09/10th-Kampus-BE-33
[FEATURE] 게시글 조회 기능 구현
- Loading branch information
Showing
20 changed files
with
409 additions
and
62 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
25 changes: 0 additions & 25 deletions
25
src/main/java/com/cotato/kampus/domain/model/domain/BaseTimeEntity.java
This file was deleted.
Oops, something went wrong.
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/cotato/kampus/domain/post/application/PostAuthorResolver.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,44 @@ | ||
package com.cotato.kampus.domain.post.application; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.cotato.kampus.domain.common.application.ApiUserResolver; | ||
import com.cotato.kampus.domain.common.enums.Anonymity; | ||
import com.cotato.kampus.domain.post.dto.AnonymousOrPostAuthor; | ||
import com.cotato.kampus.domain.post.dto.PostDto; | ||
import com.cotato.kampus.domain.user.dao.UserRepository; | ||
import com.cotato.kampus.domain.user.domain.User; | ||
import com.cotato.kampus.global.error.ErrorCode; | ||
import com.cotato.kampus.global.error.exception.AppException; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PostAuthorResolver { | ||
|
||
private final UserRepository userRepository; | ||
private final ApiUserResolver apiUserResolver; | ||
|
||
public AnonymousOrPostAuthor getAuthor(PostDto postDto) { | ||
AnonymousOrPostAuthor anonymousOrPostAuthor; | ||
|
||
User author = userRepository.findById(postDto.userId()) | ||
.orElseThrow(() -> new AppException(ErrorCode.USER_NOT_FOUND)); | ||
|
||
// 현재 사용자가 게시글 작성자인지 확인 | ||
Boolean isAuthor = apiUserResolver.getUserId().equals(author.getId()); | ||
|
||
if (postDto.anonymity().equals(Anonymity.ANONYMOUS)) { | ||
// 익명 사용자 정보 반환 | ||
return AnonymousOrPostAuthor.of(true, isAuthor, -1L, "Anonymous", "Default profile image"); | ||
} else { | ||
// 작성자 정보 반환 | ||
return AnonymousOrPostAuthor.of(false, isAuthor, author.getId(), author.getUsername(), | ||
author.getProfileImage()); | ||
} | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/cotato/kampus/domain/post/application/PostImageFinder.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,26 @@ | ||
package com.cotato.kampus.domain.post.application; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.cotato.kampus.domain.post.dao.PostPhotoRepository; | ||
import com.cotato.kampus.domain.post.domain.PostPhoto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Transactional(readOnly = true) | ||
public class PostImageFinder { | ||
|
||
private final PostPhotoRepository postPhotoRepository; | ||
|
||
public List<String> findPostPhotos(Long postId) { | ||
return postPhotoRepository.findALlByPostId(postId).stream() | ||
.map(PostPhoto::getPhotoUrl) | ||
.toList(); | ||
} | ||
} |
Oops, something went wrong.