Skip to content

Commit

Permalink
feat & fix: add api to get feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
aiaiaiai1 committed Sep 3, 2024
1 parent 0272ebd commit 3db8e65
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 18 deletions.
32 changes: 32 additions & 0 deletions src/main/java/gymmi/controller/FeedbackController.java
Original file line number Diff line number Diff line change
@@ -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<Void> feedback(
@Logined User user,
@RequestBody FeedbackRequest request
) {
Feedback feedback = new Feedback(user, request.getContent());
feedbackRepository.save(feedback);
return ResponseEntity.ok().build();
}


}
27 changes: 27 additions & 0 deletions src/main/java/gymmi/entity/Feedback.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions src/main/java/gymmi/entity/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/gymmi/exception/ExceptionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ public ResponseEntity<ErrorResponse> handle500Exception(GymmiException e, HttpSe
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}

@ExceptionHandler
public ResponseEntity<ErrorResponse> 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<ErrorResponse> 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() +
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/gymmi/repository/FeedbackRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gymmi.repository;

import gymmi.entity.Feedback;
import org.springframework.data.jpa.repository.JpaRepository;

public interface FeedbackRepository extends JpaRepository<Feedback, Long> {

}
15 changes: 15 additions & 0 deletions src/main/java/gymmi/request/FeedbackRequest.java
Original file line number Diff line number Diff line change
@@ -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;

}
6 changes: 5 additions & 1 deletion src/main/java/gymmi/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
}
}
13 changes: 10 additions & 3 deletions src/main/java/gymmi/service/WorkspaceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -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<Worker> sortedWorkers = workerRepository.getAllByWorkspaceIdOrderByContributedScore(workspaceId);

List<Integer> workerRanks = rankTied(sortedWorkers);

int achievementScore = workspaceRepository.getAchievementScore(workspaceId);

List<Worker> 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();
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/gymmi/integration/WorkspaceIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));

}

Expand Down

0 comments on commit 3db8e65

Please sign in to comment.