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

(회원) 전체 카테고리 목록 조회 기능 구현 #89

Merged
merged 25 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f3e8263
feat: (#67) (회원) 선호 카테고리 삭제 API 기능 구현
aiaiaiai1 Jul 18, 2023
f4b1f67
feat: (#67) Swagger 어노테이션 추가
aiaiaiai1 Jul 18, 2023
383519f
test: (#67) Controller 단위테스트, Service 통합테스트 추가
aiaiaiai1 Jul 18, 2023
ee2f013
style: (#67) final 키워드 추가
aiaiaiai1 Jul 18, 2023
07b3288
refactor: (#68) CategoryResponse 파라미터 값 수정
aiaiaiai1 Jul 19, 2023
e3a022d
feat: (#68) (회원) 카테고리 목록 전체 조회 API 추가
aiaiaiai1 Jul 19, 2023
f57dd51
teat: (#68) (회원) 레파지토리 테스트 추가
aiaiaiai1 Jul 19, 2023
b6949bb
teat: (#67) 선호하는 카테고리에 없는 카테고리를 삭제하는 경우 예외 테스트 추가
aiaiaiai1 Jul 19, 2023
4a82237
refactor: (#67) 개행 및 스태틱 임포트 리펙터링
aiaiaiai1 Jul 19, 2023
03dcd00
feat: (#67) Swagger 어노테이션 에러 응답 설명 추가
aiaiaiai1 Jul 19, 2023
c6e04fe
merge
aiaiaiai1 Jul 19, 2023
4da9a94
fix: (#68) 파라미터 반환값 수정
aiaiaiai1 Jul 19, 2023
247ed8f
test: (#68) 서비스, 컨트롤러 테스트 추가
aiaiaiai1 Jul 19, 2023
7d3c827
refactor: (#67) url 오타 수정
aiaiaiai1 Jul 19, 2023
8694859
refactor: (#67) 개행 및 컨벤션 수정
aiaiaiai1 Jul 19, 2023
a8b6aab
feat: (#68) Swagger 어노테이션 추가
aiaiaiai1 Jul 19, 2023
705f873
mergeMerge branch 'feat/#67' into feat/#68
aiaiaiai1 Jul 20, 2023
58c1b6e
style: (#68) 개행 삭제
aiaiaiai1 Jul 20, 2023
faf6fc6
merge 작업 수행
aiaiaiai1 Jul 20, 2023
3cecd49
style: (#68) 개행 수정
aiaiaiai1 Jul 20, 2023
3d4307b
refactor: (#68) @Nested 삭제
aiaiaiai1 Jul 20, 2023
dfa58ed
mergeMerge branch 'dev' into feat/#68
aiaiaiai1 Jul 20, 2023
79bbcb0
refactor: (#68) 들여쓰기 제거
aiaiaiai1 Jul 20, 2023
a5e9740
refactor: (#68) @Param 어노테이션 추가
aiaiaiai1 Jul 20, 2023
7848b8a
refactor: (#68) 시크릿 키 디코딩 제거
aiaiaiai1 Jul 20, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CategoryController {

private final CategoryService categoryService;

@Operation(summary = "카테고리 조회하기", description = "전체 카테고리 목록을 조회한다.")
@Operation(summary = "카테고리 목록 조회하기", description = "전체 카테고리 목록을 조회한다.")
@ApiResponse(responseCode = "200", description = "조회 성공")
@GetMapping("/guest")
public ResponseEntity<List<CategoryResponse>> getAllCategories() {
Expand Down Expand Up @@ -58,10 +58,12 @@ public ResponseEntity<Void> removeFavoriteCategory(final Member member, @PathVar
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

@Operation(summary = "회원으로 모든 카테고리 목록 조회하기", description = "회원의 선호하는 카테고리와 전체 카테고리 목록을 조회한다.")
@ApiResponse(responseCode = "200", description = "조회 성공")
@GetMapping
public ResponseEntity<Void> getAllCategories(final Member member) {
categoryService.getAllCategories(member);
return ResponseEntity.status(HttpStatus.OK).build();
public ResponseEntity<List<CategoryResponse>> getAllCategories(final Member member) {
final List<CategoryResponse> categories = categoryService.getAllCategories(member);
return ResponseEntity.status(HttpStatus.OK).body(categories);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface VoteRepository extends JpaRepository<Vote, Long> {

Expand All @@ -17,7 +18,7 @@ public interface VoteRepository extends JpaRepository<Vote, Long> {
" WHERE v.postOption.id = :postOptionId" +
" GROUP BY m.ageRange, m.gender"
)
List<VoteStatus> findVoteCountByPostOptionIdGroupByAgeRangeAndGender(Long postOptionId);
List<VoteStatus> findVoteCountByPostOptionIdGroupByAgeRangeAndGender(@Param("postOptionId") Long postOptionId);

Optional<Vote> findByMemberAndPostOption(final Member member, final PostOption postOption);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;
import io.jsonwebtoken.security.SignatureException;

import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -36,7 +38,7 @@ public TokenProcessor(
@Value("${jwt.token.expiration-time}") final int tokenExpirationTime,
final ObjectMapper objectMapper
) {
this.key = Keys.hmacShaKeyFor(Decoders.BASE64.decode(secretKey));
this.key = Keys.hmacShaKeyFor(secretKey.getBytes(StandardCharsets.UTF_8));
this.tokenExpirationTime = tokenExpirationTime;
this.objectMapper = objectMapper;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package com.votogether.domain.category.contorller;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doNothing;

import com.votogether.domain.category.dto.response.CategoryResponse;
import com.votogether.domain.category.entity.Category;
import com.votogether.domain.category.service.CategoryService;
import com.votogether.domain.member.service.MemberService;
import com.votogether.global.jwt.TokenProcessor;
import io.restassured.module.mockmvc.RestAssuredMockMvc;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpStatus;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.doNothing;

@WebMvcTest(CategoryController.class)
class CategoryControllerTest {

Expand Down Expand Up @@ -57,6 +60,39 @@ void getAllCategories() {
.body("[0].isFavorite", equalTo(false));
}

@Test
@DisplayName("회원으로 전체 카테고리 목록을 조회한다.")
void getAllCategoriesFromMember() {
// given
Category category = Category.builder()
.name("개발")
.build();

Category category1 = Category.builder()
.name("음식")
.build();

List<CategoryResponse> categoryResponses = List.of(
new CategoryResponse(category, false),
new CategoryResponse(category1, true)
);

given(categoryService.getAllCategories(any())).willReturn(categoryResponses);

// when
List<CategoryResponse> results = RestAssuredMockMvc
.given().log().all()
.when().get("/categories")
.then().log().all()
.status(HttpStatus.OK)
.extract()
.as(new ParameterizedTypeReference<List<CategoryResponse>>() {
}.getType());

// then
assertThat(results).usingRecursiveComparison().isEqualTo(categoryResponses);
}

@Test
@DisplayName("선호하는 카테고리를 선호 카테고리 목록에 추가한다.")
void addFavoriteCategory() {
Expand Down