Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] - {FEEDBACK} 공용 ApiResponse, 피드백 컨트롤러 테스트 및 기능 구현 #15

Merged
merged 5 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/main/java/com/loveloveshot/common/response/ApiResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.loveloveshot.common.response;

import com.loveloveshot.common.response.enumtype.ApiStatus;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;

@Getter
@AllArgsConstructor
@EqualsAndHashCode
public class ApiResponse {
private ApiStatus status;
private String message;
private Object data;

public static ApiResponse success(String message, Object data) {
return new ApiResponse(ApiStatus.SUCCESS, message, data);
}

public static ApiResponse error(String message) {
return new ApiResponse(ApiStatus.ERROR, message, null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.loveloveshot.common.response.enumtype;

public enum ApiStatus {
SUCCESS,
ERROR
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.loveloveshot.feedback.command.application.controller;

import com.loveloveshot.common.response.ApiResponse;
import com.loveloveshot.feedback.command.application.dto.request.FeedbackRequest;
import com.loveloveshot.feedback.command.application.service.FeedbackCommandService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/v1/feedbacks")
public class FeedbackCommandController {
private final FeedbackCommandService feedbackCommandService;

@PostMapping
public ApiResponse createFeedback(FeedbackRequest feedbackRequest) {
return ApiResponse.success("성공적으로 제출되었습니다."
, feedbackCommandService.createFeedback(feedbackRequest));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FeedbackCommandService {
private final FeedbackCommandRepository feedbackCommandRepository;

@Transactional
public FeedbackResponse submitFeedback(FeedbackRequest feedbackRequest) {
public FeedbackResponse createFeedback(FeedbackRequest feedbackRequest) {
Feedback feedback = new Feedback.Builder()
.feedbackContent(feedbackRequest.getFeedbackContent())
.build();
Expand All @@ -26,5 +26,5 @@ public FeedbackResponse submitFeedback(FeedbackRequest feedbackRequest) {
savedFeedback.getFeedbackContent()
);
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
package com.loveloveshot.feedback.command.application.controller;

import com.loveloveshot.common.response.ApiResponse;
import com.loveloveshot.feedback.command.application.dto.request.FeedbackRequest;
import com.loveloveshot.feedback.command.domain.aggregate.entity.Feedback;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

@SpringBootTest
@Transactional
public class FeedbackCommandControllerTest {
}
FeedbackRequest feedbackRequest = new FeedbackRequest();

@Autowired
private FeedbackCommandController feedbackCommandController;

@BeforeEach
public void setUp() {
Feedback feedback = new Feedback.Builder()
.feedbackContent("정말 훌륭합니다.")
.build();

feedbackRequest.setFeedbackContent(feedback.getFeedbackContent());
}

@Test
@DisplayName("피드백 제출 테스트 : success")
void createFeedbackTest() {
ApiResponse apiResponse = feedbackCommandController
.createFeedback(feedbackRequest);

Assertions.assertEquals("SUCCESS"
, apiResponse.getStatus().toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void setUp() {
void submitFeedbackTest() {
long before = feedbackCommandRepository.count();

feedbackCommandService.submitFeedback(feedbackRequest);
feedbackCommandService.createFeedback(feedbackRequest);

long after = feedbackCommandRepository.count();

Expand Down
Loading