Skip to content

Commit

Permalink
Merge pull request #36 from 9oormthonUniv-seoultech/develop
Browse files Browse the repository at this point in the history
Develop to Main 3
  • Loading branch information
Jeongh00 authored Oct 17, 2024
2 parents 404cb4d + fe550a8 commit e64cb64
Show file tree
Hide file tree
Showing 111 changed files with 1,858 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.pocket.batch.step.AddPlacesReader;
import com.pocket.batch.step.AddPlacesWriter;
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto;
import com.pocket.outbound.entity.JpaPhotoBooth;
import com.pocket.outbound.entity.photobooth.JpaPhotoBooth;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto;
import com.pocket.domain.entity.photobooth.PhotoBooth;
import com.pocket.outbound.entity.JpaPhotoBooth;
import com.pocket.outbound.entity.photobooth.JpaPhotoBooth;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ private List<PhotoBoothFindResponseDto> mapToDto(KakaoLocalResponse response) {
PhotoBoothFindResponseDto dto = new PhotoBoothFindResponseDto(
document.getPlace_name(),
document.getRoad_address_name(),
Double.parseDouble(document.getX()),
Double.parseDouble(document.getY()),
Double.parseDouble(document.getX()),
mapToBrand(document.getCategory_name())
);
dtoList.add(dto);
Expand Down
18 changes: 15 additions & 3 deletions batch/src/main/java/com/pocket/batch/step/AddPlacesWriter.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.pocket.batch.step;

import com.pocket.outbound.entity.JpaPhotoBooth;
import com.pocket.outbound.repository.PhotoBoothRepository;
import com.pocket.outbound.entity.photobooth.JpaPhotoBooth;
import com.pocket.outbound.repository.photobooth.PhotoBoothRepository;
import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class AddPlacesWriter implements ItemWriter<JpaPhotoBooth> {

Expand All @@ -23,7 +25,17 @@ public void write(Chunk<? extends JpaPhotoBooth> chunk) throws Exception {
if (item == null) {
throw new IllegalArgumentException("Item cannot be null");
}
photoBoothRepository.save(item);

// 중복 체크: 예를 들어 이름과 좌표가 동일한지를 체크
Optional<JpaPhotoBooth> existingBooth = photoBoothRepository
.findByPhotoBoothNameAndPhotoBoothXAndPhotoBoothY(item.getPhotoBooth().getName(),
item.getPhotoBooth().getX(),
item.getPhotoBooth().getY());

// 중복이 없을 경우에만 저장
if (existingBooth.isEmpty()) {
photoBoothRepository.save(item);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto;
import com.pocket.domain.entity.photobooth.PhotoBoothBrand;
import com.pocket.outbound.entity.JpaPhotoBooth;
import com.pocket.outbound.entity.photobooth.JpaPhotoBooth;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.pocket.domain.entity.photobooth.PhotoBooth;
import com.pocket.domain.entity.photobooth.PhotoBoothBrand;
import com.pocket.outbound.entity.JpaPhotoBooth;
import com.pocket.outbound.repository.PhotoBoothRepository;
import com.pocket.outbound.entity.photobooth.JpaPhotoBooth;
import com.pocket.outbound.repository.photobooth.PhotoBoothRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
Expand Down
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,16 @@
package com.pocket.core.image.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
@Schema(description = "프리사인드 URL 요청 DTO")
public class PresignedUrlRequest {

private final String prefix;

private final String fileName;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pocket.domain.dto.image;
package com.pocket.domain.dto.album;

import java.util.List;

Expand All @@ -9,7 +9,6 @@ public record AlbumRegisterRequestDto(
String date,
List<String> hashtag,
String memo,
String imageName, // 이미지 이름
String prefix // S3 버킷 내에 저장할 경로
String filePath
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.pocket.domain.dto.album;

import java.util.List;

public record AlbumRegisterResponseDto(
Long photoboothId,
String year,
String month,
String date,
List<String> hashtag,
String memo,
String filePath
) {

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

import com.pocket.domain.entity.photobooth.PhotoBoothBrand;

public record NearPhotoBoothInfo(
Long id,
String name
String name,
PhotoBoothBrand brand,
double x,
double y
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pocket.domain.dto.review;

public record BoothFeatureCountDto(
String featureName,
Long count
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.pocket.domain.dto.review;

public record BoothFeatureDto(
Long id,
String featureName
) {

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

public record PhotoFeatureCountDto(
String featureName,
Long count
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pocket.domain.dto.review;

public record PhotoFeatureDto(
Long id,
String featureName
) {
}
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,17 @@
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<Long> boothFeatures,
List<Long> 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
) {

}
10 changes: 8 additions & 2 deletions domain/src/main/java/com/pocket/domain/entity/image/Image.java
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.image.AlbumRegisterRequestDto;
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);
}

}
Loading

0 comments on commit e64cb64

Please sign in to comment.