Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into feat/#126
Browse files Browse the repository at this point in the history
  • Loading branch information
funnysunny08 committed Nov 8, 2023
2 parents a38c7ef + fc6c854 commit f0054eb
Show file tree
Hide file tree
Showing 34 changed files with 1,901 additions and 1,443 deletions.
32 changes: 32 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@

== 0. ์ธ์ฆ

=== ๋ณดํ˜ธ์†Œ ๋กœ๊ทธ์ธ

==== Request
operation::auth-controller-test/shelter-login[snippets='http-request,request-fields']

==== Response
operation::auth-controller-test/shelter-login[snippets='http-response,response-fields,response-cookies']

=== ๋ด‰์‚ฌ์ž ๋กœ๊ทธ์ธ

==== Request
operation::auth-controller-test/volunteer-login[snippets='http-request,request-fields']

==== Response
operation::auth-controller-test/volunteer-login[snippets='http-response,response-fields,response-cookies']

=== ์•ก์„ธ์Šค ํ† ํฐ ๊ฐฑ์‹ 

==== Request
operation::auth-controller-test/refresh-access-token[snippets='http-request,request-cookies']

==== Response
operation::auth-controller-test/refresh-access-token[snippets='http-response,response-fields,response-cookies']

== 1. ๋ด‰์‚ฌ์ž

=== ๋ด‰์‚ฌ์ž๊ฐ€ ์™„๋ฃŒํ•œ ๋ด‰์‚ฌ ๋ชจ์ง‘๊ธ€ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ
Expand Down Expand Up @@ -75,6 +99,14 @@ operation::recruitment-controller-test/register-recruitment[snippets='http-respo

== 5. ๋ด‰์‚ฌ ํ›„๊ธฐ

=== ๋ณดํ˜ธ์†Œ์˜ ํ›„๊ธฐ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ

==== Request
operation::review-controller-test/find-shelter-reviews-by-shelter[snippets='http-request,request-headers,path-parameters,query-parameters']

==== Response
operation::review-controller-test/find-shelter-reviews-by-shelter[snippets='http-response,response-fields']

== 6. ๋ณดํ˜ธ ๋™๋ฌผ

= ๋ด‰์‚ฌ์ž
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.clova.anifriends.domain.animal.dto.response.FindAnimalsByVolunteerResponse;
import com.clova.anifriends.domain.animal.dto.response.RegisterAnimalResponse;
import com.clova.anifriends.domain.animal.service.AnimalService;
import com.clova.anifriends.domain.auth.resolver.LoginUser;
import com.clova.anifriends.domain.auth.LoginUser;
import jakarta.validation.Valid;
import java.net.URI;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.clova.anifriends.domain.applicant.dto.FindApplicantsApprovedResponse;
import com.clova.anifriends.domain.applicant.dto.FindApplyingVolunteersResponse;
import com.clova.anifriends.domain.applicant.service.ApplicantService;
import com.clova.anifriends.domain.auth.resolver.LoginUser;
import com.clova.anifriends.domain.auth.LoginUser;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.clova.anifriends.domain.auth.resolver;
package com.clova.anifriends.domain.auth;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.clova.anifriends.domain.auth.authentication;

import com.clova.anifriends.domain.auth.jwt.JwtProvider;
import com.clova.anifriends.domain.auth.jwt.response.CustomClaims;
import com.clova.anifriends.domain.auth.dto.response.CustomClaims;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.clova.anifriends.domain.auth.controller;

import com.clova.anifriends.domain.auth.controller.request.LoginRequest;
import com.clova.anifriends.domain.auth.controller.response.LoginResponse;
import com.clova.anifriends.domain.auth.jwt.response.TokenResponse;
import com.clova.anifriends.domain.auth.dto.request.LoginRequest;
import com.clova.anifriends.domain.auth.dto.response.LoginResponse;
import com.clova.anifriends.domain.auth.dto.response.TokenResponse;
import com.clova.anifriends.domain.auth.service.AuthService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.clova.anifriends.domain.auth.controller.request;
package com.clova.anifriends.domain.auth.dto.request;

import jakarta.validation.constraints.NotBlank;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.clova.anifriends.domain.auth.jwt.response;
package com.clova.anifriends.domain.auth.dto.response;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.clova.anifriends.domain.auth.controller.response;
package com.clova.anifriends.domain.auth.dto.response;

import com.clova.anifriends.domain.auth.jwt.UserRole;
import com.clova.anifriends.domain.auth.jwt.response.TokenResponse;

public record LoginResponse(Long userId, UserRole role, String accessToken) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.clova.anifriends.domain.auth.jwt.response;
package com.clova.anifriends.domain.auth.dto.response;

import com.clova.anifriends.domain.auth.jwt.UserRole;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

public class InvalidJwtException extends AuthenticationException {

public InvalidJwtException(String message) {
super(ErrorCode.UN_AUTHENTICATION, message);
}

public InvalidJwtException(ErrorCode errorCode, String message) {
super(errorCode, message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.clova.anifriends.domain.auth.jwt;


import com.clova.anifriends.domain.auth.jwt.response.CustomClaims;
import com.clova.anifriends.domain.auth.jwt.response.TokenResponse;
import com.clova.anifriends.domain.auth.dto.response.CustomClaims;
import com.clova.anifriends.domain.auth.dto.response.TokenResponse;

public interface JwtProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.clova.anifriends.domain.auth.exception.AuthNotFoundException;
import com.clova.anifriends.domain.auth.jwt.JwtProvider;
import com.clova.anifriends.domain.auth.jwt.UserRole;
import com.clova.anifriends.domain.auth.jwt.response.TokenResponse;
import com.clova.anifriends.domain.auth.dto.response.TokenResponse;
import com.clova.anifriends.domain.auth.repository.RefreshTokenRepository;
import com.clova.anifriends.domain.shelter.Shelter;
import com.clova.anifriends.domain.shelter.repository.ShelterRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.clova.anifriends.domain.recruitment.controller;

import com.clova.anifriends.domain.auth.resolver.LoginUser;
import com.clova.anifriends.domain.auth.LoginUser;
import com.clova.anifriends.domain.recruitment.dto.request.FindRecruitmentsByShelterRequest;
import com.clova.anifriends.domain.recruitment.dto.request.FindRecruitmentsByVolunteerRequest;
import com.clova.anifriends.domain.recruitment.dto.request.RegisterRecruitmentRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.clova.anifriends.domain.review.controller;

import com.clova.anifriends.domain.auth.resolver.LoginUser;
import com.clova.anifriends.domain.auth.LoginUser;
import com.clova.anifriends.domain.review.dto.request.RegisterReviewRequest;
import com.clova.anifriends.domain.review.dto.response.FindReviewResponse;
import com.clova.anifriends.domain.review.dto.response.FindShelterReviewsByVolunteerResponse;
import com.clova.anifriends.domain.review.dto.response.FindShelterReviewsResponse;
import com.clova.anifriends.domain.review.dto.response.FindShelterReviewsByShelterResponse;
import com.clova.anifriends.domain.review.dto.response.FindVolunteerReviewsResponse;
import com.clova.anifriends.domain.review.service.ReviewService;
import java.net.URI;
Expand Down Expand Up @@ -44,10 +44,11 @@ public ResponseEntity<Void> registerReview(
}

@GetMapping("/shelters/{shelterId}/reviews")
public ResponseEntity<FindShelterReviewsResponse> findShelterReviews(
public ResponseEntity<FindShelterReviewsByShelterResponse> findShelterReviewsByShelter(
@PathVariable("shelterId") Long shelterId,
Pageable pageable) {
FindShelterReviewsResponse response = reviewService.findShelterReviews(shelterId, pageable);
FindShelterReviewsByShelterResponse response
= reviewService.findShelterReviewsByShelter(shelterId, pageable);
return ResponseEntity.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
import java.util.List;
import org.springframework.data.domain.Page;

public record FindShelterReviewsResponse(List<FindShelterReviewResponse> reviews,
PageInfo pageInfo) {
public record FindShelterReviewsByShelterResponse(
List<FindShelterReviewResponse> reviews,
PageInfo pageInfo) {

public record FindShelterReviewResponse(
Long reviewId,
LocalDateTime createdAt,
String content,
LocalDateTime reviewCreatedAt,
String reviewContent,
List<String> reviewImageUrls,

String volunteerName,
int temperature,
int volunteerTemperature,
String volunteerImageUrl,
long VolunteerReviewCount) {

Expand All @@ -36,11 +37,11 @@ public static FindShelterReviewResponse from(Review review) {
}
}

public static FindShelterReviewsResponse from(Page<Review> reviewPage) {
public static FindShelterReviewsByShelterResponse from(Page<Review> reviewPage) {
PageInfo pageInfo = PageInfo.of(reviewPage.getTotalElements(), reviewPage.hasNext());
List<FindShelterReviewResponse> reviews = reviewPage
.map(FindShelterReviewResponse::from)
.stream().toList();
return new FindShelterReviewsResponse(reviews, pageInfo);
return new FindShelterReviewsByShelterResponse(reviews, pageInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.clova.anifriends.domain.review.Review;
import com.clova.anifriends.domain.review.dto.response.FindReviewResponse;
import com.clova.anifriends.domain.review.dto.response.FindShelterReviewsByVolunteerResponse;
import com.clova.anifriends.domain.review.dto.response.FindShelterReviewsResponse;
import com.clova.anifriends.domain.review.dto.response.FindShelterReviewsByShelterResponse;
import com.clova.anifriends.domain.review.dto.response.FindVolunteerReviewsResponse;
import com.clova.anifriends.domain.review.exception.ApplicantNotFoundException;
import com.clova.anifriends.domain.review.exception.ReviewBadRequestException;
Expand Down Expand Up @@ -37,10 +37,11 @@ private Review getReview(Long userId, Long reviewId) {
}

@Transactional(readOnly = true)
public FindShelterReviewsResponse findShelterReviews(Long shelterId, Pageable pageable) {
Page<Review> reviewPage
= reviewRepository.findAllByShelterId(shelterId, pageable);
return FindShelterReviewsResponse.from(reviewPage);
public FindShelterReviewsByShelterResponse findShelterReviewsByShelter(
Long shelterId,
Pageable pageable) {
Page<Review> reviewPage = reviewRepository.findAllByShelterId(shelterId, pageable);
return FindShelterReviewsByShelterResponse.from(reviewPage);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.clova.anifriends.domain.shelter.controller;

import com.clova.anifriends.domain.auth.resolver.LoginUser;
import com.clova.anifriends.domain.auth.LoginUser;
import com.clova.anifriends.domain.shelter.dto.CheckDuplicateShelterEmailRequest;
import com.clova.anifriends.domain.shelter.dto.CheckDuplicateShelterResponse;
import com.clova.anifriends.domain.shelter.dto.FindShelterDetailResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.clova.anifriends.domain.volunteer.controller;

import com.clova.anifriends.domain.auth.resolver.LoginUser;
import com.clova.anifriends.domain.auth.LoginUser;
import com.clova.anifriends.domain.volunteer.dto.request.CheckDuplicateVolunteerEmailRequest;
import com.clova.anifriends.domain.volunteer.dto.request.RegisterVolunteerRequest;
import com.clova.anifriends.domain.volunteer.dto.response.CheckDuplicateVolunteerEmailResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.clova.anifriends.global.config;

import com.clova.anifriends.domain.auth.authentication.JwtAuthenticationProvider;
import com.clova.anifriends.domain.auth.filter.JwtAuthenticationFilter;
import com.clova.anifriends.global.web.filter.JwtAuthenticationFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.clova.anifriends.global.config;

import com.clova.anifriends.domain.auth.resolver.LoginUserArgumentResolver;
import com.clova.anifriends.global.web.argumentresolver.LoginUserArgumentResolver;
import java.util.List;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.clova.anifriends.domain.auth.jwt;
package com.clova.anifriends.global.jwt;

import com.clova.anifriends.domain.auth.dto.response.CustomClaims;
import com.clova.anifriends.domain.auth.dto.response.TokenResponse;
import com.clova.anifriends.domain.auth.exception.ExpiredAccessTokenException;
import com.clova.anifriends.domain.auth.exception.InvalidJwtException;
import com.clova.anifriends.domain.auth.exception.ExpiredRefreshTokenException;
import com.clova.anifriends.domain.auth.jwt.response.CustomClaims;
import com.clova.anifriends.domain.auth.jwt.response.TokenResponse;
import com.clova.anifriends.global.exception.ErrorCode;
import com.clova.anifriends.domain.auth.exception.InvalidJwtException;
import com.clova.anifriends.domain.auth.jwt.JwtProvider;
import com.clova.anifriends.domain.auth.jwt.UserRole;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.JwtException;
Expand Down Expand Up @@ -101,7 +102,7 @@ public CustomClaims parseAccessToken(String token) {
} catch (JwtException ex) {
log.info("[EX] {}: ์ž˜๋ชป๋œ JWT์ž…๋‹ˆ๋‹ค.", ex.getClass().getSimpleName());
}
throw new InvalidJwtException(ErrorCode.UN_AUTHENTICATION, "์œ ํšจํ•˜์ง€ ์•Š์€ JWT์ž…๋‹ˆ๋‹ค.");
throw new InvalidJwtException("์œ ํšจํ•˜์ง€ ์•Š์€ JWT์ž…๋‹ˆ๋‹ค.");
}

@Override
Expand All @@ -117,6 +118,6 @@ public TokenResponse refreshAccessToken(String refreshToken) {
} catch (JwtException ex) {
log.info("[EX] {}: ์ž˜๋ชป๋œ ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ์ž…๋‹ˆ๋‹ค.", ex.getClass().getSimpleName());
}
throw new InvalidJwtException(ErrorCode.UN_AUTHENTICATION, "์œ ํšจํ•˜์ง€ ์•Š์€ ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ์ž…๋‹ˆ๋‹ค.");
throw new InvalidJwtException("์œ ํšจํ•˜์ง€ ์•Š์€ ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ์ž…๋‹ˆ๋‹ค.");
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.clova.anifriends.domain.auth.resolver;
package com.clova.anifriends.global.web.argumentresolver;

import static com.clova.anifriends.global.exception.ErrorCode.UN_AUTHENTICATION;

import com.clova.anifriends.domain.auth.authentication.JwtAuthentication;
import com.clova.anifriends.domain.auth.exception.AuthAuthenticationException;
import com.clova.anifriends.domain.auth.LoginUser;
import java.util.Objects;
import org.springframework.core.MethodParameter;
import org.springframework.security.core.Authentication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.clova.anifriends.domain.auth.filter;
package com.clova.anifriends.global.web.filter;

import com.clova.anifriends.domain.auth.authentication.JwtAuthenticationProvider;
import com.clova.anifriends.domain.auth.exception.InvalidJwtException;
import jakarta.servlet.FilterChain;
import jakarta.servlet.GenericFilter;
import jakarta.servlet.ServletException;
Expand All @@ -17,17 +18,30 @@
public class JwtAuthenticationFilter extends GenericFilter {

private static final String HEADER = "Authorization";
private static final String BEARER = "Bearer ";
private final JwtAuthenticationProvider authenticationProvider;

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
String accessToken = request.getHeader(HEADER);
if (Objects.nonNull(accessToken)) {
String bearerAccessToken = request.getHeader(HEADER);
if (Objects.nonNull(bearerAccessToken)) {
String accessToken = removeBearer(bearerAccessToken);
Authentication authentication = authenticationProvider.authenticate(accessToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
}
chain.doFilter(req, res);
}

private String removeBearer(String bearerAccessToken) {
checkTokenContainsBearer(bearerAccessToken);
return bearerAccessToken.replace(BEARER, "");
}

private static void checkTokenContainsBearer(String bearerAccessToken) {
if(!bearerAccessToken.contains(BEARER)) {
throw new InvalidJwtException("์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š๋Š” ์•ก์„ธ์Šค ํ† ํฐ ํ˜•์‹์ž…๋‹ˆ๋‹ค.");
}
}
}
Loading

0 comments on commit f0054eb

Please sign in to comment.