Skip to content

Commit

Permalink
Merge pull request #71 from mujik-tigers/test/refactor-user
Browse files Browse the repository at this point in the history
refactor: 대규모 로직 변경
  • Loading branch information
yeonise authored Apr 21, 2024
2 parents 5e80943 + 756789f commit ea043fc
Show file tree
Hide file tree
Showing 46 changed files with 1,033 additions and 866 deletions.
78 changes: 39 additions & 39 deletions src/docs/asciidoc/api/user.adoc
Original file line number Diff line number Diff line change
@@ -1,107 +1,107 @@
[[User-API]]
== User API

[[update-nickname-success]]
[[change-nickname-success]]
=== 닉네임 변경 성공

==== HTTP Request

include::{snippets}/update-nickname-success/http-request.adoc[]
include::{snippets}/update-nickname-success/request-fields.adoc[]
include::{snippets}/change-nickname-success/http-request.adoc[]
include::{snippets}/change-nickname-success/request-fields.adoc[]

==== HTTP Response

include::{snippets}/update-nickname-success/http-response.adoc[]
include::{snippets}/update-nickname-success/response-fields.adoc[]
include::{snippets}/change-nickname-success/http-response.adoc[]
include::{snippets}/change-nickname-success/response-fields.adoc[]

{nbsp}

[[update-nickname-fail]]
[[change-nickname-fail]]
=== 닉네임 변경 실패: 요청 데이터 오류가 발생했습니다

==== HTTP Request

include::{snippets}/update-nickname-fail/http-request.adoc[]
include::{snippets}/update-nickname-fail/request-fields.adoc[]
include::{snippets}/change-nickname-fail/http-request.adoc[]
include::{snippets}/change-nickname-fail/request-fields.adoc[]

==== HTTP Response

include::{snippets}/update-nickname-fail/http-response.adoc[]
include::{snippets}/update-nickname-fail/response-fields.adoc[]
include::{snippets}/change-nickname-fail/http-response.adoc[]
include::{snippets}/change-nickname-fail/response-fields.adoc[]

{nbsp}

[[change-participant-role-success]]
[[change-role-success]]
=== 다른 유저의 역할 변경 성공

==== HTTP Request

include::{snippets}/change-participant-role-success/http-request.adoc[]
include::{snippets}/change-participant-role-success/request-fields.adoc[]
include::{snippets}/change-role-success/http-request.adoc[]
include::{snippets}/change-role-success/request-fields.adoc[]

==== HTTP Response

include::{snippets}/change-participant-role-success/http-response.adoc[]
include::{snippets}/change-participant-role-success/response-fields.adoc[]
include::{snippets}/change-role-success/http-response.adoc[]
include::{snippets}/change-role-success/response-fields.adoc[]

{nbsp}

[[change-self-role-fail]]
=== 다른 유저의 역할 변경 실패: 자신의 역할을 변경할 수 없다
[[change-role-fail-self]]
=== 다른 유저의 역할 변경 실패: 자신의 역할은 변경할 수 없습니다

==== HTTP Request

include::{snippets}/change-self-role-fail/http-request.adoc[]
include::{snippets}/change-self-role-fail/request-fields.adoc[]
include::{snippets}/change-role-fail-self/http-request.adoc[]
include::{snippets}/change-role-fail-self/request-fields.adoc[]

==== HTTP Response

include::{snippets}/change-self-role-fail/http-response.adoc[]
include::{snippets}/change-self-role-fail/response-fields.adoc[]
include::{snippets}/change-role-fail-self/http-response.adoc[]
include::{snippets}/change-role-fail-self/response-fields.adoc[]

{nbsp}

[[change-higher-or-equal-user-role-fail]]
=== 다른 유저의 역할 변경 실패: 자신보다 낮은 역할을 가진 유저의 역할만 변경할 수 있다
[[change-role-fail-equal-or-higher-user]]
=== 다른 유저의 역할 변경 실패: 자신과 동등하거나 높은 단계의 유저에 대한 역할을 변경할 수 없습니다

==== HTTP Request

include::{snippets}/change-higher-or-equal-user-role-fail/http-request.adoc[]
include::{snippets}/change-higher-or-equal-user-role-fail/request-fields.adoc[]
include::{snippets}/change-role-fail-equal-or-higher-user/http-request.adoc[]
include::{snippets}/change-role-fail-equal-or-higher-user/request-fields.adoc[]

==== HTTP Response

include::{snippets}/change-higher-or-equal-user-role-fail/http-response.adoc[]
include::{snippets}/change-higher-or-equal-user-role-fail/response-fields.adoc[]
include::{snippets}/change-role-fail-equal-or-higher-user/http-response.adoc[]
include::{snippets}/change-role-fail-equal-or-higher-user/response-fields.adoc[]

{nbsp}

[[change-higher-or-equal-role-fail]]
=== 다른 유저의 역할 변경 실패: 자신보다 낮은 역할로의 변경만 가능하다
[[change-role-fail-higher-role]]
=== 다른 유저의 역할 변경 실패: 자신의 역할보다 높은 단계의 역할로 변경할 수 없습니다

==== HTTP Request

include::{snippets}/change-higher-or-equal-role-fail/http-request.adoc[]
include::{snippets}/change-higher-or-equal-role-fail/request-fields.adoc[]
include::{snippets}/change-role-fail-higher-role/http-request.adoc[]
include::{snippets}/change-role-fail-higher-role/request-fields.adoc[]

==== HTTP Response

include::{snippets}/change-higher-or-equal-role-fail/http-response.adoc[]
include::{snippets}/change-higher-or-equal-role-fail/response-fields.adoc[]
include::{snippets}/change-role-fail-higher-role/http-response.adoc[]
include::{snippets}/change-role-fail-higher-role/response-fields.adoc[]

{nbsp}

[[not-manageable-change-role-fail]]
=== 다른 유저의 역할 변경 실패: 매니저 등급보다 낮은 역할의 유저는 다른 유저의 역할을 변경할 수 없다
[[change-role-fail-not-manageable-user]]
=== 다른 유저의 역할 변경 실패: MANAGER보다 낮은 단계의 유저는 다른 유저의 역할을 변경할 수 없습니다

==== HTTP Request

include::{snippets}/not-manageable-role-fail/http-request.adoc[]
include::{snippets}/not-manageable-role-fail/request-fields.adoc[]
include::{snippets}/change-role-fail-not-manageable-user/http-request.adoc[]
include::{snippets}/change-role-fail-not-manageable-user/request-fields.adoc[]

==== HTTP Response

include::{snippets}/not-manageable-role-fail/http-response.adoc[]
include::{snippets}/not-manageable-role-fail/response-fields.adoc[]
include::{snippets}/change-role-fail-not-manageable-user/http-response.adoc[]
include::{snippets}/change-role-fail-not-manageable-user/response-fields.adoc[]

{nbsp}
2 changes: 2 additions & 0 deletions src/main/java/site/youtogether/config/PropertiesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import site.youtogether.config.property.CookieProperties;
import site.youtogether.config.property.JwtProperties;

@Configuration
@EnableConfigurationProperties(value = {
CookieProperties.class,
JwtProperties.class
})
public class PropertiesConfig {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/site/youtogether/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import java.util.List;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import lombok.RequiredArgsConstructor;
import site.youtogether.util.interceptor.SessionCreateInterceptor;
import site.youtogether.util.interceptor.SingleRoomCheckInterceptor;
import site.youtogether.util.resolver.UserTrackingArgumentResolver;

Expand All @@ -17,6 +19,7 @@
public class WebConfig implements WebMvcConfigurer {

private final SingleRoomCheckInterceptor singleRoomCheckInterceptor;
private final SessionCreateInterceptor sessionCreateInterceptor;
private final UserTrackingArgumentResolver userTrackingArgumentResolver;

@Override
Expand All @@ -30,6 +33,9 @@ public void addCorsMappings(CorsRegistry registry) {

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(sessionCreateInterceptor)
.addPathPatterns("/**")
.order(Ordered.HIGHEST_PRECEDENCE);
registry.addInterceptor(singleRoomCheckInterceptor)
.addPathPatterns("/rooms/**");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package site.youtogether.config.property;

import org.springframework.boot.context.properties.ConfigurationProperties;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@ConfigurationProperties("cookie")
@RequiredArgsConstructor
@Getter
public class CookieProperties {

private final String name;
private final String domain;
private final String path;
private final String sameSite;
private final int expiry;

}
7 changes: 6 additions & 1 deletion src/main/java/site/youtogether/exception/ErrorType.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ public enum ErrorType {
NOT_MANAGEABLE(HttpStatus.FORBIDDEN, "다른 사람의 역할을 변경할 수 없습니다"),
CHAT_MESSAGE_SEND_DENIED(HttpStatus.FORBIDDEN, "채팅 메시지를 보낼 권한이 없습니다"),
ROOM_TITLE_CHANGE_DENIED(HttpStatus.FORBIDDEN, "방 제목을 변경할 권한이 없습니다"),
USERS_IN_DIFFERENT_ROOM(HttpStatus.BAD_REQUEST, "해당 방에 두 유저가 존재하지 않습니다"),

// Room
ROOM_NO_EXISTENCE(HttpStatus.NOT_FOUND, "방이 없습니다"),
SINGLE_ROOM_PARTICIPATION_VIOLATION(HttpStatus.BAD_REQUEST, "하나의 방에만 참가할 수 있습니다"),
ROOM_PASSWORD_NOT_MATCH(HttpStatus.FORBIDDEN, "패스워드가 일치하지 않습니다"),
ROOM_CAPACITY_EXCEEDED(HttpStatus.FORBIDDEN, "방의 참가 인원이 가득 찼습니다");
ROOM_CAPACITY_EXCEEDED(HttpStatus.FORBIDDEN, "방의 참가 인원이 가득 찼습니다"),
USER_ABSENT(HttpStatus.BAD_REQUEST, "방 안에 사용자가 존재하지 않습니다"),

// Cookie
COOKIE_NO_EXISTENCE(HttpStatus.UNAUTHORIZED, "쿠키가 없습니다");

private final HttpStatus status;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package site.youtogether.exception.cookie;

import site.youtogether.exception.CustomException;
import site.youtogether.exception.ErrorType;

public class CookieNoExistenceException extends CustomException {

public CookieNoExistenceException() {
super(ErrorType.COOKIE_NO_EXISTENCE);
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package site.youtogether.exception.room;

import site.youtogether.exception.CustomException;
import site.youtogether.exception.ErrorType;

public class UserAbsentException extends CustomException {

public UserAbsentException() {
super(ErrorType.USER_ABSENT);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package site.youtogether.exception.user;

import site.youtogether.exception.CustomException;
import site.youtogether.exception.ErrorType;

public class UsersInDifferentRoomException extends CustomException {

public UsersInDifferentRoomException() {
super(ErrorType.USERS_IN_DIFFERENT_ROOM);
}

}
22 changes: 10 additions & 12 deletions src/main/java/site/youtogether/jwt/JwtService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import io.jsonwebtoken.UnsupportedJwtException;
import lombok.RequiredArgsConstructor;
import site.youtogether.config.property.JwtProperties;
import site.youtogether.exception.jwt.AuthorizationHeaderNoExistenceException;
import site.youtogether.exception.jwt.InvalidTokenException;

@Service
Expand All @@ -40,15 +39,12 @@ public String issue(Long userId, Duration expiry) {
.compact();
}

public Long parse(String authorizationHeader) {
validationAuthorizationHeader(authorizationHeader);
String token = extract(authorizationHeader);
public Long parse(String token) {
try {
Claims claims = Jwts.parser()
.setSigningKey(jwtProperties.getSecretKey())
.parseClaimsJws(token)
.getBody();

return claims.get(USER_ID, Long.class);
} catch (ExpiredJwtException e) {
throw new IllegalArgumentException("토큰 시간 만료");
Expand All @@ -59,14 +55,16 @@ public Long parse(String authorizationHeader) {
}
}

private void validationAuthorizationHeader(String header) {
if (header == null || !header.startsWith(BEARER)) {
throw new AuthorizationHeaderNoExistenceException();
public boolean isValidToken(String token) {
try {
Jwts.parser()
.setSigningKey(jwtProperties.getSecretKey())
.parseClaimsJws(token)
.getBody();
return true;
} catch (ExpiredJwtException | UnsupportedJwtException | MalformedJwtException | SignatureException e) {
return false;
}
}

private String extract(String authorizationHeader) {
return authorizationHeader.substring(BEARER.length());
}

}
2 changes: 1 addition & 1 deletion src/main/java/site/youtogether/message/MessageType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public enum MessageType {

CHAT, PARTICIPANTS_INFO, ROOM_TITLE
CHAT, PARTICIPANTS, ROOM_TITLE

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import site.youtogether.user.dto.UserInfo;
import site.youtogether.room.Participant;

@RequiredArgsConstructor
@Getter
public class ParticipantsInfoMessage {
public class ParticipantsMessage {

private final MessageType messageType = MessageType.PARTICIPANTS_INFO;
private final MessageType messageType = MessageType.PARTICIPANTS;

private final List<UserInfo> participants;
private final List<Participant> participants;

}
Loading

0 comments on commit ea043fc

Please sign in to comment.