Skip to content

Commit

Permalink
목표 및 주제 전체 조회 기능 구현 및 테스트 완료 (#103)
Browse files Browse the repository at this point in the history
* feat: [#101] Goal 전체 조회 기능 구현 및 테스트 완료

``

* feat: [#101] Subject 전체 조회 기능 구현 및 테스트 완료
  • Loading branch information
nathan29849 authored Feb 8, 2023
1 parent 53ecc0a commit 5b4cf73
Show file tree
Hide file tree
Showing 23 changed files with 412 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public enum ResponseCodeAndMessages implements CodeAndMessages {
FIND_DETAIL_ASSIGNMENT_SUCCESS("S-A003", "과제 개별 조회를 성공했습니다."),
MODIFY_ASSIGNMENT_SUCCESS("S-A004", "과제 수정을 성공했습니다"),
DELETE_ASSIGNMENT_SUCCESS("S-A005", "과제 삭제를 성공했습니다"),

/**
* Goal & Subject
*/
FIND_ALL_GOALS_SUCCESS("S-GS001", "목표 조회를 성공했습니다."),
FIND_ALL_SUBJECTS_SUCCESS("S-GS002", "주제 조회를 성공했습니다."),
;

private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ public class SubjectResponse {

private final Long subjectId;
private final String content;
private final String image;

private SubjectResponse(Long subjectId, String content) {
private SubjectResponse(Long subjectId, String content, String image) {
this.subjectId = subjectId;
this.content = content;
this.image = image;
}

public static SubjectResponse of(Subject subject) {
return new SubjectResponse(subject.getId(), subject.getContent());
return new SubjectResponse(
subject.getId(),
subject.getContent(),
subject.getImage()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.be.core.application.member;

import com.example.be.core.application.dto.response.GoalResponse;
import com.example.be.core.domain.member.goal.Goal;
import com.example.be.core.repository.member.goal.GoalRepository;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
public class GoalService {

private final GoalRepository goalRepository;

public GoalService(GoalRepository goalRepository) {
this.goalRepository = goalRepository;
}


public List<GoalResponse> findAll() {

List<Goal> goals = goalRepository.findAll();
return goals.stream()
.map(GoalResponse::of)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.be.core.application;
package com.example.be.core.application.member;

import static com.example.be.core.domain.member.grade.SpeakingGradeType.GIVER;
import static com.example.be.core.domain.member.grade.SpeakingGradeType.LEARNER;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.be.core.application.member;

import com.example.be.core.application.dto.response.SubjectResponse;
import com.example.be.core.domain.member.subject.Subject;
import com.example.be.core.repository.member.subject.SubjectRepository;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
public class SubjectService {

private final SubjectRepository subjectRepository;

public SubjectService(SubjectRepository subjectRepository) {
this.subjectRepository = subjectRepository;
}

public List<SubjectResponse> findAll() {
List<Subject> subjects = subjectRepository.findAll();
return subjects.stream()
.map(SubjectResponse::of)
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import lombok.AccessLevel;
import lombok.Getter;
Expand All @@ -21,8 +20,11 @@ public class Subject {

private String content;

public Subject(Long id, String content) {
private String image;

public Subject(Long id, String content, String image) {
this.id = id;
this.content = content;
this.image = image;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.be.core.web.member;

import static com.example.be.common.response.ResponseCodeAndMessages.FIND_ALL_GOALS_SUCCESS;

import com.example.be.common.response.BaseResponse;
import com.example.be.core.application.member.GoalService;
import com.example.be.core.application.dto.response.GoalResponse;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goal")
public class GoalController {

private final GoalService goalService;

public GoalController(GoalService goalService) {
this.goalService = goalService;
}

@GetMapping
@ApiOperation(value = "목표 전체 조회입니다.")
public BaseResponse<List<GoalResponse>> findAll() {
List<GoalResponse> response = goalService.findAll();
return new BaseResponse<>(FIND_ALL_GOALS_SUCCESS, response);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.be.core.web;
package com.example.be.core.web.member;

import static com.example.be.common.response.ResponseCodeAndMessages.CANCEL_FOLLOW_MEMBER_SUCCESS;
import static com.example.be.common.response.ResponseCodeAndMessages.FIND_MEMBER_INFO_SUCCESS;
Expand All @@ -7,7 +7,7 @@
import static com.example.be.common.response.ResponseCodeAndMessages.SIGN_UP_MEMBER_SUCCESS;

import com.example.be.common.response.BaseResponse;
import com.example.be.core.application.MemberService;
import com.example.be.core.application.member.MemberService;
import com.example.be.core.application.dto.request.MemberModifyRequest;
import com.example.be.core.application.dto.request.MemberSignUpRequest;
import com.example.be.core.application.dto.response.FollowResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.be.core.web.member;

import static com.example.be.common.response.ResponseCodeAndMessages.FIND_ALL_SUBJECTS_SUCCESS;

import com.example.be.common.response.BaseResponse;
import com.example.be.core.application.dto.response.SubjectResponse;
import com.example.be.core.application.member.SubjectService;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/subject")
public class SubjectController {

private final SubjectService subjectService;

public SubjectController(SubjectService subjectService) {
this.subjectService = subjectService;
}

@GetMapping
@ApiOperation(value = "주제 전체 조회입니다.")
public BaseResponse<List<SubjectResponse>> findAll() {
List<SubjectResponse> response = subjectService.findAll();
return new BaseResponse<>(FIND_ALL_SUBJECTS_SUCCESS, response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Transactional(readOnly = true)
public class LoginService {

private static final String BASIC_PROFILE_IMAGE = "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/b5ddbdeb-00bf-425a-9321-e36d25323bc0.jpg";
private static final String BASIC_PROFILE_IMAGE = "https://haru-speak-s3.s3.ap-northeast-2.amazonaws.com/image/static/basic_profile_image.jpg";
private final KakaoProvider kakaoProvider;
private final JwtProvider jwtProvider;
private final MemberRepository memberRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.be.core.application.goal_subject;

import static org.assertj.core.api.Assertions.assertThat;

import com.example.be.core.application.member.GoalService;
import com.example.be.core.application.InitServiceTest;
import com.example.be.core.application.dto.response.GoalResponse;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

@DisplayName("서비스 테스트 : Goal 전체 조회")
class GoalFindAllTest extends InitServiceTest {

@Autowired
private GoalService goalService;

@Nested
@DisplayName("목표를 전체 조회할 때")
class FindAllTest {

@Nested
@DisplayName("정상적인 요청이라면")
class NormalTest {

@Test
void find_all_goals_test(){
//given & when
List<GoalResponse> goals = goalService.findAll();

//then
assertThat(goals).hasSize(5);
assertThat(goals.get(0).getGoalId()).isEqualTo(1L);
assertThat(goals.get(1).getGoalId()).isEqualTo(2L);
assertThat(goals.get(2).getGoalId()).isEqualTo(3L);
assertThat(goals.get(3).getGoalId()).isEqualTo(4L);
assertThat(goals.get(4).getGoalId()).isEqualTo(5L);
assertThat(goals.get(1).getContent()).isEqualTo("다른 사람들의 피드백!");
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.be.core.application.goal_subject;

import static org.assertj.core.api.Assertions.assertThat;

import com.example.be.core.application.InitServiceTest;
import com.example.be.core.application.dto.response.SubjectResponse;
import com.example.be.core.application.member.SubjectService;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

@DisplayName("서비스 테스트 : Subject 전체 조회")
class SubjectFindAllTest extends InitServiceTest {

@Autowired
private SubjectService subjectService;

@Nested
@DisplayName("주제를 전체 조회할 때")
class FindAllTest {

@Nested
@DisplayName("정상적인 요청이라면")
class NormalTest {

@Test
void find_all_subjects_test() {
//give & when
List<SubjectResponse> subjects = subjectService.findAll();

//then
assertThat(subjects).hasSize(9);
assertThat(subjects.get(0).getSubjectId()).isEqualTo(1L);
assertThat(subjects.get(1).getSubjectId()).isEqualTo(2L);
assertThat(subjects.get(2).getSubjectId()).isEqualTo(3L);
assertThat(subjects.get(3).getSubjectId()).isEqualTo(4L);
assertThat(subjects.get(4).getSubjectId()).isEqualTo(5L);
assertThat(subjects.get(5).getSubjectId()).isEqualTo(6L);
assertThat(subjects.get(6).getSubjectId()).isEqualTo(7L);
assertThat(subjects.get(7).getSubjectId()).isEqualTo(8L);
assertThat(subjects.get(8).getSubjectId()).isEqualTo(9L);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.example.be.common.exception.member.NotFoundFollowRelationshipException;
import com.example.be.common.exception.member.NotFoundMemberIdException;
import com.example.be.core.application.InitServiceTest;
import com.example.be.core.application.MemberService;
import com.example.be.core.application.dto.response.FollowResponse;
import com.example.be.core.domain.member.Follow;
import com.example.be.core.repository.member.FollowRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.example.be.core.application.InitServiceTest;
import com.example.be.core.application.MemberService;
import com.example.be.core.application.dto.request.MemberModifyRequest;
import com.example.be.core.application.dto.request.MemberSignUpRequest;
import com.example.be.core.application.dto.response.MemberResponse;
Expand All @@ -13,7 +12,6 @@
import com.example.be.core.domain.member.grade.SpeakingGradeLevel;
import java.util.Arrays;
import java.util.List;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.example.be.core.application.InitServiceTest;
import com.example.be.core.application.MemberService;
import com.example.be.core.application.dto.request.MemberSignUpRequest;
import com.example.be.core.application.dto.response.MemberResponse;
import com.example.be.core.domain.member.MemberType;
import com.example.be.core.domain.member.SpeakingTestType;
import com.example.be.core.domain.member.grade.SpeakingGradeLanguage;
import com.example.be.core.domain.member.grade.SpeakingGradeLevel;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.example.be.core.application.InitServiceTest;
import com.example.be.core.application.MemberService;
import com.example.be.core.application.dto.request.MemberSignUpRequest;
import com.example.be.core.application.dto.response.MemberSignUpResponse;
import com.example.be.core.domain.member.MemberType;
Expand Down
Loading

0 comments on commit 5b4cf73

Please sign in to comment.