Skip to content

Commit

Permalink
Merge pull request #64 from DSM-Repo/feedback-confirm-service
Browse files Browse the repository at this point in the history
pr: 피드백 수락 API 추가
  • Loading branch information
dkflfkd53 authored Aug 17, 2024
2 parents 9bc7733 + a3f6712 commit be17f17
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.example.whopper.domain.feedback.api;

import com.example.whopper.domain.feedback.application.usecase.AddFeedbackUseCase;
import com.example.whopper.domain.feedback.application.usecase.DeleteFeedbackUseCase;
import com.example.whopper.domain.feedback.application.usecase.FindFeedbackUseCase;
import com.example.whopper.domain.feedback.application.usecase.UpdateFeedbackUseCase;
import com.example.whopper.domain.feedback.application.usecase.*;
import com.example.whopper.domain.feedback.dto.FeedbackRequest;
import com.example.whopper.domain.feedback.dto.FeedbackResponse;
import com.example.whopper.domain.feedback.dto.UpdateFeedbackRequest;
Expand All @@ -26,6 +23,14 @@ public class FeedbackController {

private final FindFeedbackUseCase findFeedbackUseCase;

private final ConfirmFeedbackUseCase confirmFeedbackUseCase;

@OnlyStudent
@PostMapping("/{feedbackId}")
public void confirm(@PathVariable String feedbackId) {
confirmFeedbackUseCase.confirm(feedbackId);
}

@OnlyStudent
@GetMapping
public DataResponseInfo<FeedbackResponse> getMyFeedbackList() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.whopper.domain.feedback.application.impl;

import com.example.whopper.domain.feedback.application.usecase.ConfirmFeedbackUseCase;
import com.example.whopper.domain.feedback.dao.FeedbackMongoRepository;
import com.example.whopper.domain.feedback.exception.FeedbackNotFoundException;
import com.example.whopper.global.error.exception.ForbiddenException;
import com.example.whopper.global.utils.current.CurrentStudent;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ConfirmFeedbackService implements ConfirmFeedbackUseCase {
private final FeedbackMongoRepository feedbackMongoRepository;
private final CurrentStudent currentStudent;

@Override
public void confirm(String id) {
var feedback = feedbackMongoRepository.findById(id)
.orElseThrow(() -> FeedbackNotFoundException.EXCEPTION);

var currentDocument = currentStudent.getDocument();

if (!currentDocument.getId().equals(feedback.getDocumentId())) {
throw ForbiddenException.EXCEPTION;
}

feedback.confirmed();
feedbackMongoRepository.save(feedback);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.whopper.domain.feedback.application.usecase;

public interface ConfirmFeedbackUseCase {
void confirm(String id);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.example.whopper.domain.feedback.domain;

import com.example.whopper.domain.document.domain.DocumentEntity;
import com.example.whopper.domain.document.domain.element.type.DocumentElementType;
import lombok.Builder;
import lombok.Getter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

@Getter
Expand All @@ -19,15 +17,27 @@ public class FeedbackEntity {

private String documentId;

private Status status;

@Builder
public FeedbackEntity(String comment, String writerName, DocumentElementType type, String documentId) {
this.comment = comment;
this.writerName = writerName;
this.type = type;
this.documentId = documentId;
status = Status.PENDING;
}

public void updateFeedback(String comment) {
this.comment = comment;
}

public void confirmed() {
status = Status.CONFIRMED;
}

enum Status {
CONFIRMED,
PENDING
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.example.whopper.domain.feedback.dto;

import com.example.whopper.domain.document.domain.DocumentEntity;
import com.example.whopper.domain.document.domain.element.type.DocumentElementType;
import com.example.whopper.domain.feedback.domain.FeedbackEntity;

public record FeedbackResponse(
String id,
DocumentElementType type,
String comment
String comment,
String status
) {
public FeedbackResponse(FeedbackEntity feedback) {
this(feedback.getId(), feedback.getType(), feedback.getComment());
this(feedback.getId(), feedback.getType(), feedback.getComment(), String.valueOf(feedback.getStatus()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.example.whopper.domain.major.application.usecase.AddMajorUseCase;
import com.example.whopper.domain.major.dao.MajorRepository;
import com.example.whopper.domain.major.domain.MajorEntity;
import com.example.whopper.domain.major.exception.AlreadyExistsMajorNameException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum ErrorCode {

FORBIDDEN(403, "접근 권한이 없는 유저입니다."),

// auth
PASSWORD_MISMATCH(401, "비밀번호가 일치하지 않습니다."),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.whopper.global.error.exception;

public class ForbiddenException extends WhopperException {
public static final WhopperException EXCEPTION = new ForbiddenException();

private ForbiddenException() {
super(ErrorCode.FORBIDDEN);
}
}

0 comments on commit be17f17

Please sign in to comment.