Skip to content

Commit

Permalink
[BE] 코딩 컨밴션을 정하기 위해 전체적으로 리팩토링한다. (#236) (#238)
Browse files Browse the repository at this point in the history
* refactor: 코딩 컨밴션을 맞추며 전체적으로 리팩터링

* [BE] 특정 사용자의 프로젝트 이름을 중복 사용하지 못하게 수정 (#218) (#235)

* feat: 프로젝트 이름 중복 체크 로직 추가

* test: 프로젝트 이름 중복에 대한 테스트 코드 추가

* feat: 프로젝트 이름 중복에 대한 인수 테스트 추가

* refactor: asciidoc 파일명 수정

* refactor: 가독성 좋게 코드 수정

* [BE] 비회원 댓글 비밀번호만 체크하는 API 만들기 / 관리자 댓글 삭제 기능 (#217) (#230)

* feat: 비로그인 유저 비밀번호 확인 api 구현 및 테스트 작성

* test: 비밀번호 일치하지 않는 경우 테스트 작성 및 restdoc 작성

* chore: gitignore 설정 추가

* feat: 관리자 댓글 삭제 기능 구현 및 테스트 작성

* docs: restdoc adoc 작성

* refactor: 메소드 네이밍 변경

Co-authored-by: JinYoung Park <[email protected]>

* [BE] 카카오 프사를 바꿨을 경우, 서버의 카카오 프로필 데이터가 업데이트 되지 않는 문제를 해결한다. (#202) (#231)

* refactor: 카카오에서 받아온 데이터기준으로 사용자 정보 업데이트 하도록 리팩터링

* feat: jpa 테스트 격리를 위한 클래스 구현

* refactor: 병렬 테스트 구현
- junit5 Parallel Execution 적용

* refactor: 모든 테스트가 병렬적으로 수행되도록 리팩터링

* refactor: 병렬 수행 설정 수정
- 테스트 클래스는 병렬도 수행된다.
- 테스트 클래스 내의 메서드들은 순차적으로 수행된다.

* refactor: 서브 모듈 수정

* refactor: optional 변수명 수정

* refactor: 불필요한 로직제거
- 빈생성시 afterPropertiesSet에서 자동 초기화 되므로 체크 안해도 된다고 판단함

Co-authored-by: JinYoung Park <[email protected]>

* style: 코드 포메팅 수정

Co-authored-by: jaeseongDev <[email protected]>
Co-authored-by: Sehwan_Jang <[email protected]>
Co-authored-by: JinYoung Park <[email protected]>
  • Loading branch information
4 people committed Jul 28, 2021
1 parent 500e785 commit f7e6e8a
Show file tree
Hide file tree
Showing 56 changed files with 569 additions and 536 deletions.
4 changes: 2 additions & 2 deletions backend/src/main/java/com/darass/darass/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*");
.allowedOrigins("*")
.allowedMethods("*");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
import com.darass.darass.auth.oauth.controller.AuthenticationPrincipalArgumentResolver;
import com.darass.darass.auth.oauth.controller.RequiredLoginArgumentResolver;
import com.darass.darass.auth.oauth.service.OAuthService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
@RequiredArgsConstructor
public class AuthenticationPrincipalConfig implements WebMvcConfigurer {

private final OAuthService oAuthService;

@Override
public void addArgumentResolvers(List argumentResolvers) {
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(createAuthenticationPrincipalArgumentResolver());
argumentResolvers.add(createRequiredLoginArgumentResolver());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.darass.darass.user.domain.SocialLoginUser;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Objects;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
Expand All @@ -32,11 +33,11 @@ public SocialLoginUser findSocialLoginUser(String accessToken) {
try {
SocialLoginResponse socialLoginResponse
= restTemplate.postForObject(KAKAO_API_SERVER_URI, apiRequest, SocialLoginResponse.class);
return parseUser(socialLoginResponse);
return parseUser(Objects.requireNonNull(socialLoginResponse));

} catch (HttpClientErrorException e) {
throw ExceptionWithMessageAndCode.INVALID_JWT_TOKEN.getException();
}
} // TODO: null 포인터 예외 잡아야한다.
}

private HttpEntity<HttpHeaders> prepareRequest(String accessToken) {
Expand All @@ -53,7 +54,7 @@ private SocialLoginUser parseUser(SocialLoginResponse socialLoginResponse) {
String email = kaKaoAccount.getEmail();
Profile profile = socialLoginResponse.getKaKaoAccount().getProfile();
String nickname = profile.getNickname();
String profileImageUrl = profile.getThumbnail_image_url();
String profileImageUrl = profile.getThumbnailImageUrl();

return SocialLoginUser
.builder()
Expand All @@ -63,6 +64,5 @@ private SocialLoginUser parseUser(SocialLoginResponse socialLoginResponse) {
.email(email)
.profileImageUrl(profileImageUrl)
.build();

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.darass.darass.auth.oauth.api.domain.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -11,5 +12,7 @@ public class Profile {

private String nickname;

private String thumbnail_image_url;
@JsonProperty("thumbnail_image_url")
private String thumbnailImageUrl;

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public boolean supportsParameter(MethodParameter parameter) {
@Override
public User resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
String accessToken = AuthorizationExtractor.extract(Objects.requireNonNull(webRequest.getNativeRequest(HttpServletRequest.class)));
String accessToken = AuthorizationExtractor
.extract(Objects.requireNonNull(webRequest.getNativeRequest(HttpServletRequest.class)));

if (Objects.isNull(accessToken) || accessToken.isEmpty()) {
return new GuestUser();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.darass.darass.auth.oauth.controller;

import com.darass.darass.auth.oauth.controller.dto.TokenResponse;
import com.darass.darass.auth.oauth.dto.TokenResponse;
import com.darass.darass.auth.oauth.service.OAuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
import com.darass.darass.auth.oauth.service.OAuthService;
import com.darass.darass.exception.ExceptionWithMessageAndCode;
import com.darass.darass.user.domain.User;
import java.util.Objects;
import javax.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

@RequiredArgsConstructor
public class RequiredLoginArgumentResolver implements HandlerMethodArgumentResolver {

Expand All @@ -27,9 +26,9 @@ public boolean supportsParameter(MethodParameter parameter) {

@Override
public User resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
String accessToken = AuthorizationExtractor.extract(Objects.requireNonNull(webRequest.getNativeRequest(
HttpServletRequest.class)));
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
String accessToken = AuthorizationExtractor
.extract(Objects.requireNonNull(webRequest.getNativeRequest(HttpServletRequest.class)));

if (Objects.isNull(accessToken)) {
throw ExceptionWithMessageAndCode.SHOULD_LOGIN.getException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.darass.darass.auth.oauth.controller.dto;
package com.darass.darass.auth.oauth.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.darass.darass.auth.oauth.infrastructure;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;

public class AuthorizationExtractor {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.darass.darass.auth.oauth.infrastructure;

import com.darass.darass.exception.ExceptionWithMessageAndCode;
import io.jsonwebtoken.*;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.MalformedJwtException;
import io.jsonwebtoken.SignatureAlgorithm;
import java.util.Date;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class JwtTokenProvider {

@Value("${security.jwt.token.secret-key}")
private String secretKey;

@Value("${security.jwt.token.expire-length}")
private long validityInMilliseconds;

Expand All @@ -21,11 +25,11 @@ public String createAccessToken(String payload) {
Date validity = new Date(now.getTime() + validityInMilliseconds);

return Jwts.builder()
.setClaims(claims)
.setIssuedAt(now)
.setExpiration(validity)
.signWith(SignatureAlgorithm.HS256, secretKey)
.compact();
.setClaims(claims)
.setIssuedAt(now)
.setExpiration(validity)
.signWith(SignatureAlgorithm.HS256, secretKey)
.compact();
}

public String getPayload(String accessToken) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
package com.darass.darass.auth.oauth.service;

import com.darass.darass.auth.oauth.api.domain.UserInfoProvider;
import com.darass.darass.auth.oauth.controller.dto.TokenResponse;
import com.darass.darass.auth.oauth.dto.TokenResponse;
import com.darass.darass.auth.oauth.infrastructure.JwtTokenProvider;
import com.darass.darass.exception.ExceptionWithMessageAndCode;
import com.darass.darass.user.domain.SocialLoginUser;
import com.darass.darass.user.repository.SocialLoginUserRepository;
import java.util.Optional;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
@AllArgsConstructor
@Transactional
@AllArgsConstructor
@Service
public class OAuthService {

private SocialLoginUserRepository socialLoginUserRepository;

private JwtTokenProvider jwtTokenProvider;
private UserInfoProvider userInfoProvider;

private UserInfoProvider userInfoProvider; //TODO: Mocking시 final 못붙이는 문제가 있다.

public TokenResponse oauthLogin(String oauthAccessToken) {
SocialLoginUser socialLoginUser = userInfoProvider.findSocialLoginUser(oauthAccessToken);
Optional<SocialLoginUser> possibleSocialLoginUser = socialLoginUserRepository.findByOauthId(socialLoginUser.getOauthId());

if (possibleSocialLoginUser.isEmpty()) {
Optional<SocialLoginUser> possibleSocialLoginUser = socialLoginUserRepository
.findByOauthId(socialLoginUser.getOauthId());

if (possibleSocialLoginUser.isEmpty()) { //TODO: 옵셔널로 변경 가능?

socialLoginUserRepository.save(socialLoginUser);
return TokenResponse.of(jwtTokenProvider.createAccessToken(socialLoginUser.getId().toString()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
package com.darass.darass.comment.controller;

import com.darass.darass.auth.oauth.domain.AuthenticationPrincipal;
import com.darass.darass.comment.controller.dto.CommentCreateRequest;
import com.darass.darass.comment.controller.dto.CommentDeleteRequest;
import com.darass.darass.comment.controller.dto.CommentResponse;
import com.darass.darass.comment.controller.dto.CommentUpdateRequest;
import com.darass.darass.comment.dto.CommentCreateRequest;
import com.darass.darass.comment.dto.CommentDeleteRequest;
import com.darass.darass.comment.dto.CommentResponse;
import com.darass.darass.comment.dto.CommentUpdateRequest;
import com.darass.darass.comment.service.CommentService;
import com.darass.darass.user.domain.User;
import java.util.List;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/comments")
@RequiredArgsConstructor
@RequestMapping("/api/v1/comments")
@RestController
public class CommentController {

private final CommentService commentService;

@GetMapping
public ResponseEntity<List<CommentResponse>> read(@RequestParam("url") String url, @RequestParam("projectKey") String projectKey) {
public ResponseEntity<List<CommentResponse>> read(@RequestParam("url") String url,
@RequestParam("projectKey") String projectKey) {
List<CommentResponse> commentResponses = commentService.findAllCommentsByUrlAndProjectKey(url, projectKey);
return ResponseEntity.status(HttpStatus.OK).body(commentResponses);
}

@PostMapping
public ResponseEntity<CommentResponse> save(@AuthenticationPrincipal User user, @Valid @RequestBody CommentCreateRequest commentRequest) {
public ResponseEntity<CommentResponse> save(@AuthenticationPrincipal User user,
@Valid @RequestBody CommentCreateRequest commentRequest) {
CommentResponse commentResponse = commentService.save(user, commentRequest);
return ResponseEntity.status(HttpStatus.CREATED).body(commentResponse);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor
@Getter
@NoArgsConstructor
@Entity
public class Comment extends BaseTimeEntity {

@Id
Expand All @@ -32,6 +32,7 @@ public class Comment extends BaseTimeEntity {
private Project project;

private String url;

private String content;

@Builder
Expand All @@ -55,7 +56,7 @@ public boolean match(String url, String projectKey) {
return this.url.equals(url) && project.isSame(projectKey);
}

public Long getUserId(){
public Long getUserId() {
return user.getId();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class Comments {

private final List<Comment> comments;

public Comments(List<Comment> comments) {
this.comments = comments;
}

public List<Comment> match(String url, String projectKey) {
return comments.stream()
.filter(it -> it.match(url, projectKey))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.darass.darass.comment.controller.dto;
package com.darass.darass.comment.dto;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -14,10 +15,12 @@ public class CommentCreateRequest {

private String guestPassword;

@NotBlank
private String projectSecretKey;

@NotNull
private String content;

@NotBlank
private String url;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.darass.darass.comment.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class CommentDeleteRequest {

private final Long guestUserId;

private final String guestUserPassword;
}
Loading

0 comments on commit f7e6e8a

Please sign in to comment.