Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev-api' into dev-api
Browse files Browse the repository at this point in the history
# Conflicts:
#	findMuse-API/src/main/java/com/whh/findmuseapi/review/repository/ReviewRepository.java
ehyeok9 committed Nov 25, 2024
2 parents 3dc100b + 24ca201 commit c8d74d6
Showing 28 changed files with 578 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.whh.findmuseapi.art.controller;

import com.whh.findmuseapi.art.dto.ArtHomeResponse;
import com.whh.findmuseapi.art.dto.response.ArtHomeResponse;
import com.whh.findmuseapi.art.dto.ArtLikeRequest;
import com.whh.findmuseapi.art.dto.ArtListResponse;
import com.whh.findmuseapi.art.dto.ArtOneResponse;
import com.whh.findmuseapi.art.dto.response.ArtListResponse;
import com.whh.findmuseapi.art.dto.response.ArtOneResponse;
import com.whh.findmuseapi.art.service.ArtService;
import com.whh.findmuseapi.common.constant.ResponseCode;
import com.whh.findmuseapi.common.util.ApiResponse;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.whh.findmuseapi.art.controller;

import com.whh.findmuseapi.art.dto.MapResponse;
import com.whh.findmuseapi.art.dto.response.MapResponse;
import com.whh.findmuseapi.art.service.ArtService;
import com.whh.findmuseapi.common.constant.ResponseCode;
import com.whh.findmuseapi.common.util.ApiResponse;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.whh.findmuseapi.art.dto.response;

import com.whh.findmuseapi.art.entity.ArtHistory;
import lombok.Builder;

@Builder
public record ArtHistoryResponse(
Long id,
float star,
boolean activeStatus,
Long userId,
ArtTumbnailResponse art
) {
public static ArtHistoryResponse fromEntity(ArtHistory artHistory) {
return ArtHistoryResponse.builder()
.id(artHistory.getId())
.star(artHistory.getStar())
.activeStatus(artHistory.isActiveStatus())
.userId(artHistory.getUser().getId())
.art(ArtTumbnailResponse.toDto(artHistory.getArt()))
.build();
}
}


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.whh.findmuseapi.art.dto;
package com.whh.findmuseapi.art.dto.response;

import com.whh.findmuseapi.art.entity.Art;
import lombok.Builder;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.whh.findmuseapi.art.dto.response;


import com.whh.findmuseapi.art.entity.Art;
import lombok.Builder;
import lombok.Getter;

import java.util.List;


@Builder
@Getter
public class ArtListResponse {

private List<ArtTumbnailResponse> artList;

public static ArtListResponse toDto(List<Art> arts) {
return ArtListResponse.builder()
.artList(arts.stream()
.map(ArtTumbnailResponse::toDto).toList()).build();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.whh.findmuseapi.art.dto;
package com.whh.findmuseapi.art.dto.response;

import com.whh.findmuseapi.art.entity.Art;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.whh.findmuseapi.art.dto;
package com.whh.findmuseapi.art.dto.response;

import com.whh.findmuseapi.art.entity.Art;
import lombok.Builder;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.whh.findmuseapi.art.dto.response;

import com.whh.findmuseapi.art.entity.Art;
import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
class ArtTumbnailResponse {
private String title;
private String place;
private String genre;
private String poster;
private String startDate;
private String endDate;
private boolean isLiked; // 관심여부

public static ArtTumbnailResponse toDto(Art art) {
return ArtTumbnailResponse.builder()
.title(art.getTitle())
.place(art.getPlace())
.genre(art.getArtType().getInfo())
.poster(art.getPoster())
.startDate(art.getStartDate())
.endDate(art.getEndDate())
.isLiked(!art.getArtLikes().isEmpty())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.whh.findmuseapi.art.dto;
package com.whh.findmuseapi.art.dto.response;

import com.whh.findmuseapi.art.entity.Art;
import lombok.Builder;
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ public class Art {
@OneToMany(mappedBy = "art", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
private List<Ticket> tickets = new ArrayList<>();

@OneToMany(mappedBy = "art", fetch = FetchType.LAZY)
@OneToMany(mappedBy = "art", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<ArtLike> artLikes = new ArrayList<>();

@OneToMany(mappedBy = "art", fetch = FetchType.LAZY)
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.whh.findmuseapi.art.service;

import com.whh.findmuseapi.art.dto.*;
import com.whh.findmuseapi.art.dto.response.ArtHomeResponse;
import com.whh.findmuseapi.art.dto.response.ArtListResponse;
import com.whh.findmuseapi.art.dto.response.ArtOneResponse;
import com.whh.findmuseapi.art.dto.response.MapResponse;

import java.util.List;

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.whh.findmuseapi.art.service;

import com.whh.findmuseapi.art.dto.*;
import com.whh.findmuseapi.art.dto.response.*;
import com.whh.findmuseapi.art.entity.Art;
import com.whh.findmuseapi.art.entity.ArtLike;
import com.whh.findmuseapi.art.repository.ArtHistoryRepository;
Original file line number Diff line number Diff line change
@@ -72,8 +72,26 @@ public static ArtType convert(String info){
}
throw new CBadRequestException("일치하는 장르가 없습니다. 다시 요청해주세요");
}

}

@Getter
@RequiredArgsConstructor
public enum ReviewSortType {
LATEST("최신순"),
POPULAR("인기순");

private final String description;

public static ReviewSortType fromString(String value) {
for (ReviewSortType type : ReviewSortType.values()) {
if (type.getDescription().equals(value)) {
return type;
}
}
throw new IllegalArgumentException("Invalid ReviewSortType: " + value);
}
}

@RequiredArgsConstructor
public enum AlarmType {
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.whh.findmuseapi.review.dto;

import com.whh.findmuseapi.review.entity.ArtReview;
import com.whh.findmuseapi.review.entity.ArtReviewLike;
import lombok.Builder;

import java.time.format.DateTimeFormatter;

@Builder
public record ReviewResponse(
Long artId,
String artTitle,
String artPoster,
String name,
String star,
String content,
String date,
boolean isThumbed,
int thumbsUpCnt
) {
public static ReviewResponse toDto(ArtReview review, ArtReviewLike reviewLike) {
return ReviewResponse.builder()
.artId(review.getArt().getId())
.artTitle(review.getArt().getTitle())
.artPoster(review.getArt().getPoster())
.name(review.getUser().getNickname())
.star(review.getStar())
.content(review.getContent())
.date(review.getCreateDate().toString())
.date(review.getCreateDate().format(DateTimeFormatter.ISO_LOCAL_DATE))
.isThumbed(reviewLike != null && reviewLike.getUser() != null)
.thumbsUpCnt(review.getLikeCount())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -5,9 +5,11 @@
import com.whh.findmuseapi.user.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

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

@Repository
@@ -17,8 +19,18 @@ public interface ReviewRepository extends JpaRepository<ArtReview, Long> {
ArtReview findByUserAndArt(User user, Art art);

@Query("select ar from ArtReview ar left join ar.reviewLikes arl on ar.id = arl.artReview.id where ar.art.id = :artId and arl.user.id = :userId order by ar.createDate desc")
List<ArtReview> findAllByArtOrderByCreateDateDesc(Long artId, Long userId);
Optional<List<ArtReview>> findAllByArtOrderByCreateDateDesc(Long artId, Long userId);

// @Query("select ar from ArtReview ar left join ar.reviewLikes arl on ar.id = arl.artReview.id where ar.art.id = :artId and arl.user.id = :userId order by ar.likeCount desc")
// List<ArtReview> findAllByArtOrderByLikeCountDesc(Long artId, Long userId);
@Query("select ar, arl from ArtReview ar left join ArtReviewLike arl on ar.id = arl.artReview.id where ar.art.id = :artId and arl.user.id = :userId order by ar.likeCount desc")
Optional<List<Object[]>> findAllByArtOrderByLikeCountDesc(Long artId, Long userId);

// 최신순 리뷰 목록 조회
@Query("select ar, arl from ArtReview ar left join ArtReviewLike arl on ar.id = arl.artReview.id where ar.user.id = :userId order by ar.createDate desc")
List<Object[]> findAllByUserOrderByCreateDateDesc(Long userId);

// 인기순 리뷰 목록 조회
@Query("select ar, arl from ArtReview ar left join ArtReviewLike arl on ar.id = arl.artReview.id where ar.user.id = :userId order by ar.likeCount desc")
List<Object[]> findAllByUserOrderByLikeCountDesc(Long userId);
@Query("select ar from ArtReview ar left join ar.reviewLikes arl on ar.id = arl.artReview.id where ar.art.id = :artId and arl.user.id = :userId order by ar.likeCount desc")
Optional<List<ArtReview>> findAllByArtOrderByLikeCountDesc(Long artId, Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.whh.findmuseapi.user.controller;

import com.whh.findmuseapi.common.constant.ResponseCode;
import com.whh.findmuseapi.common.util.ApiResponse;
import com.whh.findmuseapi.user.entity.User;
import com.whh.findmuseapi.user.service.BlackUserService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class BlackUserController {

private final BlackUserService blackUserService;

@Operation(summary = "사용자 차단")
@PostMapping("/block/{targetUserId}")
public ApiResponse<Void> blockUser(@AuthenticationPrincipal User user, @PathVariable long targetUserId) {
blackUserService.blockUser(user, targetUserId);
return ApiResponse.createSuccess(ResponseCode.SUCCESS, null);
}

@Operation(summary = "차단된 사용자 목록 조회")
@GetMapping("/list")
public ApiResponse<List<User>> getBlockedUsers(@AuthenticationPrincipal User user) {
return ApiResponse.createSuccess(ResponseCode.SUCCESS, blackUserService.getBlockedUsers(user));
}

@Operation(summary = "사용자 차단 해제")
@PostMapping("/unblock/{targetUserId}")
public ApiResponse<Void> unblockUser(@AuthenticationPrincipal User user, @PathVariable long targetUserId) {
blackUserService.unblockUser(user, targetUserId);
return ApiResponse.createSuccess(ResponseCode.SUCCESS, null);
}
}
Original file line number Diff line number Diff line change
@@ -93,12 +93,4 @@ public ApiResponse<?> updateProfile(@AuthenticationPrincipal User user,
userService.updateProfile(user, userProfileChangeRequest, profileImage);
return ApiResponse.createSuccessWithNoContent(ResponseCode.SUCCESS);
}

@Operation(summary = "마이페이지 : 메인 화면")
@GetMapping("/main")
public ApiResponse<MyInfo> getMyInfo(@AuthenticationPrincipal User user) {
return ApiResponse.createSuccess(ResponseCode.SUCCESS, userInfoService.getMyInfo(user));
}


}
Loading

0 comments on commit c8d74d6

Please sign in to comment.