diff --git a/build.gradle b/build.gradle index 32c410e..d0b3c6f 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,6 @@ buildscript { } } - plugins { id 'java' id 'org.springframework.boot' version '2.7.13' diff --git a/snapspot-api/src/main/java/snap/ApiApplication.java b/snapspot-api/src/main/java/snap/ApiApplication.java index 4cf18b9..28d74a4 100644 --- a/snapspot-api/src/main/java/snap/ApiApplication.java +++ b/snapspot-api/src/main/java/snap/ApiApplication.java @@ -3,11 +3,13 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import javax.annotation.PostConstruct; import java.util.TimeZone; +@EnableJpaAuditing @EntityScan(basePackages = {"snap"}) @EnableJpaRepositories(basePackages = {"snap"}) @SpringBootApplication diff --git a/snapspot-api/src/main/java/snap/api/message/dto/MessageResponseDto.java b/snapspot-api/src/main/java/snap/api/message/dto/MessageResponseDto.java index 409c65e..07ab225 100644 --- a/snapspot-api/src/main/java/snap/api/message/dto/MessageResponseDto.java +++ b/snapspot-api/src/main/java/snap/api/message/dto/MessageResponseDto.java @@ -9,6 +9,8 @@ import snap.domains.message.entity.Sender; import snap.enums.Role; +import java.time.LocalDateTime; + @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class MessageResponseDto { @@ -16,6 +18,7 @@ public class MessageResponseDto { private Boolean isMine; private Sender sender; private String contents; + private LocalDateTime createdAt; public MessageResponseDto(Message message, Member member) { Sender sender = Sender.MEMBER; @@ -27,5 +30,6 @@ public MessageResponseDto(Message message, Member member) { this.contents = message.getContents(); this.sender = message.getSender(); this.isMine = sender.equals(message.getSender()); + this.createdAt = message.getCreatedAt(); } } diff --git a/snapspot-api/src/main/java/snap/api/message/service/MessageService.java b/snapspot-api/src/main/java/snap/api/message/service/MessageService.java index fdde756..b34ef2f 100644 --- a/snapspot-api/src/main/java/snap/api/message/service/MessageService.java +++ b/snapspot-api/src/main/java/snap/api/message/service/MessageService.java @@ -30,7 +30,6 @@ public Message createMessage(Member member, MessageRequestDto request) { } Plan plan = planDomainService.findByPlanId(request.getPlanId()); - if (!plan.getCustomer().getMemberId().equals(member.getMemberId())) { if (!plan.getPhotographer().getMember().getMemberId().equals(member.getMemberId())) { @@ -38,8 +37,6 @@ public Message createMessage(Member member, MessageRequestDto request) { } } - - return messageDomainService.createMessage( plan, request.getContents(), diff --git a/snapspot-api/src/main/java/snap/api/plan/dto/response/PlanFullResponseDto.java b/snapspot-api/src/main/java/snap/api/plan/dto/response/PlanFullResponseDto.java index d188fe8..3c46c1c 100644 --- a/snapspot-api/src/main/java/snap/api/plan/dto/response/PlanFullResponseDto.java +++ b/snapspot-api/src/main/java/snap/api/plan/dto/response/PlanFullResponseDto.java @@ -38,6 +38,8 @@ public class PlanFullResponseDto { private String y; private Status status; private List messages; + private LocalDateTime createdAt; + private LocalDateTime modifiedAt; @Builder public PlanFullResponseDto(Plan plan, Member member, List messageList) { @@ -59,5 +61,7 @@ public PlanFullResponseDto(Plan plan, Member member, List messageList) this.messages = messageList.stream() .map(message -> new MessageResponseDto(message, member)) .collect(Collectors.toList()); + this.createdAt = plan.getCreatedAt(); + this.modifiedAt = plan.getModifiedAt(); } } diff --git a/snapspot-api/src/main/java/snap/api/plan/dto/response/PlanResponseDto.java b/snapspot-api/src/main/java/snap/api/plan/dto/response/PlanResponseDto.java index 2a5d9ab..ab06b09 100644 --- a/snapspot-api/src/main/java/snap/api/plan/dto/response/PlanResponseDto.java +++ b/snapspot-api/src/main/java/snap/api/plan/dto/response/PlanResponseDto.java @@ -33,6 +33,8 @@ public class PlanResponseDto { private Long price; private String request; private Status status; + private LocalDateTime createdAt; + private LocalDateTime modifiedAt; @Builder public PlanResponseDto(Plan plan) { @@ -47,5 +49,7 @@ public PlanResponseDto(Plan plan) { this.wishPlace = plan.getWishPlace(); this.request = plan.getRequest(); this.status = plan.getStatus(); + this.createdAt = plan.getCreatedAt(); + this.modifiedAt = plan.getModifiedAt(); } } diff --git a/snapspot-api/src/main/java/snap/api/plan/service/PlanService.java b/snapspot-api/src/main/java/snap/api/plan/service/PlanService.java index bdb0b7a..3d50404 100644 --- a/snapspot-api/src/main/java/snap/api/plan/service/PlanService.java +++ b/snapspot-api/src/main/java/snap/api/plan/service/PlanService.java @@ -28,6 +28,7 @@ import java.util.UUID; import java.util.stream.Collectors; +@Slf4j @Service @RequiredArgsConstructor public class PlanService { @@ -46,6 +47,7 @@ public PlanResponseDto createRequest(Member member, PlanRequestDto requestDto) { public PlanFullResponseDto createDeposit(Member member, DepositRequestDto requestDto) throws ParseException { JSONObject coordinate = kakaoClient.getCoordinateFromAddress(requestDto.getPlaceAddress()); + log.info((String) coordinate.get("x"), (String) coordinate.get("y")); Plan plan = planDomainService.createDeposit(requestDto.toEntity(), (String) coordinate.get("x"), (String) coordinate.get("y")); return new PlanFullResponseDto(plan, member, messageDomainService.findByPlanId(plan.getPlanId())); } diff --git a/snapspot-api/src/main/java/snap/api/review/service/ReviewService.java b/snapspot-api/src/main/java/snap/api/review/service/ReviewService.java index a6b04b3..d804514 100644 --- a/snapspot-api/src/main/java/snap/api/review/service/ReviewService.java +++ b/snapspot-api/src/main/java/snap/api/review/service/ReviewService.java @@ -45,6 +45,7 @@ public List findReviewListByMember(Member member) { return reviewList.stream().map(ReviewResponseDto::new).collect(Collectors.toList()); } + @Transactional(readOnly = true) public List findReviewListByPhotographer(Photographer photographer) { return reviewDomainService.findReviewListByPhotographer(photographer) .stream().map(ReviewResponseDto::new).collect(Collectors.toList()); diff --git a/snapspot-domain/src/main/java/snap/domains/global/entity/BaseTimeEntity.java b/snapspot-domain/src/main/java/snap/domains/global/entity/BaseTimeEntity.java new file mode 100644 index 0000000..97ef6ee --- /dev/null +++ b/snapspot-domain/src/main/java/snap/domains/global/entity/BaseTimeEntity.java @@ -0,0 +1,22 @@ +package snap.domains.global.entity; + +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.time.LocalDateTime; + +@Getter +@MappedSuperclass +@EntityListeners(AuditingEntityListener.class) +public class BaseTimeEntity { + @CreatedDate + @Column(updatable = false, columnDefinition = "TIMESTAMP") + private LocalDateTime createdAt; + + @LastModifiedDate + @Column(columnDefinition = "TIMESTAMP") + private LocalDateTime modifiedAt; +} diff --git a/snapspot-domain/src/main/java/snap/domains/message/entity/Message.java b/snapspot-domain/src/main/java/snap/domains/message/entity/Message.java index ce9379b..5394b3a 100644 --- a/snapspot-domain/src/main/java/snap/domains/message/entity/Message.java +++ b/snapspot-domain/src/main/java/snap/domains/message/entity/Message.java @@ -4,14 +4,16 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import snap.domains.global.entity.BaseTimeEntity; import snap.domains.plan.entity.Plan; import javax.persistence.*; +import java.time.LocalDateTime; @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Message { +public class Message extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long messageId; diff --git a/snapspot-domain/src/main/java/snap/domains/plan/entity/Plan.java b/snapspot-domain/src/main/java/snap/domains/plan/entity/Plan.java index 1352164..6815cfe 100644 --- a/snapspot-domain/src/main/java/snap/domains/plan/entity/Plan.java +++ b/snapspot-domain/src/main/java/snap/domains/plan/entity/Plan.java @@ -7,6 +7,7 @@ import lombok.NoArgsConstructor; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Type; +import snap.domains.global.entity.BaseTimeEntity; import snap.domains.member.entity.Member; import snap.domains.photographer.entity.Photographer; import snap.domains.review.entity.Review; @@ -21,7 +22,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Plan { +public class Plan extends BaseTimeEntity { @Id @GeneratedValue(generator = "uuid2") @GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator") diff --git a/snapspot-domain/src/main/java/snap/domains/plan/repository/PlanJPARepository.java b/snapspot-domain/src/main/java/snap/domains/plan/repository/PlanJPARepository.java index 02c5229..de30bf5 100644 --- a/snapspot-domain/src/main/java/snap/domains/plan/repository/PlanJPARepository.java +++ b/snapspot-domain/src/main/java/snap/domains/plan/repository/PlanJPARepository.java @@ -12,15 +12,14 @@ public interface PlanJPARepository extends JpaRepository { - List findAllByCustomer(Member member); - List findAllByPhotographer(Photographer photographer); + List findAllByCustomerOrderByCreatedAtDesc(Member member); + List findAllByPhotographerOrderByCreatedAtDesc(Photographer photographer); List findAllByPhotographerAndStatus(Photographer photographer, Status status1); - List findAllByPhotographerAndStatusOrStatus(Photographer photographer, Status status1, Status status2); + List findAllByPhotographerAndStatusOrStatusOrderByCreatedAtDesc(Photographer photographer, Status status1, Status status2); + List findAllByPhotographerAndStatusOrStatusOrStatusOrderByCreatedAtDesc(Photographer photographer, Status status1, Status status2, Status status3); - List findAllByPhotographerAndStatusOrStatusOrStatus(Photographer photographer, Status status1, Status status2, Status status3); - Optional findByPlanIdAndCustomer(UUID planId, Member member); } diff --git a/snapspot-domain/src/main/java/snap/domains/plan/repository/PlanQueryDslRepository.java b/snapspot-domain/src/main/java/snap/domains/plan/repository/PlanQueryDslRepository.java index 8b120f7..df11b29 100644 --- a/snapspot-domain/src/main/java/snap/domains/plan/repository/PlanQueryDslRepository.java +++ b/snapspot-domain/src/main/java/snap/domains/plan/repository/PlanQueryDslRepository.java @@ -21,7 +21,6 @@ public class PlanQueryDslRepository { private final EntityManager em; private final JPAQueryFactory queryFactory; - public void changePlanStatusOfToday() { LocalDateTime now = LocalDateTime.now(); now = LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), 0, 0, 0); diff --git a/snapspot-domain/src/main/java/snap/domains/plan/service/PlanDomainService.java b/snapspot-domain/src/main/java/snap/domains/plan/service/PlanDomainService.java index 1cbac17..f8046a0 100644 --- a/snapspot-domain/src/main/java/snap/domains/plan/service/PlanDomainService.java +++ b/snapspot-domain/src/main/java/snap/domains/plan/service/PlanDomainService.java @@ -78,12 +78,12 @@ public Plan updateState(Plan plan, Status status) { @Transactional(readOnly = true) public List findByPhotographer(Photographer photographer) { - return planRepository.findAllByPhotographer(photographer); + return planRepository.findAllByPhotographerOrderByCreatedAtDesc(photographer); } @Transactional(readOnly = true) public List findByMember(Member member) { - return planRepository.findAllByCustomer(member); + return planRepository.findAllByCustomerOrderByCreatedAtDesc(member); } public Plan findByPlanIdAndMember(UUID planId, Member member) { @@ -100,12 +100,12 @@ public void updateStateOfComplete() { @Transactional(readOnly = true) public List findByPhotographerAndStatus1(Photographer photographer, Status status, Status status1) { - return planRepository.findAllByPhotographerAndStatusOrStatus(photographer, status, status1); + return planRepository.findAllByPhotographerAndStatusOrStatusOrderByCreatedAtDesc(photographer, status, status1); } @Transactional(readOnly = true) public List findByPhotographerAndStatus(Photographer photographer, Status status, Status status1, Status status2) { - return planRepository.findAllByPhotographerAndStatusOrStatusOrStatus(photographer,status,status1,status2); + return planRepository.findAllByPhotographerAndStatusOrStatusOrStatusOrderByCreatedAtDesc(photographer,status,status1,status2); } public void changePlan(