From e466b2d86108a574c968a7ae5859cc670bab02c3 Mon Sep 17 00:00:00 2001 From: zqwz Date: Wed, 22 Nov 2023 01:42:54 +0900 Subject: [PATCH 01/16] =?UTF-8?q?chore=20:=20=EC=9D=B4=EB=AF=B8=EC=A7=80?= =?UTF-8?q?=20=ED=83=80=EC=9E=84=EC=A1=B4=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 30eb8ec..dcbd751 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,9 @@ version: "4" services: + app: + image: ejoh/trip-together + environment: + TZ: "Asia/Seoul" springboot: image: ejoh/trip-together container_name: trip-together From 86285b849e66bcea41cd6a1b904d862515239c69 Mon Sep 17 00:00:00 2001 From: wjstmdduf Date: Wed, 22 Nov 2023 11:19:57 +0900 Subject: [PATCH 02/16] =?UTF-8?q?refactor=20:=20=EC=9C=A0=EC=A0=80=20Dto?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80,=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/user/controller/UserController.java | 34 +++++++++++++------ .../java/com/tgd/trip/user/domain/User.java | 13 +++++++ .../java/com/tgd/trip/user/dto/UserDto.java | 15 ++++++++ .../com/tgd/trip/user/mapper/UserMapper.java | 19 +++++++++++ .../tgd/trip/user/service/UserService.java | 20 +++++++++++ 5 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/tgd/trip/user/mapper/UserMapper.java diff --git a/src/main/java/com/tgd/trip/user/controller/UserController.java b/src/main/java/com/tgd/trip/user/controller/UserController.java index 33fa445..226f5a9 100644 --- a/src/main/java/com/tgd/trip/user/controller/UserController.java +++ b/src/main/java/com/tgd/trip/user/controller/UserController.java @@ -9,6 +9,7 @@ import com.tgd.trip.user.domain.User; import com.tgd.trip.user.dto.SignupDto; import com.tgd.trip.user.dto.UserDto; +import com.tgd.trip.user.mapper.UserMapper; import com.tgd.trip.user.service.UserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -29,7 +30,7 @@ public class UserController { private final PasswordEncoder passwordEncoder; private final JwtTokenProvider jwtTokenProvider; private final UserService userService; - + private final UserMapper userMapper; @GetMapping("/signup") public ResponseEntity signup(@AuthenticationPrincipal SecurityUser securityUser) { System.out.println("회원가입 요청옴"); @@ -44,20 +45,20 @@ public ResponseEntity signup(@AuthenticationPrincipal SecurityUser se } @GetMapping("/mypage") - public ResponseEntity getUserInfo(@AuthenticationPrincipal SecurityUser securityUser) { - User user = null; + public ResponseEntity getUserInfo(@AuthenticationPrincipal SecurityUser securityUser) { + UserDto.Response response = null; try { Long userId = securityUser.getMember().getUserId(); if (securityUser.getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_USER"))) { // 요청한 유저가 게스트 라면 - user = userService.getUserInfo(userId); + User user = userService.getUserInfo(userId); + response = userMapper.entityToResponse(user); System.out.println("유저 찾음" + user); } - System.out.println("유저정보 반환" + user.toString()); }catch (Exception e){ System.out.println("문제발생!!"); e.printStackTrace(); } - return ResponseEntity.ok(user); + return ResponseEntity.ok(response); } @PostMapping("/signup") @@ -73,18 +74,31 @@ public ResponseEntity signup(@AuthenticationPrincipal SecurityUser secur return ResponseEntity.ok(newToken); } + @PatchMapping("/userupdate") + public ResponseEntity userUpdate(@AuthenticationPrincipal SecurityUser securityUser, + @RequestPart UserDto.Patch patch, + @RequestPart(value = "file", required = false) MultipartFile file){ + System.out.println("유저업데이트 컨트롤러 요청" + patch); + + User user = userService.userUpdate(securityUser.getMember(), patch, file); + + UserDto.Response response = userMapper.entityToResponse(user); + + return ResponseEntity.ok(response); + + } + @GetMapping("/userSchedule") public ResponseEntity userSchedule(@AuthenticationPrincipal SecurityUser securityUser) { List userSchedule = null; try { Long userId = securityUser.getMember().getUserId(); - if (securityUser.getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_USER"))) { - userSchedule = userService.userSchedule(userId); - } + userSchedule = userService.userSchedule(userId); }catch (Exception e){ System.out.println("문제발생!!!!!!!!!!!!!!!"); - e.printStackTrace(); } + e.printStackTrace(); + } return ResponseEntity.ok(userSchedule); } @GetMapping("/userWishSD") diff --git a/src/main/java/com/tgd/trip/user/domain/User.java b/src/main/java/com/tgd/trip/user/domain/User.java index 905d441..546a3d9 100644 --- a/src/main/java/com/tgd/trip/user/domain/User.java +++ b/src/main/java/com/tgd/trip/user/domain/User.java @@ -4,6 +4,7 @@ import com.tgd.trip.global.BaseEntity; import com.tgd.trip.schedule.domain.Schedule; import com.tgd.trip.schedule.domain.ScheduleBookmark; +import com.tgd.trip.user.dto.UserDto; import lombok.*; import javax.persistence.*; @@ -11,6 +12,7 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.List; +import java.util.Optional; @Entity @Getter @@ -89,4 +91,15 @@ public void addSchedule(Schedule schedule) { } schedule.setUser(this); } + + public void userUpdate(UserDto.Patch patch, String imgUrl) { + Optional.ofNullable(patch.nickname()) + .ifPresent(this::setNickName); + Optional.ofNullable(imgUrl) + .ifPresent(this::setImgUrl); + Optional.ofNullable(patch.birth()) + .ifPresent(this::setBirth); + Optional.ofNullable(patch.sex()) + .ifPresent(this::setSex); + } } diff --git a/src/main/java/com/tgd/trip/user/dto/UserDto.java b/src/main/java/com/tgd/trip/user/dto/UserDto.java index 267a45a..f4fbdd3 100644 --- a/src/main/java/com/tgd/trip/user/dto/UserDto.java +++ b/src/main/java/com/tgd/trip/user/dto/UserDto.java @@ -9,4 +9,19 @@ public class UserDto { @Builder public record SimpleResponse(Long userId, String nickname, String imgUrl, LocalDate birth, Boolean sex) { } + + @Builder + public record Response(Long userId, String name, + String nickname, String imgUrl, + LocalDate birth, Boolean sex) { + + } + + @Builder + public record Patch(Long userId, String name, + String nickname, String imgUrl, + LocalDate birth, Boolean sex) { + + } + } diff --git a/src/main/java/com/tgd/trip/user/mapper/UserMapper.java b/src/main/java/com/tgd/trip/user/mapper/UserMapper.java new file mode 100644 index 0000000..99a649e --- /dev/null +++ b/src/main/java/com/tgd/trip/user/mapper/UserMapper.java @@ -0,0 +1,19 @@ +package com.tgd.trip.user.mapper; + +import com.tgd.trip.user.domain.User; +import com.tgd.trip.user.dto.UserDto; +import org.springframework.stereotype.Component; + +@Component +public class UserMapper { + public UserDto.Response entityToResponse(User user) { + return UserDto.Response.builder() + .userId(user.getUserId()) + .name(user.getName()) + .nickname(user.getNickName()) + .imgUrl(user.getImgUrl()) + .birth(user.getBirth()) + .sex(user.getSex()) + .build(); + } +} diff --git a/src/main/java/com/tgd/trip/user/service/UserService.java b/src/main/java/com/tgd/trip/user/service/UserService.java index e7f1cd0..b37d84a 100644 --- a/src/main/java/com/tgd/trip/user/service/UserService.java +++ b/src/main/java/com/tgd/trip/user/service/UserService.java @@ -13,6 +13,7 @@ import com.tgd.trip.user.domain.Role; import com.tgd.trip.user.domain.User; import com.tgd.trip.user.dto.SignupDto; +import com.tgd.trip.user.dto.UserDto; import com.tgd.trip.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -115,4 +116,23 @@ public List userWishAT(Long userId) { return bookmarks.stream().map(AttractionBookmark::getAttraction).collect(Collectors.toList()); } + + public User userUpdate(User member, UserDto.Patch patch, MultipartFile file) { + String imgUrl = ""; + + System.out.println("유저업데이트 서비스 요청" + patch); + if(file != null){ + imgUrl = s3Uploader.saveUploadFile(file); + imgUrl = s3Uploader.getFilePath(imgUrl); + }else { + imgUrl = patch.imgUrl(); + } + member.userUpdate(patch, imgUrl); + + System.out.println("유저업데이트 서비스 요청 이후" + member.getNickName()); + + userRepository.save(member); + + return member; + } } From eb7cd256f65d20ae3f25bb8cebf606e8f6fe13bf Mon Sep 17 00:00:00 2001 From: zini9188 Date: Wed, 22 Nov 2023 14:17:16 +0900 Subject: [PATCH 03/16] =?UTF-8?q?refactor=20:=20=ED=9A=8C=EC=9B=90=20?= =?UTF-8?q?=EA=B0=80=EC=9E=85=ED=95=9C=20=EC=82=AC=EB=9E=8C=EB=A7=8C=20?= =?UTF-8?q?=EC=9D=BC=EC=A0=95,=20=EB=8C=93=EA=B8=80=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B2=80=EC=A6=9D=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ScheduleController.java | 22 ++++++++----- .../tgd/trip/schedule/dto/ScheduleDto.java | 2 +- .../schedule/service/ScheduleService.java | 31 +++++++++++++------ 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/tgd/trip/schedule/controller/ScheduleController.java b/src/main/java/com/tgd/trip/schedule/controller/ScheduleController.java index 860c177..902c463 100644 --- a/src/main/java/com/tgd/trip/schedule/controller/ScheduleController.java +++ b/src/main/java/com/tgd/trip/schedule/controller/ScheduleController.java @@ -5,12 +5,14 @@ import com.tgd.trip.schedule.dto.ScheduleDto; import com.tgd.trip.schedule.mapper.ScheduleMapper; import com.tgd.trip.schedule.service.ScheduleService; +import com.tgd.trip.security.SecurityUser; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -27,19 +29,21 @@ public class ScheduleController { private final ScheduleMapper scheduleMapper; @PostMapping - public ResponseEntity createSchedule(@RequestPart ScheduleDto.Post post, + public ResponseEntity createSchedule(@AuthenticationPrincipal SecurityUser securityUser, + @RequestPart ScheduleDto.Post post, @RequestParam(value = "image", required = false) MultipartFile file) { log.info(String.valueOf(post)); - Schedule schedule = scheduleService.createSchedule(post, file); + Schedule schedule = scheduleService.createSchedule(post, securityUser, file); return ResponseEntity.created(URI.create(String.format("api/schedule/%s", schedule.getScheduleId()))).build(); } @PatchMapping("{schedule-id}") - public ResponseEntity updateSchedule(@PathVariable("schedule-id") Long id, + public ResponseEntity updateSchedule(@AuthenticationPrincipal SecurityUser securityUser, + @PathVariable("schedule-id") Long id, @RequestPart ScheduleDto.Patch patch, @RequestParam(value = "image", required = false) MultipartFile file) { log.info(String.valueOf(patch)); - Schedule schedule = scheduleService.updateSchedule(id, patch, file); + Schedule schedule = scheduleService.updateSchedule(securityUser, id, patch, file); ScheduleDto.Response response = scheduleMapper.entityToResponse(schedule); return ResponseEntity.ok(response); } @@ -98,9 +102,10 @@ public ResponseEntity createScheduleLike(@PathVariable("schedule-id") Long sc } @PostMapping(value = "{schedule-id}/comment") - public ResponseEntity createComment(@PathVariable("schedule-id") Long scheduleId, + public ResponseEntity createComment(@AuthenticationPrincipal SecurityUser securityUser, + @PathVariable("schedule-id") Long scheduleId, @RequestBody CommentDto.Post post) { - scheduleService.createComment(scheduleId, post); + scheduleService.createComment(securityUser, scheduleId, post); return ResponseEntity.status(HttpStatus.CREATED).build(); } @@ -120,9 +125,10 @@ public ResponseEntity getComments(@PathVariable("schedule-id") Long scheduleI } @DeleteMapping(value = "{schedule-id}/comment/{comment-id}") - public ResponseEntity deleteComment(@PathVariable("schedule-id") Long scheduleId, + public ResponseEntity deleteComment(@AuthenticationPrincipal SecurityUser securityUser, + @PathVariable("schedule-id") Long scheduleId, @PathVariable("comment-id") Long commentId) { - scheduleService.deleteComment(scheduleId, commentId); + scheduleService.deleteComment(securityUser, scheduleId, commentId); return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } } diff --git a/src/main/java/com/tgd/trip/schedule/dto/ScheduleDto.java b/src/main/java/com/tgd/trip/schedule/dto/ScheduleDto.java index ac8a60f..6466745 100644 --- a/src/main/java/com/tgd/trip/schedule/dto/ScheduleDto.java +++ b/src/main/java/com/tgd/trip/schedule/dto/ScheduleDto.java @@ -7,7 +7,7 @@ public class ScheduleDto { - public record Post(String title, String content, Boolean viewYn, List days, Long userId) { + public record Post(String title, String content, Boolean viewYn, List days) { } public record Patch(String title, String content, Boolean viewYn, List days) { diff --git a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java index c595792..b827cc3 100644 --- a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java +++ b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java @@ -11,6 +11,7 @@ import com.tgd.trip.schedule.repository.ScheduleBookmarkRepository; import com.tgd.trip.schedule.repository.ScheduleLikeRepository; import com.tgd.trip.schedule.repository.ScheduleRepository; +import com.tgd.trip.security.SecurityUser; import com.tgd.trip.user.domain.User; import com.tgd.trip.user.service.UserService; import lombok.RequiredArgsConstructor; @@ -40,9 +41,9 @@ public class ScheduleService { private final UserService userService; @Transactional - public Schedule createSchedule(ScheduleDto.Post post, MultipartFile file) { + public Schedule createSchedule(ScheduleDto.Post post, SecurityUser securityUser, MultipartFile file) { // 유저 존재하는지 판별 - User verifyUser = userService.getVerifyUser(post.userId()); + User user = userService.getVerifyUser(securityUser.getMember().getUserId()); // 일정 이름, 내용을 가지는 객체 생성 String imgUrl = ""; @@ -65,17 +66,21 @@ public Schedule createSchedule(ScheduleDto.Post post, MultipartFile file) { .forEach(dayAttractionDto -> dayAttractionService.update(dayAttractionDto, day)); }); // 유저와 연결 - verifyUser.addSchedule(schedule); + user.addSchedule(schedule); scheduleRepository.save(schedule); return schedule; } @Transactional - public Schedule updateSchedule(Long scheduleId, ScheduleDto.Patch patch, MultipartFile file) { + public Schedule updateSchedule(SecurityUser securityUser, Long scheduleId, ScheduleDto.Patch patch, MultipartFile file) { // 기존 스케줄 가져오기 Schedule schedule = getSchedule(scheduleId); + if (!securityUser.getMember().getEmail().equals(schedule.getUser().getEmail())) { + throw new CustomException(ErrorCode.DIFFERENT_USER); + } + // 일정용 이미지 업로드 String imgUrl = ""; if (file != null) { @@ -186,15 +191,15 @@ public void createLike(Long scheduleId, Long userId) { } @Transactional - public void createComment(Long scheduleId, CommentDto.Post post) { + public void createComment(SecurityUser securityUser, Long scheduleId, CommentDto.Post post) { + // 유저 가져오기 + User user = securityUser.getMember(); + // 스케줄 예외 처리 Schedule findSchedule = getSchedule(scheduleId); - // 유저 예외 처리 - User findUser = userService.getVerifyUser(post.userId()); - // 댓글 생성 - Comment comment = new Comment(findUser, post.content()); + Comment comment = new Comment(user, post.content()); findSchedule.addComments(comment); commentRepository.save(comment); } @@ -222,7 +227,9 @@ public void updateComment(Long scheduleId, Long commentId, CommentDto.Patch patc } @Transactional - public void deleteComment(Long scheduleId, Long commentId) { + public void deleteComment(SecurityUser securityUser, Long scheduleId, Long commentId) { + User user = securityUser.getMember(); + // 스케줄 예외 처리 getSchedule(scheduleId); @@ -230,6 +237,10 @@ public void deleteComment(Long scheduleId, Long commentId) { Comment findComment = commentRepository.findById(commentId) .orElseThrow(() -> new CustomException(ErrorCode.COMMENT_NOT_FOUND)); + if (!findComment.getUser().getEmail().equals(user.getEmail())) { + throw new CustomException(ErrorCode.DIFFERENT_USER); + } + commentRepository.delete(findComment); } } From 90a61ccb567e0c4e5056cb4f6ca12aa1bf883097 Mon Sep 17 00:00:00 2001 From: zini9188 Date: Wed, 22 Nov 2023 17:34:11 +0900 Subject: [PATCH 04/16] =?UTF-8?q?refactor=20:=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=95=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ScheduleController.java | 8 ++-- .../trip/schedule/mapper/ScheduleMapper.java | 41 +++++++++---------- .../repository/ScheduleRepository.java | 5 +-- .../schedule/service/ScheduleService.java | 7 ++-- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/tgd/trip/schedule/controller/ScheduleController.java b/src/main/java/com/tgd/trip/schedule/controller/ScheduleController.java index 902c463..5464e10 100644 --- a/src/main/java/com/tgd/trip/schedule/controller/ScheduleController.java +++ b/src/main/java/com/tgd/trip/schedule/controller/ScheduleController.java @@ -1,5 +1,6 @@ package com.tgd.trip.schedule.controller; +import com.tgd.trip.global.dto.PageResponse; import com.tgd.trip.schedule.domain.Schedule; import com.tgd.trip.schedule.dto.CommentDto; import com.tgd.trip.schedule.dto.ScheduleDto; @@ -8,6 +9,7 @@ import com.tgd.trip.security.SecurityUser; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.http.HttpStatus; @@ -60,9 +62,9 @@ public ResponseEntity getSchedule(@PathVariable("schedule-id") Long id) { public ResponseEntity getSchedules(@RequestParam(required = false) String keyword, @RequestParam(required = false) String sort, @PageableDefault(page = 1, size = 20) Pageable pageable) { - List schedules = scheduleService.getSchedules(keyword, sort, pageable); - List responses = scheduleMapper.simpleResponses(schedules); - return ResponseEntity.ok(responses); + Page schedules = scheduleService.getSchedules(keyword, sort, pageable); + Page responses = scheduleMapper.simpleResponses(schedules); + return ResponseEntity.ok(new PageResponse<>(responses.getContent(), responses)); } @DeleteMapping("{schedule-id}") diff --git a/src/main/java/com/tgd/trip/schedule/mapper/ScheduleMapper.java b/src/main/java/com/tgd/trip/schedule/mapper/ScheduleMapper.java index 3d78e7c..3b74d8d 100644 --- a/src/main/java/com/tgd/trip/schedule/mapper/ScheduleMapper.java +++ b/src/main/java/com/tgd/trip/schedule/mapper/ScheduleMapper.java @@ -4,6 +4,7 @@ import com.tgd.trip.schedule.domain.Schedule; import com.tgd.trip.schedule.dto.*; import com.tgd.trip.user.dto.UserDto; +import org.springframework.data.domain.Page; import org.springframework.stereotype.Component; import java.util.List; @@ -38,27 +39,25 @@ public ScheduleDto.Response entityToResponse(Schedule schedule) { .build(); } - public List simpleResponses(List schedules) { - return schedules.stream() - .map(schedule -> ScheduleDto.SimpleResponse.builder() - .scheduleId(schedule.getScheduleId()) - .title(schedule.getTitle()) - .content(schedule.getContent()) - .imgUrl(schedule.getImgUrl()) - .wishCount(schedule.getWishCount()) - .likeCount(schedule.getLikeCount()) - .days(schedule.getDays().stream() - .map(day -> new DayDto.DateResponse(day.getDayId(), day.getDate())) - .toList()) - .user(UserDto.SimpleResponse.builder() - .userId(schedule.getUser().getUserId()) - .nickname(schedule.getUser().getNickName()) - .imgUrl(schedule.getUser().getImgUrl()) - .birth(schedule.getUser().getBirth()) - .sex(schedule.getUser().getSex()) - .build() - ).build()) - .toList(); + public Page simpleResponses(Page schedules) { + return schedules.map(schedule -> ScheduleDto.SimpleResponse.builder() + .scheduleId(schedule.getScheduleId()) + .title(schedule.getTitle()) + .content(schedule.getContent()) + .imgUrl(schedule.getImgUrl()) + .wishCount(schedule.getWishCount()) + .likeCount(schedule.getLikeCount()) + .days(schedule.getDays().stream() + .map(day -> new DayDto.DateResponse(day.getDayId(), day.getDate())) + .toList()) + .user(UserDto.SimpleResponse.builder() + .userId(schedule.getUser().getUserId()) + .nickname(schedule.getUser().getNickName()) + .imgUrl(schedule.getUser().getImgUrl()) + .birth(schedule.getUser().getBirth()) + .sex(schedule.getUser().getSex()) + .build() + ).build()); } public List entityToCommentResponse(Schedule schedule) { diff --git a/src/main/java/com/tgd/trip/schedule/repository/ScheduleRepository.java b/src/main/java/com/tgd/trip/schedule/repository/ScheduleRepository.java index 2c2a91f..4fd72aa 100644 --- a/src/main/java/com/tgd/trip/schedule/repository/ScheduleRepository.java +++ b/src/main/java/com/tgd/trip/schedule/repository/ScheduleRepository.java @@ -1,12 +1,11 @@ package com.tgd.trip.schedule.repository; import com.tgd.trip.schedule.domain.Schedule; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; -import java.util.List; - public interface ScheduleRepository extends JpaRepository { - List findAllByTitleContainingAndViewYnNot(String keyword, Boolean viewYn, Pageable pageable); + Page findAllByTitleContainingAndViewYnNot(String keyword, Boolean viewYn, Pageable pageable); } diff --git a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java index b827cc3..2862181 100644 --- a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java +++ b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java @@ -16,8 +16,7 @@ import com.tgd.trip.user.service.UserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.*; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -128,8 +127,8 @@ public void deleteSchedule(Long id) { scheduleRepository.delete(schedule); } - public List getSchedules(String keyword, String sort, Pageable pageable) { - List schedules = scheduleRepository.findAllByTitleContainingAndViewYnNot(keyword, true, PageRequest.of(pageable.getPageNumber(), pageable.getPageSize())); + public Page getSchedules(String keyword, String sort, Pageable pageable) { + Page schedules = scheduleRepository.findAllByTitleContainingAndViewYnNot(keyword, true, PageRequest.of(pageable.getPageNumber() - 1, pageable.getPageSize())); return schedules; } From 1ac7d06b16fbafdd7d191dd89dee5c77436cbd6b Mon Sep 17 00:00:00 2001 From: wjstmdduf Date: Wed, 22 Nov 2023 17:39:13 +0900 Subject: [PATCH 05/16] =?UTF-8?q?refactor=20:=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95,=20=EC=82=AD=EC=A0=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tgd/trip/user/controller/UserController.java | 11 +++++++++++ .../com/tgd/trip/user/service/UserService.java | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tgd/trip/user/controller/UserController.java b/src/main/java/com/tgd/trip/user/controller/UserController.java index 226f5a9..06659d5 100644 --- a/src/main/java/com/tgd/trip/user/controller/UserController.java +++ b/src/main/java/com/tgd/trip/user/controller/UserController.java @@ -88,6 +88,17 @@ public ResponseEntity userUpdate(@AuthenticationPrincipal SecurityUser securi } + @PatchMapping("/userdelete") + public ResponseEntity userDelete(@AuthenticationPrincipal SecurityUser securityUser, + @RequestPart UserDto.Patch delete){ + if(securityUser.getMember().getUserId() == delete.userId()){ + userService.userDelete(securityUser.getMember()); + } + + return ResponseEntity.noContent().build(); + + } + @GetMapping("/userSchedule") public ResponseEntity userSchedule(@AuthenticationPrincipal SecurityUser securityUser) { List userSchedule = null; diff --git a/src/main/java/com/tgd/trip/user/service/UserService.java b/src/main/java/com/tgd/trip/user/service/UserService.java index b37d84a..de0f477 100644 --- a/src/main/java/com/tgd/trip/user/service/UserService.java +++ b/src/main/java/com/tgd/trip/user/service/UserService.java @@ -3,7 +3,6 @@ import com.tgd.trip.attraction.domain.Attraction; import com.tgd.trip.attraction.domain.AttractionBookmark; import com.tgd.trip.attraction.repository.AttractionBookmarkRepository; -import com.tgd.trip.attraction.repository.AttractionRepository; import com.tgd.trip.global.s3.S3Uploader; import com.tgd.trip.jwt.JwtTokenProvider; import com.tgd.trip.schedule.domain.Schedule; @@ -12,6 +11,7 @@ import com.tgd.trip.schedule.repository.ScheduleRepository; import com.tgd.trip.user.domain.Role; import com.tgd.trip.user.domain.User; +import com.tgd.trip.user.domain.UserStatus; import com.tgd.trip.user.dto.SignupDto; import com.tgd.trip.user.dto.UserDto; import com.tgd.trip.user.repository.UserRepository; @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.UUID; import java.util.stream.Collectors; @RequiredArgsConstructor @@ -135,4 +136,17 @@ public User userUpdate(User member, UserDto.Patch patch, MultipartFile file) { return member; } + + public void userDelete(User member) { + UUID uuid = UUID.randomUUID(); + member.setName(uuid.toString()); + member.setNickName(uuid.toString()); + member.setEmail(uuid.toString()); + member.setRoles(Collections.emptyList()); + member.setProvider(uuid.toString()); + member.setProviderId(uuid.toString()); + member.setStatus(UserStatus.DELETE); + member.setImgUrl(""); + userRepository.save(member); + } } From cbffbbf09476fc4354e4bdad41fad960e089de68 Mon Sep 17 00:00:00 2001 From: zqwz Date: Wed, 22 Nov 2023 20:00:08 +0900 Subject: [PATCH 06/16] =?UTF-8?q?fix=20:=20=ED=8E=98=EC=9D=B4=EC=A7=95=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tgd/trip/schedule/service/ScheduleService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java index 2862181..4ea358b 100644 --- a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java +++ b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java @@ -128,7 +128,7 @@ public void deleteSchedule(Long id) { } public Page getSchedules(String keyword, String sort, Pageable pageable) { - Page schedules = scheduleRepository.findAllByTitleContainingAndViewYnNot(keyword, true, PageRequest.of(pageable.getPageNumber() - 1, pageable.getPageSize())); + Page schedules = scheduleRepository.findAllByTitleContainingAndViewYnNot(keyword, true, PageRequest.of(pageable.getPageNumber(), pageable.getPageSize())); return schedules; } From b71d61e98703be077587099d8dc8c522a6339838 Mon Sep 17 00:00:00 2001 From: zqwz Date: Wed, 22 Nov 2023 20:05:07 +0900 Subject: [PATCH 07/16] =?UTF-8?q?feat=20:=20repository=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tgd/trip/schedule/repository/ScheduleRepository.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tgd/trip/schedule/repository/ScheduleRepository.java b/src/main/java/com/tgd/trip/schedule/repository/ScheduleRepository.java index 4fd72aa..9456e9d 100644 --- a/src/main/java/com/tgd/trip/schedule/repository/ScheduleRepository.java +++ b/src/main/java/com/tgd/trip/schedule/repository/ScheduleRepository.java @@ -1,11 +1,16 @@ package com.tgd.trip.schedule.repository; import com.tgd.trip.schedule.domain.Schedule; +import com.tgd.trip.user.domain.User; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ScheduleRepository extends JpaRepository { Page findAllByTitleContainingAndViewYnNot(String keyword, Boolean viewYn, Pageable pageable); -} + + List findAllByUser(User user); +} \ No newline at end of file From db355145e6705f6be61f01c7ed4c860cc8ebc11f Mon Sep 17 00:00:00 2001 From: zqwz Date: Thu, 23 Nov 2023 00:36:17 +0900 Subject: [PATCH 08/16] =?UTF-8?q?fix=20:=20=ED=86=A0=ED=81=B0=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B8=EC=A6=9D=20=EA=B0=9D=EC=B2=B4=20=EB=B0=9B?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ScheduleController.java | 18 +++++++++--------- .../trip/schedule/service/ScheduleService.java | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/tgd/trip/schedule/controller/ScheduleController.java b/src/main/java/com/tgd/trip/schedule/controller/ScheduleController.java index 5464e10..6ae820b 100644 --- a/src/main/java/com/tgd/trip/schedule/controller/ScheduleController.java +++ b/src/main/java/com/tgd/trip/schedule/controller/ScheduleController.java @@ -83,23 +83,23 @@ public ResponseEntity upload(@PathVariable("schedule-id") Long scheduleId, } @PostMapping(value = "{schedule-id}/wish") - public ResponseEntity createScheduleBookmark(@PathVariable("schedule-id") Long scheduleId, - @RequestParam("userId") Long userId) { - scheduleService.createBookmark(scheduleId, userId); + public ResponseEntity createScheduleBookmark(@AuthenticationPrincipal SecurityUser securityUser, + @PathVariable("schedule-id") Long scheduleId) { + scheduleService.createBookmark(scheduleId, securityUser); return ResponseEntity.status(HttpStatus.CREATED).build(); } @DeleteMapping(value = "{schedule-id}/wish") - public ResponseEntity deleteScheduleBookmark(@PathVariable("schedule-id") Long scheduleId, - @RequestParam("userId") Long userId) { - scheduleService.deleteBookmark(scheduleId, userId); + public ResponseEntity deleteScheduleBookmark(@AuthenticationPrincipal SecurityUser securityUser, + @PathVariable("schedule-id") Long scheduleId) { + scheduleService.deleteBookmark(scheduleId, securityUser); return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } @PostMapping(value = "{schedule-id}/like") - public ResponseEntity createScheduleLike(@PathVariable("schedule-id") Long scheduleId, - @RequestParam("userId") Long userId) { - scheduleService.createLike(scheduleId, userId); + public ResponseEntity createScheduleLike(@AuthenticationPrincipal SecurityUser securityUser, + @PathVariable("schedule-id") Long scheduleId) { + scheduleService.createLike(scheduleId, securityUser); return ResponseEntity.status(HttpStatus.CREATED).build(); } diff --git a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java index 4ea358b..6f2963f 100644 --- a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java +++ b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java @@ -153,8 +153,8 @@ public void createPhoto(Long scheduleId, Long dayId, List files) } @Transactional - public void createBookmark(Long scheduleId, Long userId) { - User findUser = userService.getVerifyUser(userId); + public void createBookmark(Long scheduleId, SecurityUser securityUser) { + User findUser = userService.getVerifyUser(securityUser.getMember().getUserId()); Schedule findSchedule = getSchedule(scheduleId); ScheduleBookmark scheduleBookmark = new ScheduleBookmark(findSchedule); findUser.addScheduleBookmark(scheduleBookmark); @@ -162,15 +162,15 @@ public void createBookmark(Long scheduleId, Long userId) { } @Transactional - public void deleteBookmark(Long scheduleId, Long userId) { - User findUser = userService.getVerifyUser(userId); + public void deleteBookmark(Long scheduleId, SecurityUser securityUser) { + User findUser = userService.getVerifyUser(securityUser.getMember().getUserId()); Schedule findSchedule = getSchedule(scheduleId); scheduleBookmarkRepository.deleteByUserAndSchedule(findUser, findSchedule); } @Transactional - public void createLike(Long scheduleId, Long userId) { - User findUser = userService.getVerifyUser(userId); + public void createLike(Long scheduleId, SecurityUser securityUser) { + User findUser = userService.getVerifyUser(securityUser.getMember().getUserId()); Schedule findSchedule = getSchedule(scheduleId); // 오늘의 시작 시간과 끝 시간을 구하기 From edfc7b55f92541dd82f12bf4dfbfc4ade5162e3b Mon Sep 17 00:00:00 2001 From: wjstmdduf Date: Thu, 23 Nov 2023 02:27:19 +0900 Subject: [PATCH 09/16] =?UTF-8?q?refactor=20:=20=EC=9C=A0=EC=A0=80=20?= =?UTF-8?q?=EC=9D=BC=EC=A0=95,=20=EC=9C=84=EC=8B=9C=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tgd/trip/schedule/dto/DayDto.java | 2 + .../schedule/dto/ScheduleBookmarkDto.java | 12 ++++ .../tgd/trip/schedule/dto/ScheduleDto.java | 2 + .../trip/schedule/mapper/ScheduleMapper.java | 2 + .../ScheduleBookmarkRepository.java | 1 + .../schedule/service/ScheduleService.java | 2 +- .../trip/user/controller/UserController.java | 46 +++++++-------- .../com/tgd/trip/user/mapper/UserMapper.java | 59 +++++++++++++++++++ .../trip/user/repository/UserRepository.java | 5 ++ .../tgd/trip/user/service/UserService.java | 26 +++++++- 10 files changed, 130 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/tgd/trip/schedule/dto/ScheduleBookmarkDto.java diff --git a/src/main/java/com/tgd/trip/schedule/dto/DayDto.java b/src/main/java/com/tgd/trip/schedule/dto/DayDto.java index ddbde7d..2f0845f 100644 --- a/src/main/java/com/tgd/trip/schedule/dto/DayDto.java +++ b/src/main/java/com/tgd/trip/schedule/dto/DayDto.java @@ -1,6 +1,7 @@ package com.tgd.trip.schedule.dto; import com.tgd.trip.attraction.dto.AttractionDto; +import lombok.Builder; import java.time.LocalDate; import java.util.List; @@ -12,6 +13,7 @@ public record Post(LocalDate date, List dayAttractions) { public record Patch(LocalDate date, List dayAttractions) { } + @Builder public record Response(Long dayId, LocalDate date, List attractions) { } diff --git a/src/main/java/com/tgd/trip/schedule/dto/ScheduleBookmarkDto.java b/src/main/java/com/tgd/trip/schedule/dto/ScheduleBookmarkDto.java new file mode 100644 index 0000000..6468404 --- /dev/null +++ b/src/main/java/com/tgd/trip/schedule/dto/ScheduleBookmarkDto.java @@ -0,0 +1,12 @@ +package com.tgd.trip.schedule.dto; + +import com.tgd.trip.user.dto.UserDto; +import lombok.Builder; + +import java.util.List; + +public class ScheduleBookmarkDto { + @Builder + public record SimpleResponse(Long scheduleBookmarkId, UserDto.SimpleResponse user, ScheduleDto.SimpleResponse schedule) { + } +} diff --git a/src/main/java/com/tgd/trip/schedule/dto/ScheduleDto.java b/src/main/java/com/tgd/trip/schedule/dto/ScheduleDto.java index 6466745..93b7a29 100644 --- a/src/main/java/com/tgd/trip/schedule/dto/ScheduleDto.java +++ b/src/main/java/com/tgd/trip/schedule/dto/ScheduleDto.java @@ -1,5 +1,6 @@ package com.tgd.trip.schedule.dto; +import com.tgd.trip.schedule.domain.Schedule; import com.tgd.trip.user.dto.UserDto; import lombok.Builder; @@ -27,4 +28,5 @@ public record SimpleResponse(Long scheduleId, String title, String content, Stri List days, UserDto.SimpleResponse user) { } + } diff --git a/src/main/java/com/tgd/trip/schedule/mapper/ScheduleMapper.java b/src/main/java/com/tgd/trip/schedule/mapper/ScheduleMapper.java index 3b74d8d..9b93b17 100644 --- a/src/main/java/com/tgd/trip/schedule/mapper/ScheduleMapper.java +++ b/src/main/java/com/tgd/trip/schedule/mapper/ScheduleMapper.java @@ -76,4 +76,6 @@ public List entityToCommentResponse(Schedule schedule) { comment.getModifiedAt())) .toList(); } + + } diff --git a/src/main/java/com/tgd/trip/schedule/repository/ScheduleBookmarkRepository.java b/src/main/java/com/tgd/trip/schedule/repository/ScheduleBookmarkRepository.java index 413e869..0c3ef4c 100644 --- a/src/main/java/com/tgd/trip/schedule/repository/ScheduleBookmarkRepository.java +++ b/src/main/java/com/tgd/trip/schedule/repository/ScheduleBookmarkRepository.java @@ -12,4 +12,5 @@ public interface ScheduleBookmarkRepository extends JpaRepository findAllByUser(User user); + } diff --git a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java index 2862181..4ea358b 100644 --- a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java +++ b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java @@ -128,7 +128,7 @@ public void deleteSchedule(Long id) { } public Page getSchedules(String keyword, String sort, Pageable pageable) { - Page schedules = scheduleRepository.findAllByTitleContainingAndViewYnNot(keyword, true, PageRequest.of(pageable.getPageNumber() - 1, pageable.getPageSize())); + Page schedules = scheduleRepository.findAllByTitleContainingAndViewYnNot(keyword, true, PageRequest.of(pageable.getPageNumber(), pageable.getPageSize())); return schedules; } diff --git a/src/main/java/com/tgd/trip/user/controller/UserController.java b/src/main/java/com/tgd/trip/user/controller/UserController.java index 06659d5..1025bc3 100644 --- a/src/main/java/com/tgd/trip/user/controller/UserController.java +++ b/src/main/java/com/tgd/trip/user/controller/UserController.java @@ -3,8 +3,15 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.tgd.trip.attraction.domain.Attraction; +import com.tgd.trip.attraction.dto.AttractionDto; +import com.tgd.trip.global.dto.PageResponse; import com.tgd.trip.jwt.JwtTokenProvider; import com.tgd.trip.schedule.domain.Schedule; +import com.tgd.trip.schedule.domain.ScheduleBookmark; +import com.tgd.trip.schedule.dto.ScheduleDto; +import com.tgd.trip.schedule.mapper.ScheduleMapper; +import com.tgd.trip.schedule.repository.ScheduleBookmarkRepository; +import com.tgd.trip.schedule.service.ScheduleService; import com.tgd.trip.security.SecurityUser; import com.tgd.trip.user.domain.User; import com.tgd.trip.user.dto.SignupDto; @@ -13,7 +20,6 @@ import com.tgd.trip.user.service.UserService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.crypto.password.PasswordEncoder; @@ -22,6 +28,8 @@ import java.util.List; +import static java.util.stream.Collectors.toList; + @RequiredArgsConstructor @RestController @RequestMapping("/api/user") @@ -31,6 +39,7 @@ public class UserController { private final JwtTokenProvider jwtTokenProvider; private final UserService userService; private final UserMapper userMapper; + @GetMapping("/signup") public ResponseEntity signup(@AuthenticationPrincipal SecurityUser securityUser) { System.out.println("회원가입 요청옴"); @@ -101,37 +110,26 @@ public ResponseEntity userDelete(@AuthenticationPrincipal SecurityUser securi @GetMapping("/userSchedule") public ResponseEntity userSchedule(@AuthenticationPrincipal SecurityUser securityUser) { - List userSchedule = null; - try { - Long userId = securityUser.getMember().getUserId(); - userSchedule = userService.userSchedule(userId); - }catch (Exception e){ - System.out.println("문제발생!!!!!!!!!!!!!!!"); + User verifyUser = userService.getVerifyUser(securityUser.getMember().getUserId()); + List responses = userMapper.entityToUserResponse(verifyUser); - e.printStackTrace(); - } - return ResponseEntity.ok(userSchedule); + return ResponseEntity.ok(responses); } - @GetMapping("/userWishSD") - public ResponseEntity userWishSD(@AuthenticationPrincipal SecurityUser securityUser) { - List userWishSD = null; - Long userId = securityUser.getMember().getUserId(); - if (securityUser.getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_USER"))){ - userWishSD = userService.userWishSD(userId); - } - return ResponseEntity.ok(userWishSD); + @GetMapping("/userWishSC") + public ResponseEntity userWishSC(@AuthenticationPrincipal SecurityUser securityUser) { + User verifyUser = userService.getVerifyUser(securityUser.getMember().getUserId()); + List result = userService.findScheduleBookmarkAllByUser(verifyUser); + return ResponseEntity.ok(result); } @GetMapping("/userWishAT") public ResponseEntity userWishAT(@AuthenticationPrincipal SecurityUser securityUser) { - List userWishAT = null; - Long userId = securityUser.getMember().getUserId(); + User verifyUser = userService.getVerifyUser(securityUser.getMember().getUserId()); + List result = userService.findAttractionBookmarkAllByUser(verifyUser); - if (securityUser.getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_USER"))){ - userWishAT = userService.userWishAT(userId); - } - return ResponseEntity.ok(userWishAT); + return ResponseEntity.ok(result); } + } diff --git a/src/main/java/com/tgd/trip/user/mapper/UserMapper.java b/src/main/java/com/tgd/trip/user/mapper/UserMapper.java index 99a649e..cabafd9 100644 --- a/src/main/java/com/tgd/trip/user/mapper/UserMapper.java +++ b/src/main/java/com/tgd/trip/user/mapper/UserMapper.java @@ -1,9 +1,16 @@ package com.tgd.trip.user.mapper; +import com.tgd.trip.attraction.domain.AttractionBookmark; +import com.tgd.trip.attraction.dto.AttractionDto; +import com.tgd.trip.schedule.domain.ScheduleBookmark; +import com.tgd.trip.schedule.dto.DayDto; +import com.tgd.trip.schedule.dto.ScheduleDto; import com.tgd.trip.user.domain.User; import com.tgd.trip.user.dto.UserDto; import org.springframework.stereotype.Component; +import java.util.List; + @Component public class UserMapper { public UserDto.Response entityToResponse(User user) { @@ -16,4 +23,56 @@ public UserDto.Response entityToResponse(User user) { .sex(user.getSex()) .build(); } + + public List entityToUserResponse(User user) { + return user.getSchedules().stream() + .map(schedule -> new ScheduleDto.SimpleResponse( + schedule.getScheduleId(), + schedule.getTitle(), + schedule.getContent(), + schedule.getImgUrl(), + schedule.getWishCount(), + schedule.getLikeCount(), + schedule.getDays().stream() + .map(day -> new DayDto.DateResponse(day.getDayId(), day.getDate())) + .toList(), + new UserDto.SimpleResponse( + user.getUserId(), + user.getNickName(), + user.getImgUrl(), + user.getBirth(), + user.getSex()) + )).toList(); + } + + public List entityToScheduleResponse(List responses) { + + return responses.stream().map(response -> + new ScheduleDto.SimpleResponse( + response.getSchedule().getScheduleId(), + response.getSchedule().getTitle(), + response.getSchedule().getContent(), + response.getSchedule().getImgUrl(), + response.getSchedule().getWishCount(), + response.getSchedule().getLikeCount(), + response.getSchedule().getDays().stream() + .map(day -> new DayDto.DateResponse(day.getDayId(), day.getDate())) + .toList(), + new UserDto.SimpleResponse( + response.getUser().getUserId(), + response.getUser().getNickName(), + response.getUser().getImgUrl(), + response.getUser().getBirth(), + response.getUser().getSex()) + )).toList(); + } + + public List entityToAttractionResponse(List responses) { + + return responses.stream().map(response -> + new AttractionDto.Response( + response.getAttraction() + )).toList(); + } + } diff --git a/src/main/java/com/tgd/trip/user/repository/UserRepository.java b/src/main/java/com/tgd/trip/user/repository/UserRepository.java index 1e0fce1..ae1a342 100644 --- a/src/main/java/com/tgd/trip/user/repository/UserRepository.java +++ b/src/main/java/com/tgd/trip/user/repository/UserRepository.java @@ -1,11 +1,16 @@ package com.tgd.trip.user.repository; +import com.tgd.trip.schedule.domain.Schedule; import com.tgd.trip.user.domain.User; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; public interface UserRepository extends JpaRepository { Optional findByEmail(String email); + + List findAllSchedulesByUserId(Long userId); + } diff --git a/src/main/java/com/tgd/trip/user/service/UserService.java b/src/main/java/com/tgd/trip/user/service/UserService.java index de0f477..480ed45 100644 --- a/src/main/java/com/tgd/trip/user/service/UserService.java +++ b/src/main/java/com/tgd/trip/user/service/UserService.java @@ -2,11 +2,13 @@ import com.tgd.trip.attraction.domain.Attraction; import com.tgd.trip.attraction.domain.AttractionBookmark; +import com.tgd.trip.attraction.dto.AttractionDto; import com.tgd.trip.attraction.repository.AttractionBookmarkRepository; import com.tgd.trip.global.s3.S3Uploader; import com.tgd.trip.jwt.JwtTokenProvider; import com.tgd.trip.schedule.domain.Schedule; import com.tgd.trip.schedule.domain.ScheduleBookmark; +import com.tgd.trip.schedule.dto.ScheduleDto; import com.tgd.trip.schedule.repository.ScheduleBookmarkRepository; import com.tgd.trip.schedule.repository.ScheduleRepository; import com.tgd.trip.user.domain.Role; @@ -14,6 +16,7 @@ import com.tgd.trip.user.domain.UserStatus; import com.tgd.trip.user.dto.SignupDto; import com.tgd.trip.user.dto.UserDto; +import com.tgd.trip.user.mapper.UserMapper; import com.tgd.trip.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -30,12 +33,14 @@ public class UserService { private final UserRepository userRepository; - private final ScheduleRepository scheduleRepository; + private final UserMapper userMapper; + private final ScheduleBookmarkRepository scheduleBookmarkRepository; private final AttractionBookmarkRepository attractionBookmarkRepository; private final S3Uploader s3Uploader; private final JwtTokenProvider provider; + public User getVerifyUser(String email) { return userRepository.findByEmail(email).orElseThrow(); } @@ -102,7 +107,7 @@ public void createUser(User user) { public List userSchedule(Long userId) { User user = userRepository.findById(userId).orElseThrow(() -> new RuntimeException("User not found")); - return scheduleRepository.findAllByUser(user); + return null; } public List userWishSD(Long userId) { @@ -149,4 +154,21 @@ public void userDelete(User member) { member.setImgUrl(""); userRepository.save(member); } + + public List findScheduleBookmarkAllByUser(User user) { + List responses = null; + + responses = scheduleBookmarkRepository.findAllByUser(user); + + return userMapper.entityToScheduleResponse(responses); + } + + public List findAttractionBookmarkAllByUser(User user) { + List responses = null; + + responses = attractionBookmarkRepository.findAllByUser(user); + + return userMapper.entityToAttractionResponse(responses); + } + } From ac43d11efe33f7d993235ae8ac18aa38b71ce208 Mon Sep 17 00:00:00 2001 From: zqwz Date: Thu, 23 Nov 2023 02:43:04 +0900 Subject: [PATCH 10/16] =?UTF-8?q?fix=20:=20=EB=B6=81=EB=A7=88=ED=81=AC=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tgd/trip/schedule/service/ScheduleService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java index 6f2963f..d3f2f26 100644 --- a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java +++ b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java @@ -156,6 +156,9 @@ public void createPhoto(Long scheduleId, Long dayId, List files) public void createBookmark(Long scheduleId, SecurityUser securityUser) { User findUser = userService.getVerifyUser(securityUser.getMember().getUserId()); Schedule findSchedule = getSchedule(scheduleId); + if (!findSchedule.getUser().getEmail().equals(findUser.getEmail())) { + throw new CustomException(ErrorCode.DIFFERENT_USER); + } ScheduleBookmark scheduleBookmark = new ScheduleBookmark(findSchedule); findUser.addScheduleBookmark(scheduleBookmark); scheduleBookmarkRepository.save(scheduleBookmark); @@ -165,6 +168,9 @@ public void createBookmark(Long scheduleId, SecurityUser securityUser) { public void deleteBookmark(Long scheduleId, SecurityUser securityUser) { User findUser = userService.getVerifyUser(securityUser.getMember().getUserId()); Schedule findSchedule = getSchedule(scheduleId); + if (!findSchedule.getUser().getEmail().equals(findUser.getEmail())) { + throw new CustomException(ErrorCode.DIFFERENT_USER); + } scheduleBookmarkRepository.deleteByUserAndSchedule(findUser, findSchedule); } From 8fba32b257a78f93da1ba58690ba5acb3bbba56a Mon Sep 17 00:00:00 2001 From: zqwz Date: Thu, 23 Nov 2023 02:52:52 +0900 Subject: [PATCH 11/16] =?UTF-8?q?feat=20:=20=EB=B6=81=EB=A7=88=ED=81=AC=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tgd/trip/global/exception/ErrorCode.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tgd/trip/global/exception/ErrorCode.java b/src/main/java/com/tgd/trip/global/exception/ErrorCode.java index 2473a98..d76bf28 100644 --- a/src/main/java/com/tgd/trip/global/exception/ErrorCode.java +++ b/src/main/java/com/tgd/trip/global/exception/ErrorCode.java @@ -12,8 +12,9 @@ public enum ErrorCode { ATTRACTION_NOT_FOUND(HttpStatus.NOT_FOUND, "관광지가 존재하지 않습니다."), COMMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "댓글이 존재하지 않습니다."), DIFFERENT_USER(HttpStatus.FORBIDDEN, "같은 사용자가 아닙니다."), - TOO_MANY_LIKES(HttpStatus.TOO_MANY_REQUESTS, "이미 좋아요를 했습니다."), - USER_NOT_FOUND(HttpStatus.NOT_FOUND, "사용자가 존재하지 않습니다."); + TOO_MANY_LIKES(HttpStatus.CONFLICT, "이미 좋아요를 했습니다."), + USER_NOT_FOUND(HttpStatus.NOT_FOUND, "사용자가 존재하지 않습니다."), + ALREADY_BOOKMARKED_SCHEDULE(HttpStatus.CONFLICT, "이미 북마크된 스케줄입니다."); private final HttpStatus httpStatus; private final String message; From 5a408a2bb7a73a60785728efcde86f0800904d33 Mon Sep 17 00:00:00 2001 From: zqwz Date: Thu, 23 Nov 2023 02:53:41 +0900 Subject: [PATCH 12/16] =?UTF-8?q?feat=20:=20=EC=8A=A4=EC=BC=80=EC=A4=84=20?= =?UTF-8?q?=EB=B6=81=EB=A7=88=ED=81=AC=20=EC=A1=B4=EC=9E=AC=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trip/schedule/repository/ScheduleBookmarkRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/tgd/trip/schedule/repository/ScheduleBookmarkRepository.java b/src/main/java/com/tgd/trip/schedule/repository/ScheduleBookmarkRepository.java index 0c3ef4c..2fc2691 100644 --- a/src/main/java/com/tgd/trip/schedule/repository/ScheduleBookmarkRepository.java +++ b/src/main/java/com/tgd/trip/schedule/repository/ScheduleBookmarkRepository.java @@ -11,6 +11,9 @@ public interface ScheduleBookmarkRepository extends JpaRepository { void deleteByUserAndSchedule(User user, Schedule schedule); + + boolean existsScheduleBookmarkByUserAndSchedule(User user, Schedule schedule); + List findAllByUser(User user); } From 4220504bb1ad0a043277bb13a23bcf02c59c36fe Mon Sep 17 00:00:00 2001 From: zqwz Date: Thu, 23 Nov 2023 02:53:50 +0900 Subject: [PATCH 13/16] =?UTF-8?q?feat=20:=20=EC=8A=A4=EC=BC=80=EC=A4=84=20?= =?UTF-8?q?=EB=B6=81=EB=A7=88=ED=81=AC=20=EC=A1=B4=EC=9E=AC=20=EC=97=AC?= =?UTF-8?q?=EB=B6=80=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tgd/trip/schedule/service/ScheduleService.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java index d3f2f26..378cd50 100644 --- a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java +++ b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java @@ -156,8 +156,8 @@ public void createPhoto(Long scheduleId, Long dayId, List files) public void createBookmark(Long scheduleId, SecurityUser securityUser) { User findUser = userService.getVerifyUser(securityUser.getMember().getUserId()); Schedule findSchedule = getSchedule(scheduleId); - if (!findSchedule.getUser().getEmail().equals(findUser.getEmail())) { - throw new CustomException(ErrorCode.DIFFERENT_USER); + if(scheduleBookmarkRepository.existsScheduleBookmarkByUserAndSchedule(findUser, findSchedule)){ + throw new CustomException(ErrorCode.ALREADY_BOOKMARKED_SCHEDULE); } ScheduleBookmark scheduleBookmark = new ScheduleBookmark(findSchedule); findUser.addScheduleBookmark(scheduleBookmark); @@ -168,9 +168,6 @@ public void createBookmark(Long scheduleId, SecurityUser securityUser) { public void deleteBookmark(Long scheduleId, SecurityUser securityUser) { User findUser = userService.getVerifyUser(securityUser.getMember().getUserId()); Schedule findSchedule = getSchedule(scheduleId); - if (!findSchedule.getUser().getEmail().equals(findUser.getEmail())) { - throw new CustomException(ErrorCode.DIFFERENT_USER); - } scheduleBookmarkRepository.deleteByUserAndSchedule(findUser, findSchedule); } From 220aedb49bb4f907f84917987524a42bb6346936 Mon Sep 17 00:00:00 2001 From: zini9188 Date: Fri, 24 Nov 2023 08:44:47 +0900 Subject: [PATCH 14/16] =?UTF-8?q?refactor=20:=20=EC=A0=95=EB=A0=AC=20?= =?UTF-8?q?=EC=88=9C=EC=84=9C=20=EB=B0=94=EA=BE=B8=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tgd/trip/schedule/service/ScheduleService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java index 378cd50..fa2e835 100644 --- a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java +++ b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java @@ -128,7 +128,8 @@ public void deleteSchedule(Long id) { } public Page getSchedules(String keyword, String sort, Pageable pageable) { - Page schedules = scheduleRepository.findAllByTitleContainingAndViewYnNot(keyword, true, PageRequest.of(pageable.getPageNumber(), pageable.getPageSize())); + Page schedules = scheduleRepository + .findAllByTitleContainingAndViewYnNot(keyword, true, PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("created_at").descending())); return schedules; } From c968ded6b5d89694370541cb321f5ee213aa44c1 Mon Sep 17 00:00:00 2001 From: zini9188 Date: Fri, 24 Nov 2023 08:52:14 +0900 Subject: [PATCH 15/16] =?UTF-8?q?fix=20:=20=EC=A0=95=EB=A0=AC=20=EC=86=8D?= =?UTF-8?q?=EC=84=B1=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tgd/trip/schedule/service/ScheduleService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java index fa2e835..44e789f 100644 --- a/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java +++ b/src/main/java/com/tgd/trip/schedule/service/ScheduleService.java @@ -129,7 +129,8 @@ public void deleteSchedule(Long id) { public Page getSchedules(String keyword, String sort, Pageable pageable) { Page schedules = scheduleRepository - .findAllByTitleContainingAndViewYnNot(keyword, true, PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("created_at").descending())); + .findAllByTitleContainingAndViewYnNot(keyword, true, PageRequest.of(pageable.getPageNumber(), + pageable.getPageSize(), Sort.by("createdAt").descending())); return schedules; } From b87df1a8de44acbd20cb70f1b6dc61af851aa148 Mon Sep 17 00:00:00 2001 From: zini9188 Date: Fri, 24 Nov 2023 08:55:10 +0900 Subject: [PATCH 16/16] =?UTF-8?q?docs=20:=20readme=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f71a550..ac95804 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ - Spring Framework 2.7.16 - Java 17 -- aws ec2 instance : ubuntu +- AWS EC2 ### 실행 순서 @@ -23,6 +23,7 @@ $ git submodule update --remote --merge # build.gralde에 아래 내용 없으면 추가 # ./security에서 src/main/resouces로 폴더 copy +``` processResources.dependsOn('copySecret') tasks.register('copySecret', Copy) { from './security'