Skip to content

Commit

Permalink
refactor(CookieManager): 클래스의 책임에 맞도록 상수 및 변수 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
seokmyungham committed Aug 3, 2024
1 parent dfb14f5 commit a7cb04e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
13 changes: 5 additions & 8 deletions backend/src/main/java/kr/momo/controller/CookieManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ public class CookieManager {

private static final String ACCESS_TOKEN = "ACCESS_TOKEN";
private static final String SAME_SITE_OPTION = "None";
private static final long SESSION_COOKIE_AGE = -1;
private static final long EXPIRED_COOKIE_AGE = 0;

public String createNewCookie(String value, String uuid, long maxAge) {
return createCookie(value, buildPath(uuid), maxAge);
public String createNewCookie(String value, String path) {
return createCookie(value, path, SESSION_COOKIE_AGE);
}

public String createExpiredCookie(String uuid) {
return createCookie("", buildPath(uuid), EXPIRED_COOKIE_AGE);
public String createExpiredCookie(String path) {
return createCookie("", path, EXPIRED_COOKIE_AGE);
}

private String createCookie(String value, String path, long maxAge) {
Expand All @@ -28,8 +29,4 @@ private String createCookie(String value, String path, long maxAge) {
.build()
.toString();
}

private String buildPath(String uuid) {
return String.format("/meeting/%s", uuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
@RequiredArgsConstructor
public class AttendeeController {

private static final long SESSION_COOKIE_AGE = -1;

private final AttendeeService attendeeService;
private final CookieManager cookieManager;

Expand All @@ -28,7 +26,8 @@ public ResponseEntity<MomoApiResponse<String>> login(
@PathVariable String uuid, @RequestBody @Valid AttendeeLoginRequest request
) {
AttendeeLoginResponse response = attendeeService.login(uuid, request);
String cookie = cookieManager.createNewCookie(response.token(), uuid, SESSION_COOKIE_AGE);
String path = String.format("/meeting/%s", uuid);
String cookie = cookieManager.createNewCookie(response.token(), path);

return ResponseEntity.ok()
.header(HttpHeaders.SET_COOKIE, cookie)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public ResponseEntity<MomoApiResponse<MeetingCreateResponse>> create(
@RequestBody @Valid MeetingCreateRequest request
) {
MeetingCreateResponse response = meetingService.create(request);
String cookie = cookieManager.createNewCookie(response.token(), response.uuid(), -1);
String path = String.format("/meeting/%s", response.uuid());
String cookie = cookieManager.createNewCookie(response.token(), path);

return ResponseEntity.created(URI.create("/meeting/" + response.uuid()))
.header(HttpHeaders.SET_COOKIE, cookie)
Expand Down

0 comments on commit a7cb04e

Please sign in to comment.