Skip to content

Commit

Permalink
Merge pull request #103 from MEME-UMC/add/#102
Browse files Browse the repository at this point in the history
[Add ] BaseEntity 추가 / 예약 중복 예외 처리
  • Loading branch information
daeun084 authored Feb 5, 2024
2 parents 22aff71 + 933cb03 commit daca9fc
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public ApiResponse getArtistProfile(@PathVariable Long artistId){
}

//temp method for Artist create
@Operation(summary = "temp 아티스트 생성(프론트랑 상관X)")
@PostMapping("/artist")
public ApiResponse createArtist(@RequestBody ArtistProfileDto profileDto){
artistService.createArtist(profileDto);
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/umc/meme/shop/domain/common/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package umc.meme.shop.domain.common;

import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import lombok.experimental.SuperBuilder;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@Getter
public abstract class BaseEntity {

@CreatedDate
private LocalDateTime createdAt;

@LastModifiedDate
private LocalDateTime updatedAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.common.BaseEntity;
import umc.meme.shop.domain.model.entity.Model;

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class FavoriteArtist {
public class FavoriteArtist extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package umc.meme.shop.domain.favorite.entity;

import com.fasterxml.jackson.databind.ser.Serializers;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.common.BaseEntity;
import umc.meme.shop.domain.portfolio.entity.Portfolio;
import umc.meme.shop.domain.user.User;

Expand All @@ -13,7 +15,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class FavoritePortfolio {
public class FavoritePortfolio extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ModelController {
private final ModelService modelService;

/**temp model create method**/
@Operation(summary = "temp 모델 생성(프론트랑 상관X)")
@PostMapping("/model")
public ApiResponse createModel(@RequestBody ModelProfileDto profileDto){
modelService.createModel(profileDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.common.BaseEntity;
import umc.meme.shop.domain.mypage.dto.request.MypageInquiryDto;
import umc.meme.shop.domain.user.User;
import umc.meme.shop.domain.user.UserRepository;
Expand All @@ -14,7 +15,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Inquiry {
public class Inquiry extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "inquiry_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.artist.entity.Artist;
import umc.meme.shop.domain.common.BaseEntity;
import umc.meme.shop.domain.portfolio.dto.request.UpdatePortfolioDto;
import umc.meme.shop.global.enums.Category;
import umc.meme.shop.domain.review.entity.Review;
Expand All @@ -18,7 +19,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Portfolio {
public class Portfolio extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "portfolio_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import umc.meme.shop.domain.common.BaseEntity;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class PortfolioImg {
@Getter @Setter
public class PortfolioImg extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long portfolioImgId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.common.BaseEntity;
import umc.meme.shop.domain.portfolio.entity.Portfolio;
import umc.meme.shop.global.enums.Status;
import umc.meme.shop.domain.user.User;
Expand All @@ -19,7 +20,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Reservation {
public class Reservation extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.repository.query.Param;
import umc.meme.shop.domain.artist.entity.Artist;
import umc.meme.shop.domain.model.entity.Model;
import umc.meme.shop.domain.portfolio.entity.Portfolio;
import umc.meme.shop.domain.reservation.entity.Reservation;

import java.util.List;
Expand All @@ -21,6 +22,7 @@ public interface ReservationRepository extends JpaRepository<Reservation, Long>
@Query("SELECT r FROM Reservation r JOIN r.model m WHERE r.reservationId = :reservationId AND m.userId = :modelId")
Optional<Reservation> findByReservationIdAndModelId(@Param("reservationId") Long reservationId, @Param("modelId") Long modelId);

List<Reservation> findByModelAndPortfolio(Model model, Portfolio portfolio);
}


Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ public ReservationCompleteDto createReservation(ReservationRequestDto reservatio
throw new GlobalException(ErrorStatus.NOT_ALLOW_OVER_ONE_RESERVATION);
}

//예약 중복 처리
List<Reservation> reservationList = reservationRepository.findByModelAndPortfolio(model, portfolio);
for(int i=0; i<reservationList.size(); i++){
if(reservationList.get(i).getReservationDayOfWeekAndTime().equals(reservationDto.getReservationDayOfWeekAndTime())){
throw new GlobalException(ErrorStatus.NOT_ALLOW_DUPLICATED_RESERVATION);
}
}

Reservation reservation = Reservation.builder()
.model(model)
.portfolio(portfolio)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/umc/meme/shop/domain/review/entity/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.meme.shop.domain.common.BaseEntity;
import umc.meme.shop.domain.portfolio.entity.Portfolio;
import umc.meme.shop.domain.user.User;

Expand All @@ -15,7 +16,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Review {
public class Review extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long reviewId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import umc.meme.shop.domain.common.BaseEntity;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class ReviewImg {
@Getter @Setter
public class ReviewImg extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long reviewImgId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public void createReview(ReviewDto reviewDto){
for (ReviewImg reviewImg : reviewImgList) {
reviewImg.setReview(review);
review.getReviewImgList().add(reviewImg);

}

portfolio.updateReviewList(review);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/umc/meme/shop/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import umc.meme.shop.domain.common.BaseEntity;
import umc.meme.shop.global.enums.Gender;
import umc.meme.shop.domain.mypage.entity.Inquiry;

import java.time.LocalDateTime;
import java.util.List;
import umc.meme.shop.global.enums.Provider;

Expand Down Expand Up @@ -39,6 +43,12 @@ public class User {
@Column(nullable = false, length = 40)
protected String email;

@CreatedDate
private LocalDateTime createdAt;

@LastModifiedDate
private LocalDateTime updatedAt;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
protected List<Inquiry> inquiryList;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/umc/meme/shop/global/ErrorStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public enum ErrorStatus {
//reservation
ALREADY_CHANGE_STATUS(400, "이미 예약 상태가 변경되었습니다."),
INVALID_CHANGE_STATUS(400, "이미 완료된 예약은 취소할 수 없습니다."),
NOT_ALLOW_DUPLICATED_RESERVATION(400, "중복된 예약 시간입니다."),

NOT_ALLOW_OVER_ONE_RESERVATION(400,"한 번에 하나의 예약만 가능합니다." ),
INVALID_CHANGE_COMPLETE(400,"취소된 예약을 완료 상태로 변경할 수 없습니다." ),
Expand Down

0 comments on commit daca9fc

Please sign in to comment.