From 406bc86d238ab2a54dc09b59fa2768cc8adc4cae Mon Sep 17 00:00:00 2001 From: j-yong99 Date: Wed, 8 May 2024 15:40:33 +0900 Subject: [PATCH 1/2] =?UTF-8?q?:recycle:=20DB=20=EB=8B=A4=EB=8C=80?= =?UTF-8?q?=EC=9D=BC=20fetchType=20LAZY=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?=EB=B0=8F=20=EC=98=81=EC=88=98=EC=A6=9D=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EB=B0=8F=20=EC=97=AC=ED=96=89=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=97=90=20=EC=B9=B4=EB=93=9C=EB=B7=B0=20=EA=B0=9C?= =?UTF-8?q?=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/controller/ReceiptController.java | 12 ++++ .../alreadyBookedDate/AlreadyBookedDate.java | 2 +- .../moment/core/domain/cardView/CardView.java | 2 +- .../domain/cardView/CardViewRepository.java | 8 +++ .../core/domain/imageFile/ImageFile.java | 2 +- .../moment/core/domain/receipt/Receipt.java | 2 +- .../domain/receipt/ReceiptRepository.java | 1 + .../com/moment/core/domain/trip/Trip.java | 2 +- .../core/domain/trip/TripRepository.java | 4 ++ .../moment/core/domain/tripFile/TripFile.java | 4 +- .../core/dto/request/ReceiptRequestDTO.java | 26 ++++++++ .../core/dto/response/TripResponseDTO.java | 5 +- .../moment/core/service/CardViewService.java | 32 ++++++---- .../moment/core/service/ImageFileService.java | 3 +- .../moment/core/service/ReceiptService.java | 32 ++++++++-- .../com/moment/core/service/TripService.java | 25 +++++++- .../controller/ReceiptControllerTest.java | 59 ++++++++++++++++++- 17 files changed, 187 insertions(+), 34 deletions(-) diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/controller/ReceiptController.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/controller/ReceiptController.java index 05e852e4e1..5025385ab6 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/controller/ReceiptController.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/controller/ReceiptController.java @@ -47,6 +47,7 @@ public ResponseEntity deleteReceipts( @RequestHeader Long userId, @RequestBody ReceiptRequestDTO.deleteReceipts deleteReceipts ) { + receiptService.deleteReceipts(userId, deleteReceipts); return ResponseEntity.ok(APIResponse.of(SuccessCode.DELETE_SUCCESS)); } @@ -60,4 +61,15 @@ public ResponseEntity createReceipt( receiptService.createReceipt(userId, createReceipt); return ResponseEntity.ok(APIResponse.of(SuccessCode.INSERT_SUCCESS)); } + + // 영수증 수정 + @PutMapping() + public ResponseEntity updateReceipt( + @RequestHeader Long userId, + @RequestBody ReceiptRequestDTO.updateReceipt updateReceipt + ) { + receiptService.validateUserWithReceipt(userId, updateReceipt.getId()); + receiptService.updateReceipt(userId, updateReceipt); + return ResponseEntity.ok(APIResponse.of(SuccessCode.UPDATE_SUCCESS)); + } } diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/alreadyBookedDate/AlreadyBookedDate.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/alreadyBookedDate/AlreadyBookedDate.java index 1e4feacadf..5beba9fe64 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/alreadyBookedDate/AlreadyBookedDate.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/alreadyBookedDate/AlreadyBookedDate.java @@ -23,7 +23,7 @@ public class AlreadyBookedDate extends BaseEntity { private Long id; // 유저 - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id", nullable = false) private User user; diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/cardView/CardView.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/cardView/CardView.java index e023810718..6b21072480 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/cardView/CardView.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/cardView/CardView.java @@ -22,7 +22,7 @@ public class CardView extends BaseEntity { private Long id; // tripfile_id - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "trip_file_id", nullable = false) private TripFile tripFile; diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/cardView/CardViewRepository.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/cardView/CardViewRepository.java index 57493e6dc5..194dba0e00 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/cardView/CardViewRepository.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/cardView/CardViewRepository.java @@ -1,9 +1,11 @@ package com.moment.core.domain.cardView; import com.moment.core.domain.tripFile.TripFile; +import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; +import java.util.Optional; public interface CardViewRepository extends JpaRepository { List findAllByTripFile_IdOrderByRecordedAt(Long tripFileId); @@ -15,4 +17,10 @@ public interface CardViewRepository extends JpaRepository { List findByTripFile_User_IdAndIsLovedOrderByRecordedAt(Long userId, Boolean isLoved); List findAllByTripFile(TripFile tripFile); + + Long countByTripFile_Trip_Id(Long tripId); + + @Override + @EntityGraph(attributePaths = {"tripFile"}) + Optional findById(Long id); } \ No newline at end of file diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/imageFile/ImageFile.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/imageFile/ImageFile.java index e8b2326d97..d063893bfa 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/imageFile/ImageFile.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/imageFile/ImageFile.java @@ -19,7 +19,7 @@ public class ImageFile { private Long id; // cardview 아이디 - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "card_view_id", nullable = false) private CardView cardView; diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/receipt/Receipt.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/receipt/Receipt.java index 95f55dff1e..d9f6216c71 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/receipt/Receipt.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/receipt/Receipt.java @@ -22,7 +22,7 @@ public class Receipt extends BaseEntity { @Column(name = "id") private Long id; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "trip_id", nullable = true) private Trip trip; diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/receipt/ReceiptRepository.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/receipt/ReceiptRepository.java index 39a78757eb..b073a3b281 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/receipt/ReceiptRepository.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/receipt/ReceiptRepository.java @@ -20,4 +20,5 @@ public interface ReceiptRepository extends PagingAndSortingRepository receipts); // void save(Receipt receipt); + Long countByTrip_User_Id(Long userId); } diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/trip/Trip.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/trip/Trip.java index 5ee721a241..52bdfd0b0b 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/trip/Trip.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/trip/Trip.java @@ -23,7 +23,7 @@ public class Trip extends BaseEntity { private Long id; // 유저 - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id", nullable = false) private User user; diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/trip/TripRepository.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/trip/TripRepository.java index 7534d91b79..d85b6a5481 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/trip/TripRepository.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/trip/TripRepository.java @@ -2,6 +2,7 @@ import com.moment.core.domain.user.User; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import java.util.List; import java.util.Optional; @@ -11,4 +12,7 @@ public interface TripRepository extends JpaRepository { Optional findByUser_IdAndIsNotTitledOrderByStartDate(Long userId, boolean b); List findAllByUserAndIsNotTitledOrderByStartDate(User user, boolean b); + + + } \ No newline at end of file diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/tripFile/TripFile.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/tripFile/TripFile.java index 303f3c35a0..77afa901d0 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/tripFile/TripFile.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/domain/tripFile/TripFile.java @@ -28,12 +28,12 @@ public class TripFile extends BaseEntity { private Long id; // 여행 아이디 - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "trip_id", nullable = false) private Trip trip; // 유저 - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id", nullable = false) private User user; diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/dto/request/ReceiptRequestDTO.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/dto/request/ReceiptRequestDTO.java index 96a8fc3b99..46fb34266b 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/dto/request/ReceiptRequestDTO.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/dto/request/ReceiptRequestDTO.java @@ -4,6 +4,7 @@ import lombok.*; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; public class ReceiptRequestDTO { @@ -58,6 +59,8 @@ public static class getReceipt { private Float disgust; private String receiptThemeType; + + private LocalDateTime createdAt; } @Data @@ -113,4 +116,27 @@ public static class createReceipt { private String receiptThemeType; } + + @Data + @Builder + @Getter + @Setter + @AllArgsConstructor + @NoArgsConstructor + public static class updateReceipt { + + private Long id; + + private String mainDeparture; + + private String subDeparture; + + private String mainDestination; + + private String subDestination; + + private String oneLineMemo; + + private String receiptThemeType; + } } diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/dto/response/TripResponseDTO.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/dto/response/TripResponseDTO.java index f2e185b568..bdf76e0ad3 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/dto/response/TripResponseDTO.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/dto/response/TripResponseDTO.java @@ -32,8 +32,10 @@ public static class GetTrip { @Schema(description = "여행 이름") private final String tripName; + private final int numOfCard; + // fromEntity - public static GetTrip fromEntity(Trip trip) { + public static GetTrip fromEntity(Trip trip, int numOfCard) { return GetTrip.builder() .id(trip.getId()) .email(trip.getUser().getEmail()) @@ -41,6 +43,7 @@ public static GetTrip fromEntity(Trip trip) { .endDate(trip.getEndDate()) .analyzingCount(trip.getAnalyzingCount()) .tripName(trip.getTripName()) + .numOfCard(numOfCard) .build(); } } diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/CardViewService.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/CardViewService.java index 2a2fb71eb0..c94815295d 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/CardViewService.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/CardViewService.java @@ -2,6 +2,7 @@ import com.moment.core.domain.cardView.CardView; import com.moment.core.domain.cardView.CardViewRepository; +import com.moment.core.domain.trip.Trip; import com.moment.core.domain.tripFile.TripFile; import com.moment.core.domain.user.User; import com.moment.core.domain.user.UserRepository; @@ -97,7 +98,8 @@ public CardViewResponseDTO.GetCardView uploadRecord(CardViewRequestDTO.UploadRec // tripFile, trip의 analyzingCount 증가 tripFileService.increaseAnalyzingCount(tripFile); - tripService.increaseAnalyzingCount(tripFile.getTrip()); + Trip trip = tripFile.getTrip(); + tripService.increaseAnalyzingCount(trip); List imageUrls = new ArrayList<>(); return CardViewResponseDTO.GetCardView.fromEntity(cardViewRepository.save(cardView), imageUrls); } @@ -150,32 +152,36 @@ public void updateRecord(Long cardViewId, CardViewRequestDTO.UpdateRecord update @Transactional public void deleteRecord(Long cardViewId) { CardView cardView = cardViewRepository.findById(cardViewId).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 카드뷰입니다.")); + TripFile tripFile = cardView.getTripFile(); + Trip trip = tripFile.getTrip(); + User user = tripFile.getUser(); + String userId = user.getId().toString(); + // cardView에 엮인 사진들 먼저 삭제 - String userId = cardView.getTripFile().getUser().getId().toString(); imageFileService.deleteAll(cardView, userId); s3Service.deleteFile(cardView.getRecordFileName(), userId); - boolean isAnalyzed = cardView.getRecordFileStatus().equals("WAIT"); + boolean isWaiting = cardView.getRecordFileStatus().equals("WAIT"); + boolean isFail = cardView.getRecordFileStatus().equals("FAIL"); + // 만약 tripfile의 Trip이 untitled일 경우 // 만약 tripfile의 크기가 1이라면 tripFile과 cardView 전부 삭제, untitledTrip의 analyzingCount 감소 - TripFile tripFile = cardView.getTripFile(); - if (tripFile.getTrip().getIsNotTitled()) { + if (trip.getIsNotTitled()) { if (tripFileService.getCardViewCount(tripFile) == 1) { - cardViewRepository.delete(cardView); - tripFileService.delete(cardView.getTripFile()); - if (isAnalyzed) - tripService.decreaseAnalyzingCount(cardView.getTripFile().getTrip()); + tripFileService.delete(tripFile); + if (isWaiting || isFail) + tripService.decreaseAnalyzingCount(trip); } } // 만약 tripfile의 trip이 untitled가 아닐경우 // cardView만 삭제, tripFile의 analyzingCount 감소 // trip의 analyzingCount 감소 else { - cardViewRepository.delete(cardView); - if (isAnalyzed){ - tripFileService.decreaseAnalyzingCount(cardView.getTripFile()); - tripService.decreaseAnalyzingCount(cardView.getTripFile().getTrip()); + if (isWaiting || isFail){ + tripFileService.decreaseAnalyzingCount(tripFile); + tripService.decreaseAnalyzingCount(trip); } } + cardViewRepository.delete(cardView); } public void likeCardView(Long cardViewId) { diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/ImageFileService.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/ImageFileService.java index ed2b2bba06..fd19709830 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/ImageFileService.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/ImageFileService.java @@ -55,7 +55,8 @@ public void uploadAll(List imageFiles, Long cardViewId, Long user public void deleteImages(List images, Long userId) { for (Long imageId : images) { ImageFile image = imageFileRepository.findById(imageId).orElseThrow(() -> new IllegalArgumentException("해당 이미지가 없습니다.")); - userService.validateUserWithCardView(userId, image.getCardView().getId()); + CardView cardView = image.getCardView(); + userService.validateUserWithCardView(userId, cardView.getId()); s3Service.deleteFile(image.getFileName(), userId.toString()); imageFileRepository.delete(image); } diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/ReceiptService.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/ReceiptService.java index 8e4beb0c82..550080cb99 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/ReceiptService.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/ReceiptService.java @@ -31,14 +31,13 @@ @RequiredArgsConstructor public class ReceiptService { private final ReceiptRepository receiptRepository; - private final UserRepository userRepository; private final TripFileRepository tripFileRepository; private final TripRepository tripRepository; private final CardViewRepository cardViewRepository; public Integer getReceiptCount(Long userId) { // 유저의 총 영수증 개수 반환 - return receiptRepository.findAllByTrip_User_Id(userId).size(); + return receiptRepository.countByTrip_User_Id(userId).intValue(); } public ReceiptRequestDTO.getReceiptAll getAllReceipt(Long userId, Pageable pageable) { @@ -76,6 +75,7 @@ private ReceiptRequestDTO.getReceipt mapToReceiptDTO(Receipt receipt) { .neutral(receipt.getNeutral()) .disgust(receipt.getDisgust()) .receiptThemeType(receipt.getReceiptThemeType()) + .createdAt(receipt.getCreatedAt()) .build(); } @@ -83,9 +83,7 @@ public void deleteReceipts(Long userId, ReceiptRequestDTO.deleteReceipts deleteR List receipts = new ArrayList<>(); for (ReceiptRequestDTO.deleteReceipt deleteReceipt : deleteReceipts.getReceiptIds()) { Receipt receipt = receiptRepository.findById(deleteReceipt.getReceiptId()).orElseThrow(() -> new IllegalArgumentException("해당 영수증이 존재하지 않습니다.")); - if (!receipt.getTrip().getUser().getId().equals(userId)) { - throw new IllegalArgumentException("해당 영수증을 삭제할 권한이 없습니다."); - } + validateUserWithReceipt(userId, deleteReceipt.getReceiptId()); receipts.add(receipt); } receiptRepository.deleteAll(receipts); @@ -125,7 +123,8 @@ public Map getCardViewCount(Trip trip) { public void createReceipt(Long userId, ReceiptRequestDTO.createReceipt createReceipt) { // 유저가 해당 여행에 접근 권한이 있는지 확인 Trip trip = tripRepository.findById(createReceipt.getTripId()).orElseThrow(() -> new IllegalArgumentException("해당 여행이 존재하지 않습니다.")); - if (!trip.getUser().getId().equals(userId)) { + User user = trip.getUser(); + if (!user.getId().equals(userId)) { throw new IllegalArgumentException("해당 여행에 접근 권한이 없습니다."); } @@ -177,4 +176,25 @@ public void createReceipt(Long userId, ReceiptRequestDTO.createReceipt createRec receiptRepository.save(receipt); } + + public void updateReceipt(Long userId, ReceiptRequestDTO.updateReceipt updateReceipt) { + Receipt receipt = receiptRepository.findById(updateReceipt.getId()).orElseThrow(() -> new IllegalArgumentException("해당 영수증이 존재하지 않습니다.")); + receipt.setMainDeparture(updateReceipt.getMainDeparture()); + receipt.setSubDeparture(updateReceipt.getSubDeparture()); + receipt.setMainDestination(updateReceipt.getMainDestination()); + receipt.setSubDestination(updateReceipt.getSubDestination()); + receipt.setOneLineMemo(updateReceipt.getOneLineMemo()); + receipt.setReceiptThemeType(updateReceipt.getReceiptThemeType()); + + receiptRepository.save(receipt); + } + + public void validateUserWithReceipt(Long userId, Long id) { + Receipt receipt = receiptRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("해당 영수증이 존재하지 않습니다.")); + Trip trip = receipt.getTrip(); + User user = trip.getUser(); + if (!user.getId().equals(userId)) { + throw new IllegalArgumentException("해당 영수증을 수정할 권한이 없습니다."); + } + } } diff --git a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/TripService.java b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/TripService.java index 1cca375eed..407e3db300 100644 --- a/backend/moment/moment-server/core/src/main/java/com/moment/core/service/TripService.java +++ b/backend/moment/moment-server/core/src/main/java/com/moment/core/service/TripService.java @@ -1,7 +1,11 @@ package com.moment.core.service; +import com.moment.core.domain.cardView.CardView; +import com.moment.core.domain.cardView.CardViewRepository; import com.moment.core.domain.trip.Trip; import com.moment.core.domain.trip.TripRepository; +import com.moment.core.domain.tripFile.TripFile; +import com.moment.core.domain.tripFile.TripFileRepository; import com.moment.core.domain.user.User; import com.moment.core.domain.user.UserRepository; import com.moment.core.dto.request.TripRequestDTO; @@ -17,6 +21,7 @@ import java.time.LocalDate; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -30,6 +35,8 @@ public class TripService { private final TripFileService tripFileService; private final EntityManager em; private final ReceiptService receiptService; + private final TripFileRepository tripFileRepository; + private final CardViewRepository cardViewRepository; public void save(Trip trip) { tripRepository.save(trip); @@ -42,12 +49,13 @@ public void save(Trip trip) { @Transactional public Trip delete(Long tripId) { Trip trip = tripRepository.findById(tripId).orElseThrow(() -> new RuntimeException("존재하지 않는 여행입니다.")); + User user = trip.getUser(); if(trip.getIsNotTitled()){ throw new UntitledTripDeleteException("묶이지 않은 여행은 삭제할 수 없습니다."); } - Trip untitledTrip = getUntitledTrip(trip.getUser()); + Trip untitledTrip = getUntitledTrip(user); tripFileService.deleteByTripOrUntitled(trip, untitledTrip); - alreadyBookedDateService.deleteAll(trip.getUser(), trip.getStartDate(), trip.getEndDate()); + alreadyBookedDateService.deleteAll(user, trip.getStartDate(), trip.getEndDate()); tripRepository.delete(trip); return trip; } @@ -131,12 +139,23 @@ public void decreaseAnalyzingCount(Trip trip) { tripRepository.save(trip); } + public int getCardNum(Trip trip) { +// List tripFiles = tripFileRepository.findAllByTrip(trip); +// int cardViewCount = 0; +// for (TripFile tripFile : tripFiles) { +// List cardViews = cardViewRepository.findAllByTripFile(tripFile); +// cardViewCount += cardViews.size(); +// } + return cardViewRepository.countByTripFile_Trip_Id(trip.getId()).intValue(); + } + public TripResponseDTO.GetAllTrip getAllTrip(Long userId) { User user = userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException("존재하지 않는 유저입니다.")); List rtnList = new ArrayList<>(); List trips = tripRepository.findAllByUserAndIsNotTitledOrderByStartDate(user, false); for (Trip trip : trips) { - rtnList.add(TripResponseDTO.GetTrip.fromEntity(trip)); + int numOfCard = getCardNum(trip); + rtnList.add(TripResponseDTO.GetTrip.fromEntity(trip, numOfCard)); } return TripResponseDTO.GetAllTrip.builder().trips(rtnList).build(); } diff --git a/backend/moment/moment-server/core/src/test/java/com/moment/core/controller/ReceiptControllerTest.java b/backend/moment/moment-server/core/src/test/java/com/moment/core/controller/ReceiptControllerTest.java index 25c005769e..e8ba26c2e4 100644 --- a/backend/moment/moment-server/core/src/test/java/com/moment/core/controller/ReceiptControllerTest.java +++ b/backend/moment/moment-server/core/src/test/java/com/moment/core/controller/ReceiptControllerTest.java @@ -22,10 +22,10 @@ import org.springframework.test.web.servlet.ResultActions; import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.List; -import static com.moment.core.config.DocumentFormatGenerator.getReceiptFormat; -import static com.moment.core.config.DocumentFormatGenerator.getStringNumFormat; +import static com.moment.core.config.DocumentFormatGenerator.*; import static org.junit.jupiter.api.Assertions.*; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; @@ -107,6 +107,7 @@ void getAllReceipt() throws Exception { .stDate(LocalDate.parse("2021-01-01")) .edDate(LocalDate.parse("2021-01-03")) .numOfCard(3) + .createdAt(LocalDateTime.parse("2021-01-01T00:00:00")) .build(), ReceiptRequestDTO.getReceipt.builder() .id(2L) @@ -126,6 +127,7 @@ void getAllReceipt() throws Exception { .stDate(LocalDate.parse("2021-02-01")) .edDate(LocalDate.parse("2021-02-02")) .numOfCard(3) + .createdAt(LocalDateTime.parse("2021-01-01T00:00:00")) .build(), ReceiptRequestDTO.getReceipt.builder() .id(3L) @@ -145,6 +147,7 @@ void getAllReceipt() throws Exception { .stDate(LocalDate.parse("2021-03-01")) .edDate(LocalDate.parse("2021-03-02")) .numOfCard(3) + .createdAt(LocalDateTime.parse("2021-01-01T00:00:00")) .build() )) .pagination(Pagination.builder() @@ -198,6 +201,7 @@ void getAllReceipt() throws Exception { fieldWithPath("data.receiptList[].neutral").type(JsonFieldType.NUMBER).description("중립적인 감정 비율"), fieldWithPath("data.receiptList[].disgust").type(JsonFieldType.NUMBER).description("역겨운 감정 비율"), fieldWithPath("data.receiptList[].receiptThemeType").type(JsonFieldType.STRING).attributes(getReceiptFormat()).description("영수증 테마 타입"), + fieldWithPath("data.receiptList[].createdAt").type(JsonFieldType.STRING).attributes(getDateTimeFormat()).description("생성 날짜"), fieldWithPath("data.pagination").type(JsonFieldType.OBJECT).description("페이징 정보"), fieldWithPath("data.pagination.totalPages").type(JsonFieldType.NUMBER).description("전체 페이지 수"), fieldWithPath("data.pagination.totalElements").type(JsonFieldType.NUMBER).description("전체 요소 수"), @@ -304,4 +308,53 @@ void createReceipt() throws Exception { ) .andDo(print()); } -} \ No newline at end of file + + @Test + public void updateReceipt() throws Exception { + ReceiptRequestDTO.updateReceipt updateReceipt = ReceiptRequestDTO.updateReceipt.builder() + .id(1L) + .mainDeparture("mainDeparture") + .subDeparture("subDeparture") + .mainDestination("mainDestination") + .subDestination("subDestination") + .oneLineMemo("oneLineMemo") + .receiptThemeType("A") + .build(); + + Mockito.doNothing().when(receiptService).updateReceipt(1L, updateReceipt); + + ResultActions result = mockMvc.perform(RestDocumentationRequestBuilders.put("/core/receipt") + .header("userId", 1L) + .contentType(MediaType.APPLICATION_JSON) + .content(Json.pretty(updateReceipt)) + ); + + result.andExpect(status().isOk()) + .andDo( + document("receipt/updateReceipt", + Preprocessors.preprocessRequest(Preprocessors.prettyPrint()), + Preprocessors.preprocessResponse(Preprocessors.prettyPrint()), + requestHeaders( + headerWithName("userId").description("Bearer Token") + ), + requestFields( + fieldWithPath("id").type(JsonFieldType.NUMBER).description("영수증 ID"), + fieldWithPath("mainDeparture").type(JsonFieldType.STRING).attributes(getStringNumFormat(7)).description("출발지(대)"), + fieldWithPath("subDeparture").type(JsonFieldType.STRING).attributes(getStringNumFormat(24)).description("출발지(소)"), + fieldWithPath("mainDestination").type(JsonFieldType.STRING).attributes(getStringNumFormat(7)).description("도착지(대)"), + fieldWithPath("subDestination").type(JsonFieldType.STRING).attributes(getStringNumFormat(24)).description("도착지(소)"), + fieldWithPath("oneLineMemo").type(JsonFieldType.STRING).attributes(getStringNumFormat(27)).description("한줄 메모"), + fieldWithPath("receiptThemeType").type(JsonFieldType.STRING).attributes(getReceiptFormat()).description("영수증 테마 타입") + ), + responseFields( + fieldWithPath("status").type(JsonFieldType.NUMBER).description("응답 상태 코드"), + fieldWithPath("code").type(JsonFieldType.STRING).description("응답 코드"), + fieldWithPath("msg").type(JsonFieldType.STRING).description("응답 메시지"), + fieldWithPath("detailMsg").type(JsonFieldType.STRING).description("상세 메시지"), + fieldWithPath("data").type(JsonFieldType.OBJECT).description("데이터 없음") + ) + ) + ) + .andDo(print()); + +} } \ No newline at end of file From e5a9a143c967307ecc076e04efd02cca1e8af072 Mon Sep 17 00:00:00 2001 From: j-yong99 Date: Wed, 8 May 2024 15:44:42 +0900 Subject: [PATCH 2/2] =?UTF-8?q?:recycle:=20API=20=EC=B5=9C=EC=8B=A0?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/controller/TripControllerTest.java | 4 + .../src/main/resources/static/docs/index.html | 131 ++++++++++-------- 2 files changed, 79 insertions(+), 56 deletions(-) diff --git a/backend/moment/moment-server/core/src/test/java/com/moment/core/controller/TripControllerTest.java b/backend/moment/moment-server/core/src/test/java/com/moment/core/controller/TripControllerTest.java index 8faaaff770..c947b98ed2 100644 --- a/backend/moment/moment-server/core/src/test/java/com/moment/core/controller/TripControllerTest.java +++ b/backend/moment/moment-server/core/src/test/java/com/moment/core/controller/TripControllerTest.java @@ -112,6 +112,7 @@ void getAllTrip() throws Exception{ .endDate(LocalDate.now().plusDays(1)) .analyzingCount(0) .tripName("test") + .numOfCard(0) .build(), TripResponseDTO.GetTrip.builder() .id(2L) @@ -119,6 +120,7 @@ void getAllTrip() throws Exception{ .startDate(LocalDate.now()) .endDate(LocalDate.now().plusDays(1)) .analyzingCount(1) + .numOfCard(2) .tripName("test") .build(), TripResponseDTO.GetTrip.builder() @@ -127,6 +129,7 @@ void getAllTrip() throws Exception{ .startDate(LocalDate.now()) .endDate(LocalDate.now().plusDays(1)) .analyzingCount(2) + .numOfCard(2) .tripName("test") .build() ); @@ -158,6 +161,7 @@ void getAllTrip() throws Exception{ fieldWithPath("data.trips[].startDate").attributes(getDateFormat()).description("출발일"), fieldWithPath("data.trips[].endDate").attributes(getDateFormat()).description("도착일"), fieldWithPath("data.trips[].analyzingCount").type(JsonFieldType.NUMBER).description("분석 중 파일 개수"), + fieldWithPath("data.trips[].numOfCard").type(JsonFieldType.NUMBER).description("카드뷰 개수"), fieldWithPath("data.trips[].tripName").type(JsonFieldType.STRING).description("여행 이름") ) ) diff --git a/backend/moment/moment-server/gateway/src/main/resources/static/docs/index.html b/backend/moment/moment-server/gateway/src/main/resources/static/docs/index.html index dba8a84fb1..b9af51325b 100644 --- a/backend/moment/moment-server/gateway/src/main/resources/static/docs/index.html +++ b/backend/moment/moment-server/gateway/src/main/resources/static/docs/index.html @@ -784,7 +784,7 @@

@@ -2857,8 +2857,8 @@

@@ -2887,8 +2887,8 @@

@@ -3278,8 +3289,8 @@

@@ -3309,8 +3320,8 @@

$ echo '{
   "tripId" : 1,
-  "startDate" : "2024-05-07",
-  "endDate" : "2024-05-08",
+  "startDate" : "2024-05-08",
+  "endDate" : "2024-05-09",
   "tripName" : "test"
 }' | http PUT 'http://localhost:8080/core/trip' \
     'Content-Type:application/json;charset=UTF-8' \
@@ -3325,8 +3336,8 @@ 

{
   "tripId" : 1,
-  "startDate" : "2024-05-07",
-  "endDate" : "2024-05-08",
+  "startDate" : "2024-05-08",
+  "endDate" : "2024-05-09",
   "tripName" : "test"
 }
@@ -3668,8 +3679,8 @@

HTTP/1.1 200 OK
 Content-Type: application/json
-Content-Length: 1793
+Content-Length: 1922
 
 {
   "status" : 200,
@@ -4323,7 +4334,8 @@ 

영수증 테마 타입

+

data.receiptList[].createdAt

+

String

+

생성 날짜

+ +

data.pagination

Object

페이징 정보

@@ -4672,21 +4691,21 @@