Skip to content

Commit

Permalink
chore: 주석 추가, 오타 수정
Browse files Browse the repository at this point in the history
- SearchHistoryResponseDtoV2 에서 serachTime -> searchTime으로 수정
- 함수별 기능 주석 추가 + 필요한 경우 로직 설명 주석 추가
- dto 목적에 대한 주석 추가
  • Loading branch information
yeonjae02 committed Aug 2, 2024
1 parent 7b31701 commit f43b145
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class PostDetailDto {
public class PostDetailDto { // 게시글 상세 조회에 사용하는 DTO
private String nickname;
private String profileImagerUrl;
private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class PostRequestDto {
public class PostRequestDto { // 게시글 작성 시 사용하는 DTO
private Long memberId;

@NotBlank(message = "제목은 비워둘 수 없습니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Getter @Setter
@AllArgsConstructor
@NoArgsConstructor
public class PostResponseDto {
public class PostResponseDto { // 게시글 정보를 게시글 전체 리스트 상태에서 보기 위해 사용하는 DTO
private Long postId;
private String firstImageUrl;
private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class PostUpdateDto {
public class PostUpdateDto { // 게시글 수정 시 사용하는 DTO
@Size(max=100, message="제목은 최대 100자까지 가능합니다.")
private String title;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
public interface ImageRepository extends JpaRepository<Image, Long> {
Optional<Image> findByMemberIdAndPostIsNull(Long memberId); // 회원의 프로필 이미지를 찾는 경우

// 게시글에서 해당 이미지가 포함된 개수를 반환합니다.
@Query("SELECT COUNT(i) FROM Image i WHERE i.imageUrl = :imageUrl AND i.post.id = :postId")
Long countByImageUrlAndPostId(@Param("imageUrl") String imageUrl, @Param("postId") Long postId);

// 해당 게시글에서의 이미지 순서 번호를 반환합니다.
@Query("SELECT i.order FROM Image i WHERE i.imageUrl = :imageUrl AND i.post.id = :postId")
Integer findOrderByImageUrlAndPostId(@Param("imageUrl") String imageUrl, @Param("postId") Long postId);

// 게시글 수정 시 삭제할 이미지 url을 이용하여 DB에서 삭제합니다.
@Modifying
@Query("DELETE FROM Image i WHERE i.imageUrl = :imageUrl AND i.post.id = :postId")
void deleteImageByImageUrlAndPostId(@Param("imageUrl") String imageUrl, @Param("postId") Long postId);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public ResponseEntity<Object> saveHistory(Authentication authentication,
}
}

// 데이터 저장
searchHistoryService.save(neighborhood, memberEmail, searchHistoryRequestDtos);
return ResponseEntity.status(HttpStatus.CREATED).body(Map.of("message", "장소를 저장하였습니다."));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class PlaceDtoV2 {
public class PlaceDtoV2 { // 장소 정보 DTO
@NotBlank(message = "장소ID가 누락되었습니다.")
private String placeId; // 장소의 고유 ID

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SearchHistoryRequestDtoV2 {
public class SearchHistoryRequestDtoV2 { // 검색 기록 저장 시 사용하는 DTO
@NotBlank
private String neighborhood;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SearchHistoryResponseDtoV2 {
public class SearchHistoryResponseDtoV2 { // 검색 기록 리스트 시 사용하는 DTO
private String neighborhood;
private LocalDateTime serachTime;
private LocalDateTime searchTime;
private List<PlaceDtoV2> places = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@

@Repository
public interface SearchHistoryRepositoryV2 extends JpaRepository<SearchHistoryV2, Long> {
// 멤버가 저장한 검색 기록을 최신순부터 가져옵니다.
List<SearchHistoryV2> findByMemberOrderBySearchDateDesc(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public class SearchHistoryServiceV2 {
private final SearchHistoryRepositoryV2 searchHistoryRepository;
private final MemberService memberService;

/**
* 검색 기록을 저장합니다.
*
* @param neighborhood 동 정보
* @param memberEmail 사용자 정보
* @param placeDtos 장소 정보 리스트
*/
@Transactional
public void save(String neighborhood, String memberEmail, List<PlaceDtoV2> placeDtos) {
Member member = memberService.getMemberByEmail(memberEmail);
Expand All @@ -38,7 +45,7 @@ public void save(String neighborhood, String memberEmail, List<PlaceDtoV2> place

for (PlaceDtoV2 dto : placeDtos) {
String imageUrl = dto.getImageUrl();
if (imageUrl == null || imageUrl.trim().isEmpty()) { // 이미지 url이 없거나 공백
if (imageUrl == null || imageUrl.trim().isEmpty()) { // 해당 장소의 이미지가 존재하지 않을 경우 기본 이미지를 저장합니다.
imageUrl = defaultImageUrl;
}

Expand All @@ -47,13 +54,18 @@ public void save(String neighborhood, String memberEmail, List<PlaceDtoV2> place
.placeId(dto.getPlaceId())
.address(dto.getPlaceAddress())
.imageUrl(imageUrl)
.searchHistory(searchHistory) // searchHistory 필드 설정
.searchHistory(searchHistory) /// 연관관계 설정
.build();
searchHistory.getPlaceList().add(placeInfo);
}
searchHistoryRepository.save(searchHistory);
}

/**
* 사용자가 저장한 검색 기록을 전부 최신순부터 반환합니다.
* @param member 사용자
* @return 검색 기록 정보 리스트
*/
@Transactional(readOnly = true)
public List<SearchHistoryResponseDtoV2> getHistory(Member member) {
List<SearchHistoryV2> histories = searchHistoryRepository.findByMemberOrderBySearchDateDesc(member);
Expand Down

0 comments on commit f43b145

Please sign in to comment.