Skip to content

Commit

Permalink
feat: Tag Domain 생성(#44)
Browse files Browse the repository at this point in the history
- Tag Entity 구현
+ AuthService Refactor
  - null 체크 메서드 안으로 이동
  - 정적팩터리 메서드 사용
  • Loading branch information
soonhankwon committed Feb 12, 2024
1 parent 711a3c0 commit a6ada4b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ public record AuthRefreshResponse(
Long id,
String email
) {
public static AuthRefreshResponse of(Long userId, String email) {
return new AuthRefreshResponse(userId, email);
}
}
13 changes: 7 additions & 6 deletions src/main/java/com/compono/ibackend/auth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ public class AuthService {

public AuthRefreshResponse refresh(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {

if (httpServletRequest.getCookies() == null) {
throw new CustomException(HttpStatus.UNAUTHORIZED, ErrorCode.NOT_EXIST_COOKIE);
}

String refreshToken = getCookieFromHttpServletRequest(httpServletRequest);
assert refreshToken != null;

Claims claims = jwtProvider.getClaims(refreshToken);
String email = claims.getSubject();

Expand All @@ -51,14 +48,18 @@ public AuthRefreshResponse refresh(HttpServletRequest httpServletRequest,
String newAccessToken = JWT_PREFIX + newAccessTokenValue;
httpServletResponse.setHeader(HttpHeaders.AUTHORIZATION, newAccessToken);

return new AuthRefreshResponse(userId, email);
return AuthRefreshResponse.of(userId, email);
}

public Claims getClaims(String accessToken) {
return jwtProvider.getClaims(accessToken);
}

private String getCookieFromHttpServletRequest(HttpServletRequest httpServletRequest) {
if (httpServletRequest.getCookies() == null) {
throw new CustomException(HttpStatus.UNAUTHORIZED, ErrorCode.NOT_EXIST_COOKIE);
}

Cookie cookie = Arrays.stream(httpServletRequest.getCookies())
.filter(c -> c.getName().equals(REFRESH_TOKEN_NAME))
.findFirst()
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/compono/ibackend/tag/domain/Tag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.compono.ibackend.tag.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "`tag`")
public class Tag {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "name", nullable = false)
private String name;

@Column(name = "color", nullable = false)
private String color;
}

0 comments on commit a6ada4b

Please sign in to comment.