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

v0.4.0 dev pre-release #324

Merged
merged 3 commits into from
Oct 7, 2023
Merged
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
21 changes: 20 additions & 1 deletion src/docs/asciidoc/api/admin/store.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,23 @@ include::{snippets}/store-update-activate-status-doc/path-parameters.adoc[]

=== 협업지점 비활성화
include::{snippets}/store-update-inactivate-status-doc/http-request.adoc[]
include::{snippets}/store-update-inactivate-status-doc/path-parameters.adoc[]
include::{snippets}/store-update-inactivate-status-doc/path-parameters.adoc[]

=== 협업지점 이미지 조회
==== HTTP Request
include::{snippets}/store-find-all-images-doc/http-request.adoc[]
include::{snippets}/store-find-all-images-doc/path-parameters.adoc[]

==== HTTP Response
include::{snippets}/store-find-all-images-doc/http-response.adoc[]
include::{snippets}/store-find-all-images-doc/response-fields-data.adoc[]


=== 협업지점 영업시간 조회
==== HTTP Request
include::{snippets}/store-find-all-business-hours-doc/path-parameters.adoc[]
include::{snippets}/store-find-all-business-hours-doc/http-request.adoc[]

==== HTTP Response
include::{snippets}/store-find-all-business-hours-doc/http-response.adoc[]
include::{snippets}/store-find-all-business-hours-doc/response-fields-data.adoc[]
8 changes: 6 additions & 2 deletions src/main/java/upbrella/be/rent/controller/RentController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package upbrella.be.rent.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -18,7 +19,9 @@
import upbrella.be.util.CustomResponse;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

@Slf4j
@RestController
@RequiredArgsConstructor
public class RentController {
Expand Down Expand Up @@ -63,13 +66,14 @@ public ResponseEntity<CustomResponse<ReturnFormResponse>> findReturnForm(@PathVa
}

@PostMapping("/rent")
public ResponseEntity<CustomResponse> rentUmbrellaByUser(@RequestBody RentUmbrellaByUserRequest rentUmbrellaByUserRequest, HttpSession httpSession) {
public ResponseEntity<CustomResponse> rentUmbrellaByUser(@RequestBody @Valid RentUmbrellaByUserRequest rentUmbrellaByUserRequest, HttpSession httpSession) {

SessionUser user = (SessionUser) httpSession.getAttribute("user");
User userToRent = userService.findUserById(user.getId());

rentService.addRental(rentUmbrellaByUserRequest, userToRent);

log.info("UBU 우산 대여 성공");
return ResponseEntity
.ok()
.body(new CustomResponse(
Expand All @@ -80,7 +84,7 @@ public ResponseEntity<CustomResponse> rentUmbrellaByUser(@RequestBody RentUmbrel
}

@PatchMapping("/rent")
public ResponseEntity<CustomResponse> returnUmbrellaByUser(@RequestBody ReturnUmbrellaByUserRequest returnUmbrellaByUserRequest, HttpSession httpSession) {
public ResponseEntity<CustomResponse> returnUmbrellaByUser(@RequestBody @Valid ReturnUmbrellaByUserRequest returnUmbrellaByUserRequest, HttpSession httpSession) {

SessionUser user = (SessionUser) httpSession.getAttribute("user");
User userToReturn = userService.findUserById(user.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import lombok.*;

import javax.validation.constraints.Size;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -11,5 +13,7 @@ public class RentUmbrellaByUserRequest {
private String region;
private long storeId;
private long umbrellaId;

@Size(max = 400, message = "conditionReport는 최대 400자여야 합니다.")
private String conditionReport;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import lombok.*;

import javax.validation.constraints.Size;

@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -11,5 +13,7 @@ public class ReturnUmbrellaByUserRequest {
private long returnStoreId;
private String bank;
private String accountNumber;

@Size(max = 400, message = "최대 400자여야 합니다.")
private String improvementReportContent;
}
36 changes: 28 additions & 8 deletions src/main/java/upbrella/be/store/controller/StoreController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import upbrella.be.store.dto.request.CreateClassificationRequest;
import upbrella.be.store.dto.request.CreateStoreRequest;
import upbrella.be.store.dto.request.CreateSubClassificationRequest;
import upbrella.be.store.dto.request.UpdateStoreRequest;
import upbrella.be.store.dto.request.*;
import upbrella.be.store.dto.response.*;
import upbrella.be.store.service.ClassificationService;
import upbrella.be.store.service.StoreDetailService;
import upbrella.be.store.service.StoreImageService;
import upbrella.be.store.service.StoreMetaService;
import upbrella.be.store.service.*;
import upbrella.be.util.CustomResponse;

import java.time.LocalDateTime;
Expand All @@ -26,6 +20,7 @@ public class StoreController {
private final StoreMetaService storeMetaService;
private final ClassificationService classificationService;
private final StoreDetailService storeDetailService;
private final BusinessHourService businessHourService;

@GetMapping("/stores/{storeId}")
public ResponseEntity<CustomResponse<StoreFindByIdResponse>> findStoreById(@PathVariable long storeId) {
Expand Down Expand Up @@ -109,6 +104,19 @@ public ResponseEntity<CustomResponse> updateStore(@PathVariable long storeId, @R
));
}

@GetMapping("/admin/stores/{storeId}/images")
public ResponseEntity<CustomResponse<AllImageUrlResponse>> findAllImages(@PathVariable Long storeId) {

return ResponseEntity
.ok()
.body(new CustomResponse<>(
"success",
200,
"협업지점 이미지 전체 조회 성공",
storeImageService.findAllImages(storeId)
));
}

@PostMapping(value = "/admin/stores/{storeId}/images", consumes = {"multipart/form-data"})
public ResponseEntity<CustomResponse> uploadStoreImage(@RequestPart MultipartFile image, @PathVariable long storeId) {

Expand Down Expand Up @@ -274,4 +282,16 @@ public ResponseEntity<CustomResponse> inActivateStoreStatus(@PathVariable long s
"협업지점 비활성화 성공"
));
}

@GetMapping("/admin/stores/{storeId}/businessHours")
public ResponseEntity<CustomResponse<AllBusinessHourResponse>> findAllBusinessHours(@PathVariable long storeId) {

return ResponseEntity
.ok()
.body(new CustomResponse<>(
"success",
200,
"협업지점 영업시간 전체 조회 성공",
businessHourService.findAllBusinessHours(storeId)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,15 @@ public ResponseEntity<CustomErrorResponse> essentialImage(EssentialImageExceptio
400,
ex.getMessage()));
}

@ExceptionHandler(NotExistBusinessHourException.class)
public ResponseEntity<CustomErrorResponse> notExistBusinessHour(NotExistBusinessHourException ex) {

return ResponseEntity
.badRequest()
.body(new CustomErrorResponse(
"not found",
404,
ex.getMessage()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package upbrella.be.store.dto.response;

import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Getter
@Builder
public class AllImageUrlResponse {

private Long storeId;
private List<SingleImageUrlResponse> images;

public static AllImageUrlResponse of(Long storeId, List<SingleImageUrlResponse> images) {
return AllImageUrlResponse.builder()
.storeId(storeId)
.images(images)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@AllArgsConstructor
public class SingleBusinessHourResponse {

private long id;
private DayOfWeek date;
@JsonSerialize(using = LocalTimeSerializer.class)
@JsonDeserialize(using = LocalTimeDeserializer.class)
Expand All @@ -33,6 +34,7 @@ public class SingleBusinessHourResponse {
public static SingleBusinessHourResponse createSingleHourResponse(BusinessHour businessHour) {

return SingleBusinessHourResponse.builder()
.id(businessHour.getId())
.date(businessHour.getDate())
.openAt(businessHour.getOpenAt())
.closeAt(businessHour.getCloseAt())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package upbrella.be.store.dto.response;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;
import upbrella.be.store.entity.StoreDetail;

Expand All @@ -20,19 +21,16 @@ public class SingleStoreResponse implements Serializable {
private boolean activateStatus;
private String address;
private String addressDetail;
private String thumbnail;
private String umbrellaLocation;
private String businessHour;
private String contactNumber;
private String instagramId;
private double latitude;
private double longitude;
private String content;
private List<SingleImageUrlResponse> imageUrls;
private String password;
private List<SingleBusinessHourResponse> businessHours;

public static SingleStoreResponse ofCreateSingleStoreResponse(StoreDetail storeDetail, String thumbnail, List<SingleImageUrlResponse> images, List<SingleBusinessHourResponse> businessHours) {
public static SingleStoreResponse ofCreateSingleStoreResponse(StoreDetail storeDetail) {

return SingleStoreResponse.builder()
.id(storeDetail.getStoreMeta().getId())
Expand All @@ -51,9 +49,6 @@ public static SingleStoreResponse ofCreateSingleStoreResponse(StoreDetail storeD
.longitude(storeDetail.getStoreMeta().getLongitude())
.content(storeDetail.getContent())
.password(storeDetail.getStoreMeta().getPassword())
.imageUrls(images)
.thumbnail(thumbnail)
.businessHours(businessHours)
.build();
}
}
1 change: 0 additions & 1 deletion src/main/java/upbrella/be/store/entity/BusinessHour.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static BusinessHour ofCreateBusinessHour(SingleBusinessHourRequest busine

public void updateBusinessHour(SingleBusinessHourRequest businessHour) {

this.date = businessHour.getDate();
this.openAt = businessHour.getOpenAt();
this.closeAt = businessHour.getCloseAt();
}
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/upbrella/be/store/entity/StoreMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


@Entity
Expand All @@ -34,8 +32,8 @@ public class StoreMeta {
private double latitude;
private double longitude;
private String password;
@OneToMany(mappedBy = "storeMeta", cascade = CascadeType.ALL)
private Set<BusinessHour> businessHours;
@OneToMany(mappedBy = "storeMeta")
private List<BusinessHour> businessHours;

public static StoreMeta createStoreMetaForSave(CreateStoreRequest request, Classification classification, Classification subClassification) {

Expand All @@ -52,7 +50,7 @@ public static StoreMeta createStoreMetaForSave(CreateStoreRequest request, Class
.build();
}

public static StoreMeta createStoreMetaForUpdate(UpdateStoreRequest request, Classification classification, Classification subClassification, List<BusinessHour> businessHours) {
public static StoreMeta createStoreMetaForUpdate(UpdateStoreRequest request, Classification classification, Classification subClassification) {

return StoreMeta.builder()
.name(request.getName())
Expand All @@ -63,7 +61,6 @@ public static StoreMeta createStoreMetaForUpdate(UpdateStoreRequest request, Cla
.latitude(request.getLatitude())
.longitude(request.getLongitude())
.password(request.getPassword())
.businessHours(new HashSet<>(businessHours))
.build();
}

Expand All @@ -78,7 +75,6 @@ public void updateStoreMeta(StoreMeta storeMeta) {
this.latitude = storeMeta.getLatitude();
this.longitude = storeMeta.getLongitude();
this.password = storeMeta.getPassword();
this.businessHours = storeMeta.getBusinessHours();
}

public void delete() {
Expand All @@ -88,7 +84,7 @@ public void delete() {

public boolean isOpenStore(LocalDateTime currentTime) {

Set<BusinessHour> businessHours = this.getBusinessHours();
List<BusinessHour> businessHours = this.getBusinessHours();

return businessHours.stream()
.filter(businessHour -> businessHour.getDate().equals(currentTime.getDayOfWeek()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package upbrella.be.store.exception;

public class NotExistBusinessHourException extends RuntimeException{

public NotExistBusinessHourException(String message) {

super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
public interface BusinessHourRepository extends JpaRepository<BusinessHour, Long> {

List<BusinessHour> findByStoreMetaId(Long storeMetaId);

void deleteAllByStoreMetaId(Long storeMetaId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import org.springframework.data.jpa.repository.JpaRepository;
import upbrella.be.store.entity.StoreDetail;

import java.util.Optional;


public interface StoreDetailRepository extends JpaRepository<StoreDetail, Long>, StoreDetailRepositoryCustom {

Optional<StoreDetail> findStoreDetailByStoreMetaId(long storeMetaId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.List;
import java.util.Optional;

import static upbrella.be.store.entity.QBusinessHour.businessHour;
import static upbrella.be.store.entity.QClassification.classification;
import static upbrella.be.store.entity.QStoreDetail.storeDetail;
import static upbrella.be.store.entity.QStoreImage.storeImage;
Expand All @@ -26,8 +25,6 @@ public List<StoreDetail> findAllStores() {
.join(storeDetail.storeMeta, storeMeta).fetchJoin()
.join(storeMeta.classification, classification).fetchJoin()
.join(storeMeta.subClassification, classification).fetchJoin()
.leftJoin(storeMeta.businessHours, businessHour).fetchJoin()
.leftJoin(storeDetail.storeImages, storeImage).fetchJoin()
.where(storeMeta.deleted.isFalse())
.distinct()
.fetch();
Expand Down
Loading