Skip to content

Commit d541a98

Browse files
authored
Merge pull request #45 from Grow-Fit/feat/44-logout
로그아웃 기능 구현
2 parents 9a31be8 + 88aff54 commit d541a98

22 files changed

Lines changed: 382 additions & 138 deletions

src/main/java/com/project/growfit/domain/Diet/service/impl/DietServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public ResultResponse<?> uploadPhoto(Long dietId, MultipartFile image) {
207207
Diet diet = getDietOrThrow(dietId);
208208
String imageUrl = s3UploadService.saveFile(image, imageUploadPath);
209209
diet.updateImage(imageUrl);
210-
return ResultResponse.of(ResultCode.CHILD_PHOTO_UPLOAD_SUCCESS, null);
210+
return ResultResponse.of(ResultCode.DIET_ADD_IMAGE_SUCCESS, null);
211211
}
212212

213213
@Override
@@ -235,7 +235,7 @@ public ResultResponse<?> updateDietTime(Long dietId, String newTime) {
235235
authenticatedProvider.getAuthenticatedParent();
236236
Diet diet = getDietOrThrow(dietId);
237237
diet.updateTime(parseTimeOrThrow(newTime));
238-
return ResultResponse.of(ResultCode.DIET_TIME_UPDATE_SUCCESS, null);
238+
return ResultResponse.of(ResultCode.DIET_EDIT_SUCCESS, null);
239239
}
240240

241241

src/main/java/com/project/growfit/domain/Diet/service/impl/DietSetServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public ResultResponse<?> getDietSetDetail(Long dietSetId) {
8787
).toList();
8888

8989
DietSetDetailResponseDto response = new DietSetDetailResponseDto(set.getSetName(), foodDetails);
90-
return ResultResponse.of(ResultCode.DIET_SET_DETAIL_SUCCESS, response);
90+
return ResultResponse.of(ResultCode.DIET_SET_RETRIEVAL_SUCCESS, response);
9191
}
9292

9393
@Override

src/main/java/com/project/growfit/domain/Goal/entity/Certification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
@Getter
1818
@Entity
19-
@Table(name = "goal")
19+
@Table(name = "cert_goal")
2020
@NoArgsConstructor(access = AccessLevel.PROTECTED)
2121
public class Certification {
2222

src/main/java/com/project/growfit/domain/User/controller/AuthChildController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ public ResponseEntity<?> loginChild(@RequestBody AuthChildRequestDto request, Ht
4242
ResultResponse<?> resultResponse = authChildService.login(request, response);
4343

4444
return ResponseEntity.status(HttpStatus.OK).body(resultResponse);
45+
}
46+
47+
@Operation(summary = "아이 로그아웃")
48+
@PostMapping("/logout")
49+
public ResponseEntity<?> logoutChild(HttpServletResponse response) {
50+
ResultResponse<String> resultResponse = authChildService.logout(response);
4551

52+
return ResponseEntity.status(HttpStatus.OK).body(resultResponse);
4653
}
4754

4855
@Operation(summary = "아이 인증코드로 ID 찾기")
@@ -51,7 +58,6 @@ public ResponseEntity<?> findChildIdByCode(@RequestParam String code) {
5158
ResultResponse<?> resultResponse = authChildService.findChildID(code);
5259

5360
return ResponseEntity.status(HttpStatus.OK).body(resultResponse);
54-
5561
}
5662

5763
@Operation(summary = "아이 비밀번호 재설정")

src/main/java/com/project/growfit/domain/User/controller/OAuthController.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
import com.project.growfit.domain.User.dto.response.ParentLoginResponseDto;
44
import com.project.growfit.domain.User.service.OauthService;
55
import com.project.growfit.global.exception.BusinessException;
6+
import com.project.growfit.global.response.ResultCode;
67
import com.project.growfit.global.response.ResultResponse;
78
import io.swagger.v3.oas.annotations.Operation;
89
import io.swagger.v3.oas.annotations.tags.Tag;
910
import jakarta.servlet.http.HttpServletResponse;
1011
import lombok.RequiredArgsConstructor;
1112
import org.springframework.http.HttpStatus;
1213
import org.springframework.http.ResponseEntity;
13-
import org.springframework.web.bind.annotation.GetMapping;
14-
import org.springframework.web.bind.annotation.RequestMapping;
15-
import org.springframework.web.bind.annotation.RequestParam;
16-
import org.springframework.web.bind.annotation.RestController;
14+
import org.springframework.web.bind.annotation.*;
1715

1816
@RestController
1917
@RequestMapping("/oauth")
@@ -23,9 +21,9 @@ public class OAuthController {
2321

2422
private final OauthService oauthService;
2523

26-
@Operation(summary = "카카오 소셜 로그인 콜백 컨트롤러 입니다.")
24+
@Operation(summary = "카카오 소셜 로그인 API")
2725
@GetMapping("/callback/kakao")
28-
public void getKaKaoAuthorizeCode(@RequestParam(value = "code", required = false) String code,
26+
public void kakaoLogin(@RequestParam(value = "code", required = false) String code,
2927
HttpServletResponse response) {
3028
if (code == null) {
3129
try {
@@ -57,4 +55,12 @@ public void getKaKaoAuthorizeCode(@RequestParam(value = "code", required = false
5755
}
5856
}
5957
}
58+
59+
@Operation(summary = "카카오 소셜 로그아웃 API")
60+
@PostMapping("/logout")
61+
public ResultResponse<String> kakaoLogout(@RequestParam(value = "code", required = false) String code,
62+
HttpServletResponse response) {
63+
return oauthService.kakaoLogout(code, response);
64+
65+
}
6066
}

src/main/java/com/project/growfit/domain/User/controller/TestAuthController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ public ResultResponse<?> generateToken(@RequestBody Map<String, String> request,
3838

3939
log.info("로그인 성공: email={}, accessToken 저장 완료", email);
4040
ParentLoginResponseDto dto = new ParentLoginResponseDto(email, true);
41-
return new ResultResponse<>(ResultCode.PARENT_LOGIN_SUCCESS, dto);
41+
return new ResultResponse<>(ResultCode.LOGIN_SUCCESS, dto);
4242
}
4343
}

src/main/java/com/project/growfit/domain/User/service/AuthChildService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public interface AuthChildService {
99
ResultResponse<?> findByCode(String code);
1010
ResultResponse<?> registerChildCredentials(Long child_id, AuthChildRequestDto request);
1111
ResultResponse<?> login(AuthChildRequestDto request, HttpServletResponse response);
12+
ResultResponse<String> logout(HttpServletResponse response);
1213
ResultResponse<?> findChildID(String code);
1314
ResultResponse<?> findChildPassword(FindChildPasswordRequestDto request);
1415
}

src/main/java/com/project/growfit/domain/User/service/OauthService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public interface OauthService {
1313
String getKakaoAccessToken(String code);
1414
HashMap<String, Object> getUserKakaoInfo(String access_token);
1515
ResultResponse<?> kakaoLogin(String access_token, HttpServletResponse response);
16+
ResultResponse<String> kakaoLogout(String access_token, HttpServletResponse response);
1617
ParentResponse findByUserKakaoIdentifier(String kakaoIdentifier);
1718
Long signUp(ParentOAuthRequestDto requestDto);
19+
20+
1821
}

src/main/java/com/project/growfit/domain/User/service/impl/AuthChildServiceImpl.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.project.growfit.domain.User.service.AuthChildService;
1010
import com.project.growfit.global.auth.cookie.CookieService;
1111
import com.project.growfit.global.auth.jwt.JwtProvider;
12+
import com.project.growfit.global.auth.service.AuthenticatedUserProvider;
1213
import com.project.growfit.global.auth.service.CustomAuthenticationProvider;
1314
import com.project.growfit.global.exception.BusinessException;
1415
import com.project.growfit.global.exception.ErrorCode;
@@ -37,14 +38,15 @@ public class AuthChildServiceImpl implements AuthChildService {
3738
private final JwtProvider jwtProvider;
3839
private final TokenRedisRepository tokenRedisRepository;
3940
private final CustomAuthenticationProvider authenticationProvider;
41+
private final AuthenticatedUserProvider authenticatedUser;
4042

4143
public ResultResponse<?> findByCode(String code) {
4244
log.info("[findByCode] 코드로 아이 정보 조회 요청: {}", code);
4345
Child child = getChild(code);
4446
Long childPid = child.getId();
4547

4648
log.info("[findByCode] 아이 정보 PID 조회 성공: {}", childPid);
47-
return new ResultResponse<>(ResultCode.CHILD_INFO_RETRIEVAL_SUCCESS, new ChildIdResponse(childPid));
49+
return new ResultResponse<>(ResultCode.INFO_SUCCESS, new ChildIdResponse(childPid));
4850
}
4951

5052
@Override
@@ -62,7 +64,7 @@ public ResultResponse<?> registerChildCredentials(Long child_id, AuthChildReques
6264
}
6365

6466
log.info("[registerChildCredentials] 아이 계정 정보 등록 완료: child_id={}", child_id);
65-
return new ResultResponse<>(ResultCode.PARENT_SIGNUP_SUCCESS, null);
67+
return new ResultResponse<>(ResultCode.INFO_REGISTRATION_SUCCESS, null);
6668
}
6769

6870

@@ -95,7 +97,20 @@ public ResultResponse<?> login(AuthChildRequestDto request, HttpServletResponse
9597
cookieService.saveAccessTokenToCookie(response, newAccessToken);
9698
log.debug("[login] AccessToken을 쿠키에 저장 완료: child_login_id={}", request.childId());
9799

98-
return new ResultResponse<>(ResultCode.CHILD_LOGIN_SUCCESS, null);
100+
return new ResultResponse<>(ResultCode.LOGIN_SUCCESS, null);
101+
}
102+
103+
public ResultResponse<String> logout(HttpServletResponse response) {
104+
String loginId = authenticatedUser.getAuthenticatedChild().getLoginId();
105+
log.info("[logout] 아이 로그아웃 요청: loginId={}", loginId);
106+
107+
tokenRedisRepository.deleteById(loginId);
108+
log.debug("[logout] Redis에서 리프레시 토큰 삭제 완료: loginId={}", loginId);
109+
110+
cookieService.clearCookie(response, "accessToken");
111+
log.debug("[logout] accessToken 쿠키 만료 처리 완료: loginId={}", loginId);
112+
113+
return new ResultResponse<>(ResultCode.LOGOUT_SUCCESS, null);
99114
}
100115

101116
public ResultResponse<?> findChildID(String code) {
@@ -104,7 +119,7 @@ public ResultResponse<?> findChildID(String code) {
104119
ChildInfoResponseDto dto = ChildInfoResponseDto.toDto(child);
105120

106121
log.info("[findChildID] 아이 ID 찾기 성공: {}", dto);
107-
return new ResultResponse<>(ResultCode.CHILD_INFO_RETRIEVAL_SUCCESS, dto);
122+
return new ResultResponse<>(ResultCode.INFO_SUCCESS, dto);
108123
}
109124

110125
@Override
@@ -121,7 +136,7 @@ public ResultResponse<?> findChildPassword(FindChildPasswordRequestDto request)
121136
childRepository.save(child);
122137

123138
log.info("[findChildPassword] 비밀번호 변경 완료: user_id={}", request.user_id());
124-
return new ResultResponse<>(ResultCode.PARENT_SIGNUP_SUCCESS, null);
139+
return new ResultResponse<>(ResultCode.INFO_REGISTRATION_SUCCESS, null);
125140
}
126141

127142
private Child getChild(Long child_id) {

src/main/java/com/project/growfit/domain/User/service/impl/AuthParentServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public ResultResponse<?> registerChild(CustomUserDetails user, AuthParentRequest
5656
ChildInfoResponseDto dto = ChildInfoResponseDto.toDto(child);
5757

5858
log.info("[registerChild] 자녀 등록 완료: child_id={}, parent_id={}", child.getId(), parent.getId());
59-
return new ResultResponse<>(ResultCode.PARENT_SIGNUP_SUCCESS, dto);
59+
return new ResultResponse<>(ResultCode.SIGNUP_SUCCESS, dto);
6060
}
6161

6262
@Override

0 commit comments

Comments
 (0)