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

Feat/#34 Review API #35

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.3.3'
id 'io.spring.dependency-management' version '1.1.6'
id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10'
}

allprojects {
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/java/com/pocket/core/config/QueryDslConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.pocket.core.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QueryDslConfig {

@PersistenceContext
private EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.pocket.core.exception.review;


import lombok.Getter;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@Getter
@ResponseStatus(HttpStatus.BAD_REQUEST)
public class ReviewCustomException extends RuntimeException {

private final ReviewErrorCode errorCode;

public ReviewCustomException(ReviewErrorCode errorCode) {
this.errorCode = errorCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.pocket.core.exception.review;

import com.pocket.core.exception.common.ApiResponse;
import com.pocket.core.exception.common.BaseErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum ReviewErrorCode implements BaseErrorCode {
PHOTO_FEATURE_NOT_FOUND(HttpStatus.BAD_REQUEST, "400","해당 설명에 맞는 PhotoFeature가 없습니다"),
BOOTH_FEATURE_NOT_FOUND(HttpStatus.BAD_REQUEST, "400","해당 설명에 맞는 BoothFeature가 없습니다");


private final HttpStatus httpStatus;
private final String code;
private final String message;

@Override
public ApiResponse<Void> getErrorResponse() {
return ApiResponse.onFailure(code, message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.dto.review;

import java.util.List;

public record ReviewBoothFeatureDto(
List<String> featureName,
int count
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.dto.review;

import java.util.List;

public record ReviewGet6ImagesResponseDto(
List<String> filePaths,
int totalImageCount
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.dto.review;

import java.util.List;

public record ReviewGetRecentResponseDto(
int reviewCount,
List<ReviewPreviewDto> reviews
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.dto.review;

import java.util.List;

public record ReviewPhotoFeatureDto(
List<String> featureName,
int count
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pocket.domain.dto.review;

import java.util.List;

public record ReviewPreviewDto(
Long photoboothId,
String name,
String year,
String month,
String date,
String contents,
List<String> features,
String imageUrl,
int imageCount
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.pocket.domain.dto.review;

import java.util.List;

public record ReviewRegisterRequestDto(
Long photoboothId,
int rating,
List<String> boothFeatures,
List<String> photoFeatures,
List<String> filePaths,
String content
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.pocket.domain.dto.review;

import java.util.List;

public record ReviewRegisterResponseDto(
Long photoboothId,
int rating,
List<String> boothFeatures,
List<String> photoFeatures,
List<String> filePaths,
String content
) {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pocket.domain.entity.image;

import com.pocket.domain.dto.album.AlbumRegisterRequestDto;
import com.pocket.domain.dto.review.ReviewRegisterRequestDto;
import com.pocket.domain.entity.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
Expand Down Expand Up @@ -30,11 +31,16 @@ public Image(ImageType type) {
this.type = type;
}

public void makeImage(AlbumRegisterRequestDto dto, String filePath) {
public void makeAlbumImage(AlbumRegisterRequestDto dto, String filePath) {
this.type = ImageType.PHOTO;
this.imageUrl = filePath;
this.year = dto.year();
this.month = dto.month();
this.date = dto.date();
}

public void makeReviewImage(String filePath) {
this.type = ImageType.REVIEW;
this.imageUrl = filePath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

@Getter
@Embeddable
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -26,16 +28,33 @@ public class PhotoBooth {
@Column(name = "photo_booth_brand")
private PhotoBoothBrand photoBoothBrand;

// 총 리뷰 수
private int totalReviews;

// 평균 별점
@Column(precision = 3, scale = 2)
private BigDecimal averageRating; // 기본값을 0으로 설정

private PhotoBooth(String name, String road, Double x, Double y, PhotoBoothBrand photoBoothBrand) {
this.name = name;
this.road = road;
this.x = x;
this.y = y;
this.photoBoothBrand = photoBoothBrand;
this.totalReviews = 0;
this.averageRating = BigDecimal.ZERO;
}

// 정적 팩토리 메서드
public static PhotoBooth create(String name, String road, Double x, Double y, PhotoBoothBrand brand) {
return new PhotoBooth(name, road, x, y, brand);
}

public void updateRating(int newRating) {
this.totalReviews += 1;
BigDecimal totalScore = this.averageRating.multiply(BigDecimal.valueOf(this.totalReviews - 1))
.add(BigDecimal.valueOf(newRating));
this.averageRating = totalScore.divide(BigDecimal.valueOf(this.totalReviews), 2, BigDecimal.ROUND_HALF_UP);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.pocket.domain.entity.review;


import com.pocket.core.exception.review.ReviewCustomException;
import com.pocket.core.exception.review.ReviewErrorCode;

public enum BoothFeature {
CLEAN_PROPS("깔끔한 소품"),
PRETTY_SELFIE_ZONE("예쁜 셀카존"),
Expand All @@ -21,4 +24,14 @@ public enum BoothFeature {
public String getDescription() {
return description;
}

// 한글 설명을 받아 enum을 반환하는 메소드
public static BoothFeature fromDescription(String description) {
for (BoothFeature feature : BoothFeature.values()) {
if (feature.getDescription().equals(description)) {
return feature;
}
}
throw new ReviewCustomException(ReviewErrorCode.BOOTH_FEATURE_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.pocket.domain.entity.review;

import com.pocket.core.exception.review.ReviewCustomException;
import com.pocket.core.exception.review.ReviewErrorCode;

public enum PhotoFeature {
NO_GLARE("빛번짐 없음"),
HIGH_DEFINITION("선명한 화질"),
Expand All @@ -18,4 +21,14 @@ public enum PhotoFeature {
public String getDescription() {
return description;
}

// 한글 설명을 받아 enum을 반환하는 메소드
public static PhotoFeature fromDescription(String description) {
for (PhotoFeature feature : PhotoFeature.values()) {
if (feature.getDescription().equals(description)) {
return feature;
}
}
throw new ReviewCustomException(ReviewErrorCode.PHOTO_FEATURE_NOT_FOUND);
}
}
21 changes: 17 additions & 4 deletions domain/src/main/java/com/pocket/domain/entity/review/Review.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
package com.pocket.domain.entity.review;

import com.pocket.domain.entity.BaseEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

import java.util.List;

@Getter
@Embeddable
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Review {
@AllArgsConstructor
public class Review extends BaseEntity {

@Column(name = "rating")
private int rating;

@Column(name = "content")
private String content;

@ElementCollection(targetClass = BoothFeature.class)
@Enumerated(EnumType.STRING)
@Column(name = "booth_features")
private List<BoothFeature> boothFeatures;

@ElementCollection(targetClass = PhotoFeature.class)
@Enumerated(EnumType.STRING)
@Column(name = "photo_features")
private List<PhotoFeature> photoFeatures;




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pocket.domain.port.photobooth;

public interface PhotoBoothGetNamePort {

String getPhotoBoothName(Long photoboothId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.port.photobooth;

import java.math.BigDecimal;

public interface PhotoBoothGetRatingPort {

BigDecimal getRating(Long photoboothId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.pocket.domain.port.review;


import com.pocket.domain.dto.review.ReviewBoothFeatureDto;

import java.util.List;

public interface ReviewBoothFeaturePort {

List<ReviewBoothFeatureDto> getReviewBoothFeature(Long photoboothId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.port.review;

import com.pocket.domain.dto.review.ReviewGet6ImagesResponseDto;

public interface ReviewGet6ImagesPort {

ReviewGet6ImagesResponseDto get6Images(Long photoboothId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.port.review;

import java.util.List;

public interface ReviewGetAllImagesPort {

List<String> getAllImages(Long photoboothId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.port.review;

import com.pocket.domain.dto.review.ReviewGetRecentResponseDto;

public interface ReviewGetRecentPort {

ReviewGetRecentResponseDto getRecentReview(Long photoboothId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.pocket.domain.port.review;


import com.pocket.domain.dto.review.ReviewPhotoFeatureDto;

import java.util.List;

public interface ReviewPhotoFeaturePort {

List<ReviewPhotoFeatureDto> getReviewPhotoFeature(Long photoboothId);

}
Loading