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 12 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
f8d6ad4
feat: ๋ฆฌ๋ทฐ ๋“ฑ๋ก API
JiinHong Oct 12, 2024
7fac5de
feat: ํฌํ† ๋ถ€์Šค ๋ณ„์  ์กฐํšŒ API
JiinHong Oct 12, 2024
65c2936
feat: ํฌํ† ๋ถ€์Šค ์‚ฌ์ง„ 6๊ฐœ ์กฐํšŒ API
JiinHong Oct 13, 2024
e31253f
feat: ํฌํ† ๋ถ€์Šค ์‚ฌ์ง„ 6๊ฐœ ์กฐํšŒ API (์‚ฌ์ง„ ์ด ๊ฐœ์ˆ˜ ์ถ”๊ฐ€)
JiinHong Oct 13, 2024
d0d6e9c
feat: ํฌํ† ๋ถ€์Šค ์ตœ๊ทผ ๋ฆฌ๋ทฐ 3๊ฐœ ์กฐํšŒ API
JiinHong Oct 13, 2024
1a197ce
feat: ๋ชจ๋“  ๋ฆฌ๋ทฐ ์‚ฌ์ง„ ์กฐํšŒ API
JiinHong Oct 13, 2024
3dc3ba0
feat: ํฌํ† ๋ถ€์Šค ์ตœ๊ทผ ๋ฆฌ๋ทฐ 2๊ฐœ ์กฐํšŒ API (3๊ฐœ์—์„œ 2๊ฐœ๋กœ ๋ณ€๊ฒฝ)
JiinHong Oct 13, 2024
a4374da
feat: ๋ฆฌ๋ทฐ ํฌํ† ๋ถ€์Šค ํŠน์ง• ์กฐํšŒ API
JiinHong Oct 13, 2024
a70dc5b
feat: ๋ฆฌ๋ทฐ ํฌํ† ๋ถ€์Šค ํŠน์ง• ์กฐํšŒ API (์ˆ˜์ •)
JiinHong Oct 13, 2024
c6fa59e
feat: ๋ฆฌ๋ทฐ ์ดฌ์˜ ํŠน์ง• ์กฐํšŒ API
JiinHong Oct 13, 2024
9c16e83
feat:ํฌํ† ๋ถ€์Šค ์ด๋ฆ„ ์กฐํšŒ(at ๋ฆฌ๋ทฐ ๋“ฑ๋ก ํŽ˜์ด์ง€) API
JiinHong Oct 13, 2024
d7b372e
docs: swagger ๋ฌธ์„œ ์ž…ํžˆ๊ธฐ
Jeongh00 Oct 13, 2024
6964817
feat: ์ฝ”๋“œ๋ฆฌ๋ทฐ ๋ฐ˜์˜
JiinHong Oct 14, 2024
5fb4e89
feat: querydsl ์„ค์ • & ์ฟผ๋ฆฌ ์ ์šฉ
Jeongh00 Oct 16, 2024
c5f89ee
feat: query dsl config
Jeongh00 Oct 16, 2024
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
@@ -0,0 +1,7 @@
package com.pocket.domain.dto.review;

public record ReviewBoothFeatureDto(
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,7 @@
package com.pocket.domain.dto.review;

public record ReviewPhotoFeatureDto(
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
Expand Up @@ -21,4 +21,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 IllegalArgumentException("ํ•ด๋‹น ์„ค๋ช…์— ๋งž๋Š” BoothFeature๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค: " + description);
JiinHong marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,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 IllegalArgumentException("ํ•ด๋‹น ์„ค๋ช…์— ๋งž๋Š” PhotoFeature๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค: " + description);
JiinHong marked this conversation as resolved.
Show resolved Hide resolved
}
}
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);

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

import com.pocket.domain.dto.review.ReviewRegisterRequestDto;
import com.pocket.domain.dto.review.ReviewRegisterResponseDto;

public interface ReviewRegisterPort {

ReviewRegisterResponseDto registerReview(ReviewRegisterRequestDto requestDto, String name);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,38 @@
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto;
import com.pocket.domain.entity.photobooth.PhotoBoothBrand;
import com.pocket.domain.port.photobooth.PhotoBoothFindPort;
import com.pocket.domain.port.photobooth.PhotoBoothGetNamePort;
import com.pocket.domain.port.photobooth.PhotoBoothGetRatingPort;
import com.pocket.domain.usecase.photobooth.PhotoBoothFindUseCase;
import com.pocket.domain.usecase.photobooth.PhotoBoothGetNameUseCase;
import com.pocket.domain.usecase.photobooth.PhotoBoothGetRatingUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;


@Service
@RequiredArgsConstructor
public class PhotoBoothFindService implements PhotoBoothFindUseCase {
public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNameUseCase, PhotoBoothGetRatingUseCase {

private final PhotoBoothFindPort photoBoothFindPort;
private final PhotoBoothGetRatingPort photoBoothGetRatingPort;
private final PhotoBoothGetNamePort photoBoothGetNamePort;

public PhotoBoothFindResponseDto findPhotoBoothResponse(Long id) {
return photoBoothFindPort.findById(id);
}

public String getPhotoBoothName(Long photoboothId) {
return photoBoothGetNamePort.getPhotoBoothName(photoboothId);
}
public List<NearPhotoBoothInfo> findNearPhotoBooth(double lat, double lon, List<PhotoBoothBrand> brand) {
return photoBoothFindPort.getPhotoboothWithin2Km(lat, lon, brand);
}

public BigDecimal getPhotoBoothRating(Long photoboothId) {
return photoBoothGetRatingPort.getRating(photoboothId);
}
}
Loading