Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release:v1.0.0-beta.14 #62

Merged
merged 1 commit into from
Jan 27, 2025
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 @@ -15,5 +15,6 @@ public class GetPostResponse {
private String unitName;
private String categoryName;
private Boolean userParticipatingIn;
private String userNickname;

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public class GetPostOutDto {
private String unitName;
private String categoryName;
private Boolean userParticipatingIn;
private String userNickname;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import foiegras.ygyg.post.application.dto.userpost.out.UserPostDataOutDto;
import foiegras.ygyg.post.infrastructure.entity.*;
import foiegras.ygyg.post.infrastructure.jpa.post.*;
import foiegras.ygyg.user.infrastructure.entity.UserEntity;
import foiegras.ygyg.user.infrastructure.jpa.UserJpaRepository;
import lombok.RequiredArgsConstructor;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;


@Service
Expand Down Expand Up @@ -103,37 +105,30 @@ public GetPostOutDto getPost(GetPostInDto inDto) {
// 연관 엔티티들 조회
UserPostEntity userPostEntity = userPostJpaRepository.findById(inDto.getUserPostId())
.orElseThrow(() -> new BaseException(BaseResponseStatus.NO_EXIST_USER_POST_ENTITY));

List<ParticipatingUsersEntity> participatingUsersEntity = participatingUsersJpaRepository.findByUserPostEntity(userPostEntity);
if (participatingUsersEntity.isEmpty()) throw new BaseException(BaseResponseStatus.NO_EXIST_PARTICIPATING_USERS);

PostEntity postEntity = userPostEntity.getPostEntity();

List<ItemImageUrlEntity> itemImageUrlEntity = itemImageUrlJpaRepository.findByPostEntity(postEntity);
if (itemImageUrlEntity.isEmpty()) throw new BaseException(BaseResponseStatus.NO_EXIST_ITEM_IMAGE_URL_ENTITY);

// outdto 필드들 구성
UserPostDataOutDto userPostDataOutDto = modelMapper.map(userPostEntity, UserPostDataOutDto.class);
if (userJpaRepository.findByUserUuid(userPostDataOutDto.getWriterUuid()).isEmpty()) {
// 소분글 작성자가 탈퇴유저라면 UUID를 null로 설정
// todo: post 도메인에서 user 도메인 의존하는 부분 리팩토링
userPostDataOutDto.toBuilder().writerUuid(null).build();
}
PostDataOutDto postDataOutDto = modelMapper.map(postEntity, PostDataOutDto.class);
String imageUrl = itemImageUrlEntity.get(0).getImageUrl(); // 아직은 이미지 한개만 첨부하므로
String unitName = postEntity.getItemPortioningUnitEntity().getUnit();
String categoryName = userPostEntity.getSeasoningCategoryEntity().getCategoryName();
Boolean userParticipatingIn = participatingUsersJpaRepository
.findByUserPostEntityAndParticipatingUserUUID(userPostEntity, inDto.getUserUuid()).isPresent();

// todo: post 도메인에서 user 도메인 의존하는 부분 리팩토링
// 소분글 작성자가 탈퇴유저라면 작성자 UUID null로 설정
Optional<UserEntity> postWriterEntity = userJpaRepository.findByUserUuid(userPostEntity.getWriterUuid());
if (postWriterEntity.isEmpty()) userPostDataOutDto = userPostDataOutDto.toBuilder().writerUuid(null).build();

// 리턴할 OutDto 매핑
return GetPostOutDto.builder()
.userPostDataOutDto(userPostDataOutDto)
.postDataOutDto(postDataOutDto)
.imageUrl(imageUrl)
.unitName(unitName)
.categoryName(categoryName)
.imageUrl(itemImageUrlEntity.get(0).getImageUrl())
.unitName(postEntity.getItemPortioningUnitEntity().getUnit())
.categoryName(userPostEntity.getSeasoningCategoryEntity().getCategoryName())
.userParticipatingIn(userParticipatingIn)
.userNickname(postWriterEntity.map(UserEntity::getUserNickname).orElse(null))
.build();

}
Expand Down