95 lines
3.2 KiB
Python
95 lines
3.2 KiB
Python
"""
|
|
유저 관련 API 엔드포인트
|
|
"""
|
|
|
|
from flask import request, g
|
|
from flask_restx import Resource
|
|
from flask_jwt_extended import jwt_required, get_jwt
|
|
|
|
from utils.response import *
|
|
from utils.swagger_config import user_ns
|
|
from utils.decorators import load_current_user
|
|
|
|
from models.user_model import user_swagger
|
|
|
|
from services.user.user_service import UserService
|
|
|
|
@user_ns.route("/me")
|
|
class MyProfile(Resource):
|
|
@user_ns.doc(
|
|
id="get_my_profile",
|
|
summary="내 프로필 조회",
|
|
description="현재 로그인한 사용의 프로필을 조회합니다. (토큰 기반)",
|
|
tags=["Users"],
|
|
security=[{"Bearer": []}]
|
|
)
|
|
@user_ns.response(200, "Success - 프로필 조회 완료")
|
|
@user_ns.response(401, "인증 실패에 실패하였습니다.")
|
|
@user_ns.response(500, "서버 내부 오류")
|
|
@jwt_required()
|
|
@load_current_user
|
|
def get(self):
|
|
"""내 프로필 조회"""
|
|
return success_response(
|
|
data=g.current_user.to_dict(),
|
|
message="프로필 조회 성공"
|
|
)
|
|
|
|
@user_ns.doc(
|
|
id="update_my_profile",
|
|
summary="내 프로필 업데이트",
|
|
description="현재 로그인한 사용자의 프로필을 업데이트 합니다. (토큰 기반)",
|
|
tags=["Users"],
|
|
security=[{"Bearer": []}]
|
|
)
|
|
@user_ns.expect(user_swagger.update_profile_model)
|
|
@user_ns.response(200, "Success - 프로필 업데이트 완료")
|
|
@user_ns.response(400, "잘못된 요청 데이터")
|
|
@user_ns.response(401, "인증 실패에 실패하였습니다.")
|
|
@user_ns.response(500, "서버 내부 오류")
|
|
@jwt_required()
|
|
@load_current_user
|
|
def put(self):
|
|
"""내 프로필 업데이트"""
|
|
user = g.current_user
|
|
data = request.get_json()
|
|
|
|
updated_user = UserService.update_user_profile(user.user_uuid, data)
|
|
return success_response(
|
|
data=updated_user.to_dict(),
|
|
message="프로필 업데이트 성공"
|
|
)
|
|
|
|
@user_ns.doc(
|
|
id="delete_my_account",
|
|
summary="회원 탈퇴",
|
|
description="현재 로그인한 사용자의 계정을 삭제합니다. (토큰 기반). 탈퇴 후 모든 데이터가 삭제되며 복구할 수 없습니다.",
|
|
tags=["Users"],
|
|
security=[{"Bearer": []}]
|
|
)
|
|
@user_ns.response(200, "Success - 회원 탈퇴 완료")
|
|
@user_ns.response(401, "인증에 실패하였습니다.")
|
|
@user_ns.response(404, "사용자를 찾을 수 없습니다.")
|
|
@user_ns.response(500, "서버 내부 오류")
|
|
@jwt_required()
|
|
@load_current_user
|
|
def delete(self):
|
|
"""회원 탈퇴"""
|
|
user = g.current_user
|
|
|
|
# JWT ID 추출 (로그아웃 처리용)
|
|
jwt_data = get_jwt()
|
|
jti = jwt_data.get("jti")
|
|
|
|
# 사용자 삭제 (캐시 무효화 + JWT 블랙리스트 추가 포함)
|
|
success = UserService.delete_user(user.user_uuid, jti=jti)
|
|
|
|
if not success:
|
|
return error_response(
|
|
message="회원 탈퇴에 실패했습니다.",
|
|
status_code=404
|
|
)
|
|
|
|
return success_response(
|
|
message="회원 탈퇴가 완료되었습니다."
|
|
) |