Skip to content

Commit

Permalink
Merge pull request #333 from UPbrella/dev
Browse files Browse the repository at this point in the history
v0.4.1 dev pre-release
  • Loading branch information
birdieHyun authored Oct 11, 2023
2 parents 397f586 + 187ca28 commit f4f59cf
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@
public class RentExceptionHandler {

@ExceptionHandler(NonExistingUmbrellaForRentException.class)
public ResponseEntity<CustomErrorResponse> nonExistingUmbrellaForRent(NonExistingClassificationException e) {
public ResponseEntity<CustomErrorResponse> nonExistingUmbrellaForRent(NonExistingUmbrellaForRentException e) {

return ResponseEntity
.badRequest()
.body(new CustomErrorResponse(
"fail",
400,
"대여 중인 우산이 없습니다."
e.getMessage()
));
}

@ExceptionHandler(NonExistingHistoryException.class)
public ResponseEntity<CustomErrorResponse> nonExistingHistory(NonExistingClassificationException e) {
public ResponseEntity<CustomErrorResponse> nonExistingHistory(NonExistingHistoryException e) {

return ResponseEntity
.badRequest()
.body(new CustomErrorResponse(
"fail",
400,
"해당 대여 기록이 없습니다."
e.getMessage()
));
}

Expand All @@ -42,7 +42,7 @@ public ResponseEntity<CustomErrorResponse> existingUmbrellaForRent(ExistingUmbre
.body(new CustomErrorResponse(
"fail",
400,
"이미 대여 중인 우산이 있습니다."
e.getMessage()
));
}

Expand All @@ -54,7 +54,7 @@ public ResponseEntity<CustomErrorResponse> notRefundedException(NotRefundedExcep
.body(new CustomErrorResponse(
"fail",
400,
"환불이 완료되지 않았습니다."
e.getMessage()
));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package upbrella.be.store.controller;

import org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
Expand Down Expand Up @@ -107,4 +108,15 @@ public ResponseEntity<CustomErrorResponse> notExistBusinessHour(NotExistBusiness
404,
ex.getMessage()));
}

@ExceptionHandler(FileSizeLimitExceededException.class)
public ResponseEntity<CustomErrorResponse> fileSize(FileSizeLimitExceededException ex) {

return ResponseEntity
.badRequest()
.body(new CustomErrorResponse(
"bad request",
400,
ex.getMessage()));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package upbrella.be.store.dto.response;

import com.querydsl.core.annotations.QueryProjection;
import lombok.*;
import upbrella.be.store.entity.Classification;
import upbrella.be.store.entity.ClassificationType;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor
public class SingleClassificationResponse {

private long id;
Expand All @@ -16,6 +16,15 @@ public class SingleClassificationResponse {
private double latitude;
private double longitude;

@QueryProjection
public SingleClassificationResponse(long id, ClassificationType type, String name, double latitude, double longitude) {
this.id = id;
this.type = type;
this.name = name;
this.latitude = latitude;
this.longitude = longitude;
}

public static SingleClassificationResponse ofCreateClassification(Classification classification) {

return SingleClassificationResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package upbrella.be.store.dto.response;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.querydsl.core.annotations.QueryProjection;
import lombok.*;
import upbrella.be.store.entity.StoreDetail;

import java.io.Serializable;
import java.util.List;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class SingleStoreResponse implements Serializable {

private long id;
Expand All @@ -30,25 +28,23 @@ public class SingleStoreResponse implements Serializable {
private String content;
private String password;

public static SingleStoreResponse ofCreateSingleStoreResponse(StoreDetail storeDetail) {

return SingleStoreResponse.builder()
.id(storeDetail.getStoreMeta().getId())
.name(storeDetail.getStoreMeta().getName())
.category(storeDetail.getStoreMeta().getCategory())
.classification(SingleClassificationResponse.ofCreateClassification(storeDetail.getStoreMeta().getClassification()))
.subClassification(SingleSubClassificationResponse.ofCreateSubClassification(storeDetail.getStoreMeta().getSubClassification()))
.activateStatus(storeDetail.getStoreMeta().isActivated())
.address(storeDetail.getAddress())
.addressDetail(storeDetail.getAddressDetail())
.umbrellaLocation(storeDetail.getUmbrellaLocation())
.businessHour(storeDetail.getWorkingHour())
.contactNumber(storeDetail.getContactInfo())
.instagramId(storeDetail.getInstaUrl())
.latitude(storeDetail.getStoreMeta().getLatitude())
.longitude(storeDetail.getStoreMeta().getLongitude())
.content(storeDetail.getContent())
.password(storeDetail.getStoreMeta().getPassword())
.build();
@QueryProjection
public SingleStoreResponse(long id, String name, String category, SingleClassificationResponse classification, SingleSubClassificationResponse subClassification, boolean activateStatus, String address, String addressDetail, String umbrellaLocation, String businessHour, String contactNumber, String instagramId, double latitude, double longitude, String content, String password) {
this.id = id;
this.name = name;
this.category = category;
this.classification = classification;
this.subClassification = subClassification;
this.activateStatus = activateStatus;
this.address = address;
this.addressDetail = addressDetail;
this.umbrellaLocation = umbrellaLocation;
this.businessHour = businessHour;
this.contactNumber = contactNumber;
this.instagramId = instagramId;
this.latitude = latitude;
this.longitude = longitude;
this.content = content;
this.password = password;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package upbrella.be.store.dto.response;

import com.querydsl.core.annotations.QueryProjection;
import lombok.*;
import upbrella.be.store.entity.Classification;
import upbrella.be.store.entity.ClassificationType;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class SingleSubClassificationResponse {

private long id;
private ClassificationType type;
private String name;

@QueryProjection
public SingleSubClassificationResponse(long id, ClassificationType type, String name) {
this.id = id;
this.type = type;
this.name = name;
}

public static SingleSubClassificationResponse ofCreateSubClassification(Classification classification) {

return SingleSubClassificationResponse.builder()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/upbrella/be/store/entity/StoreDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class StoreDetail {
private String addressDetail;
private String content;
@OneToMany(mappedBy = "storeDetail", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<StoreImage> storeImages;
private List<StoreImage> storeImages;


public static StoreDetail createForSave(CreateStoreRequest request, StoreMeta storeMeta) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/upbrella/be/store/entity/StoreMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public static StoreMeta createStoreMetaForUpdate(UpdateStoreRequest request, Cla
public void updateStoreMeta(StoreMeta storeMeta) {

this.name = storeMeta.getName();
this.activated = storeMeta.isActivated();
this.deleted = storeMeta.isDeleted();
this.classification = storeMeta.getClassification();
this.subClassification = storeMeta.getSubClassification();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package upbrella.be.store.repository;

import upbrella.be.store.dto.response.SingleStoreResponse;
import upbrella.be.store.entity.StoreDetail;

import java.util.List;
Expand All @@ -10,4 +11,6 @@ public interface StoreDetailRepositoryCustom {
List<StoreDetail> findAllStores();

Optional<StoreDetail> findByStoreMetaIdUsingFetchJoin(long storeMetaId);

List<SingleStoreResponse> findAllStoresForAdmin();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import upbrella.be.store.dto.response.QSingleClassificationResponse;
import upbrella.be.store.dto.response.QSingleStoreResponse;
import upbrella.be.store.dto.response.QSingleSubClassificationResponse;
import upbrella.be.store.dto.response.SingleStoreResponse;
import upbrella.be.store.entity.StoreDetail;

import java.util.List;
Expand Down Expand Up @@ -41,4 +45,44 @@ public Optional<StoreDetail> findByStoreMetaIdUsingFetchJoin(long storeMetaId) {
.where(storeMeta.deleted.isFalse())
.fetchOne());
}

@Override
public List<SingleStoreResponse> findAllStoresForAdmin() {

return queryFactory
.select(new QSingleStoreResponse(
storeDetail.storeMeta.id,
storeDetail.storeMeta.name,
storeDetail.storeMeta.category,
new QSingleClassificationResponse(
storeDetail.storeMeta.classification.id,
storeDetail.storeMeta.classification.type,
storeDetail.storeMeta.classification.name,
storeDetail.storeMeta.classification.latitude,
storeDetail.storeMeta.classification.longitude
),
new QSingleSubClassificationResponse(
storeDetail.storeMeta.subClassification.id,
storeDetail.storeMeta.subClassification.type,
storeDetail.storeMeta.subClassification.name
),
storeDetail.storeMeta.activated,
storeDetail.address,
storeDetail.addressDetail,
storeDetail.umbrellaLocation,
storeDetail.workingHour,
storeDetail.contactInfo,
storeDetail.instaUrl,
storeDetail.storeMeta.latitude,
storeDetail.storeMeta.longitude,
storeDetail.content,
storeDetail.storeMeta.password
))
.from(storeDetail)
.join(storeDetail.storeMeta, storeMeta)
.join(storeMeta.classification, classification)
.join(storeMeta.subClassification, classification)
.where(storeMeta.deleted.isFalse())
.fetch();
}
}
18 changes: 5 additions & 13 deletions src/main/java/upbrella/be/store/service/StoreDetailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class StoreDetailService {
private final UmbrellaService umbrellaService;
private final StoreDetailRepository storeDetailRepository;
private final BusinessHourService businessHourService;
private final StoreImageService storeImageService;

@Transactional
@CacheEvict(value = "stores", key = "'allStores'")
Expand All @@ -52,7 +51,7 @@ public StoreDetail findStoreDetailByStoreMetaId(Long storeId) {
.orElseThrow(() -> new NonExistingStoreDetailException("[ERROR] 존재하지 않는 가게입니다."));
}

@Transactional
@Transactional(readOnly = true)
public StoreFindByIdResponse findStoreDetailByStoreId(long storeId) {

StoreDetail storeDetail = findStoreDetailByStoreMetaId(storeId);
Expand All @@ -62,22 +61,14 @@ public StoreFindByIdResponse findStoreDetailByStoreId(long storeId) {
return StoreFindByIdResponse.fromStoreDetail(storeDetail, availableUmbrellaCount);
}

@Transactional
@Transactional(readOnly = true)
@Cacheable(value = "stores", key = "'allStores'")
public List<SingleStoreResponse> findAllStores() {

List<StoreDetail> storeDetails = storeDetailRepository.findAllStores();
return storeDetails.stream()
.map(this::createSingleStoreResponse)
.collect(Collectors.toList());
}

private SingleStoreResponse createSingleStoreResponse(StoreDetail storeDetail) {

return SingleStoreResponse.ofCreateSingleStoreResponse(storeDetail);
return storeDetailRepository.findAllStoresForAdmin();
}

@Transactional
@Transactional(readOnly = true)
public AllStoreIntroductionResponse findAllStoreIntroductions() {

List<StoreDetail> storeDetails = storeDetailRepository.findAllStores();
Expand All @@ -100,6 +91,7 @@ public void saveStoreDetail(StoreDetail storeDetail) {
storeDetailRepository.save(storeDetail);
}

@Transactional(readOnly = true)
public StoreDetail findByStoreMetaId(Long storeId) {

return storeDetailRepository.findStoreDetailByStoreMetaId(storeId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public String makeRandomId() {
return UUID.randomUUID().toString().substring(0, 10);
}

@Transactional(readOnly = true)
public AllImageUrlResponse findAllImages(long storeId) {

StoreDetail storeDetail = storeDetailService.findByStoreMetaId(storeId);
Expand Down
Loading

0 comments on commit f4f59cf

Please sign in to comment.