From 3db8e6507cd9c8d7e222f47bd1f6deba8850d768 Mon Sep 17 00:00:00 2001 From: aiaiaiai1 Date: Tue, 3 Sep 2024 19:53:23 +0900 Subject: [PATCH] feat & fix: add api to get feedback --- .../gymmi/controller/FeedbackController.java | 32 +++++++++++++++++++ src/main/java/gymmi/entity/Feedback.java | 27 ++++++++++++++++ src/main/java/gymmi/entity/Worker.java | 2 ++ .../gymmi/exception/ExceptionController.java | 20 ++++++------ .../gymmi/repository/FeedbackRepository.java | 8 +++++ .../java/gymmi/request/FeedbackRequest.java | 15 +++++++++ src/main/java/gymmi/service/AuthService.java | 6 +++- .../java/gymmi/service/WorkspaceService.java | 13 ++++++-- .../integration/WorkspaceIntegrationTest.java | 8 ++--- 9 files changed, 113 insertions(+), 18 deletions(-) create mode 100644 src/main/java/gymmi/controller/FeedbackController.java create mode 100644 src/main/java/gymmi/entity/Feedback.java create mode 100644 src/main/java/gymmi/repository/FeedbackRepository.java create mode 100644 src/main/java/gymmi/request/FeedbackRequest.java diff --git a/src/main/java/gymmi/controller/FeedbackController.java b/src/main/java/gymmi/controller/FeedbackController.java new file mode 100644 index 0000000..ea8db3d --- /dev/null +++ b/src/main/java/gymmi/controller/FeedbackController.java @@ -0,0 +1,32 @@ +package gymmi.controller; + +import gymmi.entity.Feedback; +import gymmi.entity.User; +import gymmi.global.Logined; +import gymmi.repository.FeedbackRepository; +import gymmi.request.FeedbackRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class FeedbackController { + + private final FeedbackRepository feedbackRepository; + + + @PostMapping("/feedback") + public ResponseEntity feedback( + @Logined User user, + @RequestBody FeedbackRequest request + ) { + Feedback feedback = new Feedback(user, request.getContent()); + feedbackRepository.save(feedback); + return ResponseEntity.ok().build(); + } + + +} diff --git a/src/main/java/gymmi/entity/Feedback.java b/src/main/java/gymmi/entity/Feedback.java new file mode 100644 index 0000000..85d10cd --- /dev/null +++ b/src/main/java/gymmi/entity/Feedback.java @@ -0,0 +1,27 @@ +package gymmi.entity; + +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Feedback { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @JoinColumn(name = "user_id", nullable = false, updatable = false) + @ManyToOne(fetch = FetchType.LAZY) + private User user; + + @Lob + @Column(nullable = false) + private String content; + + public Feedback(User user, String content) { + this.user = user; + this.content = content; + } +} diff --git a/src/main/java/gymmi/entity/Worker.java b/src/main/java/gymmi/entity/Worker.java index c0cd57f..3cec99d 100644 --- a/src/main/java/gymmi/entity/Worker.java +++ b/src/main/java/gymmi/entity/Worker.java @@ -15,11 +15,13 @@ import java.time.LocalDateTime; import lombok.AccessLevel; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @Table(uniqueConstraints = {@UniqueConstraint(columnNames = {"user_id", "workspace_id"})}) +@EqualsAndHashCode(of = {"id"}) public class Worker { @Id diff --git a/src/main/java/gymmi/exception/ExceptionController.java b/src/main/java/gymmi/exception/ExceptionController.java index 3ad1a83..0e81845 100644 --- a/src/main/java/gymmi/exception/ExceptionController.java +++ b/src/main/java/gymmi/exception/ExceptionController.java @@ -56,16 +56,16 @@ public ResponseEntity handle500Exception(GymmiException e, HttpSe return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } - @ExceptionHandler - public ResponseEntity handle500Exception( - Exception e, - HttpServletRequest request, - HttpServletResponse resp - ) { - ErrorResponse response = new ErrorResponse("ERROR", e.getMessage()); - log(e, request.getRequestURI()); - return ResponseEntity.status(500).body(response); - } +// @ExceptionHandler +// public ResponseEntity handle500Exception( +// Exception e, +// HttpServletRequest request, +// HttpServletResponse resp +// ) { +// ErrorResponse response = new ErrorResponse("ERROR", e.getMessage()); +// log(e, request.getRequestURI()); +// return ResponseEntity.status(500).body(response); +// } private void log(Exception e, String requestURI) { log.warn(System.lineSeparator() + diff --git a/src/main/java/gymmi/repository/FeedbackRepository.java b/src/main/java/gymmi/repository/FeedbackRepository.java new file mode 100644 index 0000000..c29e83d --- /dev/null +++ b/src/main/java/gymmi/repository/FeedbackRepository.java @@ -0,0 +1,8 @@ +package gymmi.repository; + +import gymmi.entity.Feedback; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FeedbackRepository extends JpaRepository { + +} diff --git a/src/main/java/gymmi/request/FeedbackRequest.java b/src/main/java/gymmi/request/FeedbackRequest.java new file mode 100644 index 0000000..ff95b2a --- /dev/null +++ b/src/main/java/gymmi/request/FeedbackRequest.java @@ -0,0 +1,15 @@ +package gymmi.request; + + +import jakarta.validation.constraints.NotBlank; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class FeedbackRequest { + + @NotBlank + private String content; + +} diff --git a/src/main/java/gymmi/service/AuthService.java b/src/main/java/gymmi/service/AuthService.java index 19f3f2b..a37de47 100644 --- a/src/main/java/gymmi/service/AuthService.java +++ b/src/main/java/gymmi/service/AuthService.java @@ -26,6 +26,8 @@ public class AuthService { private final TokenProcessor tokenProcessor; private final UserRepository userRepository; private final LoginedRepository loginedRepository; + private final ProfileImageRepository profileImageRepository; + private final ImageFileUploader imageFileUploader; @Transactional public void registerUser(RegistrationRequest request) { @@ -98,6 +100,8 @@ public void resign(User loginedUser, ResignRequest request) { throw new NotMatchedException("비밀번호가 일치하지 않습니다."); } loginedUser.resign(); - // 프로필사진 지우기 + ProfileImage profileImage = profileImageRepository.getByUserId(loginedUser.getId()); + profileImageRepository.delete(profileImage); + imageFileUploader.delete(profileImage.getStoredName()); } } diff --git a/src/main/java/gymmi/service/WorkspaceService.java b/src/main/java/gymmi/service/WorkspaceService.java index 113879c..b0b0585 100644 --- a/src/main/java/gymmi/service/WorkspaceService.java +++ b/src/main/java/gymmi/service/WorkspaceService.java @@ -17,6 +17,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Queue; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -226,18 +227,24 @@ private void deleteTaskAndWorker(User loginedUser, Long workspaceId) { } public InsideWorkspaceResponse enterWorkspace(User logiendUser, Long workspaceId) { - validateIfWorkerIsInWorkspace(logiendUser.getId(), workspaceId); + Worker worker = validateIfWorkerIsInWorkspace(logiendUser.getId(), workspaceId); Workspace workspace = workspaceRepository.getWorkspaceById(workspaceId); List sortedWorkers = workerRepository.getAllByWorkspaceIdOrderByContributedScore(workspaceId); - List workerRanks = rankTied(sortedWorkers); + int achievementScore = workspaceRepository.getAchievementScore(workspaceId); + List workers = sortedWorkers.stream() + .filter(w -> (!w.equals(worker))) + .collect(Collectors.toList()); + workers.add(0, worker); + + // 랭크 로직은 수정해야할듯. return InsideWorkspaceResponse.builder() .workspace(workspace) .achievementScore(achievementScore) - .sortedWorkers(sortedWorkers) + .sortedWorkers(workers) .workerRanks(workerRanks) .loginedUser(logiendUser) .build(); diff --git a/src/test/java/gymmi/integration/WorkspaceIntegrationTest.java b/src/test/java/gymmi/integration/WorkspaceIntegrationTest.java index 0c1de3f..02ab940 100644 --- a/src/test/java/gymmi/integration/WorkspaceIntegrationTest.java +++ b/src/test/java/gymmi/integration/WorkspaceIntegrationTest.java @@ -572,10 +572,10 @@ class 워크스페이스_나가기 { .statusCode(200) .body("workers[0].rank", Matchers.equalTo(1)) .body("workers[1].rank", Matchers.equalTo(1)) - .body("workers[0].isCreator", Matchers.equalTo(true)) - .body("workers[1].isCreator", Matchers.equalTo(false)) - .body("workers[0].isMyself", Matchers.equalTo(false)) - .body("workers[1].isMyself", Matchers.equalTo(true)); + .body("workers[0].isCreator", Matchers.equalTo(false)) + .body("workers[1].isCreator", Matchers.equalTo(true)) + .body("workers[0].isMyself", Matchers.equalTo(true)) + .body("workers[1].isMyself", Matchers.equalTo(false)); }