Skip to content

Commit

Permalink
Merge pull request #41 from SOPT-all/feat/37
Browse files Browse the repository at this point in the history
[FEAT] 게시물 조회 로직 수정- isSpoon추가,response에서 카테고리 관련 부분 수정
  • Loading branch information
dltnals317 authored Jan 19, 2025
2 parents 4e00efc + 6870f3f commit 33a0607
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class PostController {
private final PostService postService;
private final AwsFileService awsFileService;

@GetMapping("/{postId}")
public ResponseEntity<ResponseDTO<PostResponseDTO>> getPost(@PathVariable Long postId) {
PostResponseDTO postResponse = postService.getPostById(postId);
@GetMapping("/{userId}/{postId}")
public ResponseEntity<ResponseDTO<PostResponseDTO>> getPost(@PathVariable Long postId, @PathVariable Long userId) {
PostResponseDTO postResponse = postService.getPostById(postId, userId);
return ResponseEntity.status(HttpStatus.OK).body(ResponseDTO.success(postResponse));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public record PostResponseDTO(Long postId, Long userId, String userName, String
List<String> menuList,
String description,
String place_name, String place_address, Double latitude,
Double longitude, Long zzinCount
Double longitude, Long zzinCount, Boolean is_scoop, String IconUrlColor,
String BackgroundColor
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.Optional;

public interface ZzimPostRepository extends JpaRepository<ZzimPostEntity, Long> {

Long countByPost(PostEntity postEntity);
Optional<List<ZzimPostEntity>> findByUser_UserId(Long userId);

Long countByPost(PostEntity postEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.spoony.spoony_server.domain.spoon.entity.SpoonBalanceEntity;
import com.spoony.spoony_server.domain.spoon.entity.SpoonHistoryEntity;
import com.spoony.spoony_server.domain.spoon.repository.ActivityRepository;
import com.spoony.spoony_server.domain.spoon.repository.ScoopPostRepository;
import com.spoony.spoony_server.domain.spoon.repository.SpoonBalanceRepository;
import com.spoony.spoony_server.domain.spoon.repository.SpoonHistoryRepository;
import com.spoony.spoony_server.domain.user.entity.FollowEntity;
Expand Down Expand Up @@ -49,15 +50,14 @@ public class PostService {
private final ZzimPostRepository zzimPostRepository;
private final FollowRepository followRepository;
private final FeedRepository feedRepository;
private final ScoopPostRepository scoopPostRepository;

@Transactional
public PostResponseDTO getPostById(Long postId) {
public PostResponseDTO getPostById(Long postId, Long userId) {

PostEntity postEntity = postRepository.findById(postId).orElseThrow(() -> new BusinessException(PostErrorMessage.NOT_FOUND_ERROR));
UserEntity userEntity = userRepository.findById(userId).orElseThrow(() -> new BusinessException(PostErrorMessage.NOT_FOUND_ERROR));

PostEntity postEntity = postRepository.findById(postId).orElseThrow(() -> new BusinessException(PostErrorMessage.POST_NOT_FOUND));
UserEntity userEntity = postEntity.getUser();
if (userEntity == null) {
throw new BusinessException(PostErrorMessage.POST_NOT_FOUND);
}

RegionEntity regionEntity = userRepository.findReigonByUserId(userEntity.getUserId()).orElseThrow(() -> new BusinessException(UserErrorMessage.USER_NOT_FOUND));
PostCategoryEntity postCategoryEntity = postCategoryRepository.findByPost(postEntity).orElseThrow(() -> new BusinessException(PostErrorMessage.POST_NOT_FOUND));
Expand All @@ -67,7 +67,14 @@ public PostResponseDTO getPostById(Long postId) {
PlaceEntity place = postEntity.getPlace();
LocalDateTime latestDate = postEntity.getUpdatedAt().isAfter(postEntity.getCreatedAt()) ? postEntity.getUpdatedAt() : postEntity.getCreatedAt();
String formattedDate = latestDate.toLocalDate().toString();
Long zzim_count = postRepository.countByPostId(postId);

Long zzim_count = zzimPostRepository.countByPost(postEntity);
Boolean isScoop = scoopPostRepository.existsByUserAndPost(userEntity, postEntity);


String IconUrlColor = categoryEntity.getIconUrlColor();
String BackgroundColor = categoryEntity.getBackgroundColor();

//List<String> category_list = List.of(categoryEntity.getCategoryName());
String category = categoryEntity.getCategoryName();

Expand All @@ -77,8 +84,11 @@ public PostResponseDTO getPostById(Long postId) {
.map(menuEntity -> menuEntity.getMenuName())
.collect(Collectors.toList());


//boolean scoop, String IconUrlColor,String BackgroundColor

return new PostResponseDTO(postId, userEntity.getUserId(), userEntity.getUserName(), regionEntity.getRegionName(), category, postEntity.getTitle(), formattedDate, menuList, postEntity.getDescription(),
place.getPlaceName(), place.getPlaceAddress(), place.getLatitude(), place.getLongitude(), zzim_count
place.getPlaceName(), place.getPlaceAddress(), place.getLatitude(), place.getLongitude(), zzim_count, isScoop, IconUrlColor, BackgroundColor
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.spoony.spoony_server.domain.spoon.repository;

import com.spoony.spoony_server.domain.post.entity.PostEntity;
import com.spoony.spoony_server.domain.post.entity.ScoopPostEntity;
import com.spoony.spoony_server.domain.user.entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ScoopPostRepository extends JpaRepository<ScoopPostEntity, Long> {
//oolean existsByUser_userId(Long userId);
boolean existsByUserAndPost(UserEntity userEntity, PostEntity postEntity); // user_id의 존재 여부 확인
}


}

0 comments on commit 33a0607

Please sign in to comment.