Skip to content
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 @@ -70,7 +70,7 @@ public GetPostResponse create(Long councilId, PostRequest dto) {
NormalizedDateTime normalized = dto.category().validateAndNormalize(dto);

//Place 객체 생성
Place place = placeService.findOrCreatePlace(dto);
Place place = placeService.findOrCreatePlace(dto.place());
Comment on lines 72 to +73
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# PostRequest 파일 찾기
fd -t f "PostRequest.java" --exec cat {}

Repository: our-campUS/our-campUS-BE

Length of output: 1752


🏁 Script executed:

# StudentCouncilPostService.java의 create 메서드와 update 메서드 주변 코드 확인
fd -t f "StudentCouncilPostService.java" --exec cat -n {} \;

Repository: our-campUS/our-campUS-BE

Length of output: 12179


🏁 Script executed:

# PlaceService의 findOrCreatePlace 메서드 확인
fd -t f "PlaceService.java" --exec cat -n {} \;

Repository: our-campUS/our-campUS-BE

Length of output: 19757


create() 메서드의 null 체크 부재로 인한 일관성 문제

PostRequestplace 필드에는 @NotNull 검증이 적용되어 있지만, update() 메서드(line 216)에서는 if (dto.place() != null && ...) 체크가 있는 반면, create() 메서드(line 73)에서는 dto.place()를 null 체크 없이 바로 전달합니다. 검증 레이어에서 @NotNull로 보호되더라도, update() 메서드의 방어적 프로그래밍 접근과 일관성 있게 create() 메서드에도 동일한 null 체크를 추가하는 것이 좋습니다.

🤖 Prompt for AI Agents
In
@src/main/java/com/campus/campus/domain/councilpost/application/service/StudentCouncilPostService.java
around lines 72 - 73, The create() method calls
placeService.findOrCreatePlace(dto.place()) without a null check, which is
inconsistent with the defensive null check in update(); modify create() so it
guards dto.place() the same way as update() (e.g., if (dto.place() != null &&
... ) then call placeService.findOrCreatePlace(dto.place()) and handle the null
case appropriately) to match PostRequest validation behavior and maintain
consistency between create() and update().


StudentCouncilPost post = studentCouncilPostMapper.createStudentCouncilPost(
writer, place, dto, normalized.startDateTime(), normalized.endDateTime()
Expand Down Expand Up @@ -214,7 +214,7 @@ public GetPostResponse update(Long councilId, Long postId, PostRequest dto) {

Place place = post.getPlace();
if (dto.place() != null && (place == null || !dto.place().placeName().equals(place.getPlaceName()))) {
place = placeService.findOrCreatePlace(dto);
place = placeService.findOrCreatePlace(dto.place());
}

post.update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public interface PostImageRepository extends JpaRepository<PostImage, Long> {
order by pi.id asc
""")
List<String> findImageUrlsByPost(@Param("post") StudentCouncilPost post);

List<PostImage> findAllByPostIn(List<StudentCouncilPost> posts);
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ Page<StudentCouncilPost> findUpcomingMajorEvents(
LEFT JOIN w.school s
LEFT JOIN w.college c
LEFT JOIN w.major m
JOIN p.place pl
WHERE w.deletedAt IS NULL
AND p.category = :category
AND p.startDateTime <= :now
Expand Down Expand Up @@ -249,7 +250,7 @@ List<StudentCouncilPost> findByUserScopeWithCursor(
SELECT p
FROM StudentCouncilPost p
JOIN p.writer w
JOIN p.place pl
JOIN FETCH p.place pl
LEFT JOIN w.school s
LEFT JOIN w.college c
LEFT JOIN w.major m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
@RequiredArgsConstructor
@Slf4j
public class StudentCouncilPostForUserController {
private final StudentCouncilPostForUserService postService;

@PostMapping("/{postId}/like")
@Operation(summary = "학생회 게시글 좋아요 토글")
Expand All @@ -56,8 +57,6 @@ public CommonResponse<Page<GetLikedPostResponse>> getLikedPosts(
return CommonResponse.success(StudentCouncilPostResponseCode.POST_LIST_READ_SUCCESS, responses);
}

private final StudentCouncilPostForUserService postService;

@GetMapping("/school")
@Operation(
summary = "학교 학생회 게시글 목록 조회",
Expand All @@ -79,10 +78,11 @@ public CommonResponse<Page<PostListItemResponse>> getSchoolPosts(
@RequestParam(required = false) PostCategory category,
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "20") int size,
@RequestParam(required = false) Long excludePostId,
@RequestParam(required = false) Long excludePostId,
@CurrentUserId Long userId
) {
Page<PostListItemResponse> responseDto = postService.findSchoolPosts(category, page, size, userId, excludePostId);
Page<PostListItemResponse> responseDto = postService.findSchoolPosts(category, page, size, userId,
excludePostId);
return CommonResponse.success(StudentCouncilPostResponseCode.POST_LIST_READ_SUCCESS, responseDto);
}

Expand Down Expand Up @@ -111,7 +111,8 @@ public CommonResponse<Page<PostListItemResponse>> getCollegePosts(
@RequestParam(required = false) Long excludePostId,
@CurrentUserId Long userId
) {
Page<PostListItemResponse> responseDto = postService.findCollegePosts(category, page, size, userId, excludePostId);
Page<PostListItemResponse> responseDto = postService.findCollegePosts(category, page, size, userId,
excludePostId);

return CommonResponse.success(StudentCouncilPostResponseCode.POST_LIST_READ_SUCCESS, responseDto);
}
Expand Down Expand Up @@ -141,7 +142,8 @@ public CommonResponse<Page<PostListItemResponse>> getMajorPosts(
@RequestParam(required = false) Long excludePostId,
@CurrentUserId Long userId
) {
Page<PostListItemResponse> responseDto = postService.findMajorPosts(category, page, size, userId, excludePostId);
Page<PostListItemResponse> responseDto = postService.findMajorPosts(category, page, size, userId,
excludePostId);

return CommonResponse.success(StudentCouncilPostResponseCode.POST_LIST_READ_SUCCESS, responseDto);
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.campus.campus.domain.partnership.application.dto.response;
package com.campus.campus.domain.place.application.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

import com.campus.campus.domain.council.domain.entity.CouncilType;
import com.campus.campus.domain.councilpost.domain.entity.StudentCouncilPost;
import com.campus.campus.domain.partnership.application.dto.response.PartnershipPinResponse;
import com.campus.campus.domain.place.application.dto.response.PartnershipPinResponse;
import com.campus.campus.domain.place.application.dto.response.LikeResponse;
import com.campus.campus.domain.place.application.dto.response.SavedPlaceInfo;
import com.campus.campus.domain.place.application.dto.response.geocoder.AddressResponse;
import com.campus.campus.domain.place.application.dto.response.naver.NaverSearchResponse;
import com.campus.campus.domain.place.application.dto.response.partnership.PartnershipResponse;
import com.campus.campus.domain.place.domain.entity.Coordinate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.campus.campus.domain.partnership.application.service;
package com.campus.campus.domain.place.application.service;

import java.time.LocalDateTime;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand All @@ -15,10 +18,11 @@
import com.campus.campus.domain.councilpost.application.exception.PlaceInfoNotFoundException;
import com.campus.campus.domain.councilpost.application.exception.PostNotFoundException;
import com.campus.campus.domain.councilpost.domain.entity.PostCategory;
import com.campus.campus.domain.councilpost.domain.entity.PostImage;
import com.campus.campus.domain.councilpost.domain.entity.StudentCouncilPost;
import com.campus.campus.domain.councilpost.domain.repository.PostImageRepository;
import com.campus.campus.domain.councilpost.domain.repository.StudentCouncilPostRepository;
import com.campus.campus.domain.partnership.application.dto.response.PartnershipPinResponse;
import com.campus.campus.domain.place.application.dto.response.PartnershipPinResponse;
import com.campus.campus.domain.place.application.dto.response.partnership.PartnershipResponse;
import com.campus.campus.domain.place.application.mapper.PlaceMapper;
import com.campus.campus.domain.place.domain.entity.Place;
Expand All @@ -34,15 +38,15 @@
@Slf4j
@RequiredArgsConstructor
@Service
public class PartnershipService {
public class PartnershipPlaceService {

private final UserRepository userRepository;
private final LikedPlacesRepository likedPlacesRepository;
private final PostImageRepository postImageRepository;
private final PlaceMapper placeMapper;
private final StudentCouncilPostRepository studentCouncilPostRepository;

@Transactional
@Transactional(readOnly = true)
public List<PartnershipResponse> getPartnershipPlaces(Long userId, Long cursor, int size, double userLat,
double userLng) {
User user = userRepository.findById(userId)
Expand All @@ -58,45 +62,67 @@ public List<PartnershipResponse> getPartnershipPlaces(Long userId, Long cursor,

//유저가 속한 학생회들의 제휴글(major/college/school) 전부 조회
List<StudentCouncilPost> posts = studentCouncilPostRepository.findByUserScopeWithCursor(
majorId,
collegeId,
schoolId,
majorId, collegeId, schoolId,
PostCategory.PARTNERSHIP,
CouncilType.MAJOR_COUNCIL,
CouncilType.COLLEGE_COUNCIL,
CouncilType.SCHOOL_COUNCIL,
cursor,
LocalDateTime.now(),
pageable
CouncilType.MAJOR_COUNCIL, CouncilType.COLLEGE_COUNCIL, CouncilType.SCHOOL_COUNCIL,
cursor, LocalDateTime.now(), pageable
);

return posts.stream()
.filter(post -> post.getPlace() != null && post.getPlace().getCoordinate() != null)
List<AbstractMap.SimpleEntry<StudentCouncilPost, Double>> sortedEntries = posts.stream()
.map(post -> {
Place place = post.getPlace();

double distanceMeter = GeoUtil.distanceMeter(
userLat, userLng,
place.getCoordinate().latitude(),
place.getCoordinate().longitude()
);

// post + distance를 함께 묶음
return new AbstractMap.SimpleEntry<>(post, distanceMeter);
})
.sorted(Map.Entry.comparingByValue()) // 거리순 정렬
.sorted(Map.Entry.comparingByValue())
.limit(size)
.toList();

if (sortedEntries.isEmpty()) {
return List.of();
}

List<StudentCouncilPost> targetPosts = sortedEntries.stream()
.map(AbstractMap.SimpleEntry::getKey)
.toList();

Set<Long> placeIds = targetPosts.stream()
.map(post -> post.getPlace().getPlaceId())
.collect(Collectors.toSet());

Map<Long, List<String>> postImageMap = postImageRepository.findAllByPostIn(targetPosts)
.stream()
.collect(Collectors.groupingBy(
img -> img.getPost().getId(),
Collectors.mapping(PostImage::getImageUrl, Collectors.toList())
));

Set<Long> likedPlaceIds;
if (placeIds.isEmpty()) {
likedPlaceIds = Collections.emptySet();
} else {
likedPlaceIds = likedPlacesRepository.findLikedPlaceIds(userId, placeIds);
}

return sortedEntries.stream()
.map(entry -> {
StudentCouncilPost post = entry.getKey();
double distanceMeter = entry.getValue();
double rounded = Math.round(distanceMeter * 100.0) / 100.0;

List<String> images = postImageMap.getOrDefault(post.getId(), List.of());
boolean isLiked = likedPlaceIds.contains(post.getPlace().getPlaceId());

return placeMapper.toPartnershipResponse(
user,
post,
post.getPlace(),
isLiked(post.getPlace(), user),
getImgUrls(post),
isLiked,
images,
rounded
);
})
Expand Down Expand Up @@ -144,9 +170,7 @@ public PartnershipResponse getPartnershipDetail(Long postId, Long userId, double
.orElseThrow(UserNotFoundException::new);

double distanceMeter = GeoUtil.distanceMeter(
userLat, userLng,
place.getCoordinate().latitude(),
place.getCoordinate().longitude()
userLat, userLng, place.getCoordinate().latitude(), place.getCoordinate().longitude()
);
double rounded = Math.round(distanceMeter * 100.0) / 100.0;

Expand Down
Loading