From 1955658d34acff0c7fb2970ee4876652e2498728 Mon Sep 17 00:00:00 2001 From: lth01 Date: Sun, 12 May 2024 14:24:59 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20User=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 프론트 화면 API 로직 및 API 파라미터 게터 메서드 수정 2. 화면상 API 테스트 진행 Resolve: #144 --- src/front/src/components/Layout/Header.jsx | 3 ++- src/front/src/routes/Mypage.jsx | 6 +++--- src/front/src/routes/Resign.jsx | 2 +- src/front/src/routes/Signup.jsx | 2 +- src/front/src/routes/Test.jsx | 8 ++++---- src/front/src/utils/API.js | 21 +++++++++++++++++---- src/front/src/utils/Parameter.js | 12 +++--------- 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/front/src/components/Layout/Header.jsx b/src/front/src/components/Layout/Header.jsx index 28b339b..4228c8b 100644 --- a/src/front/src/components/Layout/Header.jsx +++ b/src/front/src/components/Layout/Header.jsx @@ -4,6 +4,7 @@ import SearchIcon from "../svg/SearchIcon"; import { Input } from "../ui/input"; import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar"; import ArticleDialog from "@/components/ArticleDialog"; +import { logout } from "@/utils/API"; const Header = () =>{ return ( @@ -39,7 +40,7 @@ const Header = () =>{ - + ); diff --git a/src/front/src/routes/Mypage.jsx b/src/front/src/routes/Mypage.jsx index f6700e1..85fcafe 100644 --- a/src/front/src/routes/Mypage.jsx +++ b/src/front/src/routes/Mypage.jsx @@ -10,7 +10,7 @@ import FollowInfo from "@/components/FollowInfo"; import MyResumes from "@/components/MyResumes"; import { anchorScrollCallback } from "@/utils/common"; import { saveProfileReqParam } from "@/utils/Parameter"; -import { fetchUserProfile, saveProfile } from "@/utils/API"; +import { fetchLoginUserProfile, saveProfile } from "@/utils/API"; const MyPage = () => { //Mypage, UserPage는 유저 정보를 통해 pageOwner인지 판단한 후 구별이 가능 @@ -28,7 +28,7 @@ const MyPage = () => { const [file, setFile] = useState(null); useEffect(() =>{ - fetchUserProfile("dlxogml11235@naver.com") + fetchLoginUserProfile() .then(async (userInfo) => { setUsername(userInfo.realName); setIdentity(userInfo.identity); @@ -46,7 +46,7 @@ const MyPage = () => { //프로필 변경 사항 저장 API const doSaveProfile = () =>{ - const reqParam = saveProfileReqParam("dlxogml11235@naver.com", identity, location, description, file); + const reqParam = saveProfileReqParam(identity, location, description, file); saveProfile(reqParam) .then((response) => { diff --git a/src/front/src/routes/Resign.jsx b/src/front/src/routes/Resign.jsx index 5912a3f..9b21680 100644 --- a/src/front/src/routes/Resign.jsx +++ b/src/front/src/routes/Resign.jsx @@ -14,7 +14,7 @@ const Resign = () => { const handleResign = () => { //가데이터 - const reqParam = withdrawReqParam("dlxogml11235@naver.com", currentPassword, true); + const reqParam = withdrawReqParam(currentPassword, true); withdraw(reqParam) .then((response) => { diff --git a/src/front/src/routes/Signup.jsx b/src/front/src/routes/Signup.jsx index 368f978..a95cef5 100644 --- a/src/front/src/routes/Signup.jsx +++ b/src/front/src/routes/Signup.jsx @@ -78,7 +78,7 @@ const Signup = () =>{ } const doLogin = () =>{ - nevigate("/"); + nevigate("/login"); }; return ( diff --git a/src/front/src/routes/Test.jsx b/src/front/src/routes/Test.jsx index 8e06be3..4e23a9e 100644 --- a/src/front/src/routes/Test.jsx +++ b/src/front/src/routes/Test.jsx @@ -18,7 +18,7 @@ import ChatBox from "@/components/ChatBox"; import FollowInfo from "@/components/FollowInfo"; import MyResumes from "@/components/MyResumes"; import UserPage from "./UserPage"; -import { fetchUserProfile, saveProfile, withdraw } from "@/utils/API"; +import { fetchLoginUserProfile, saveProfile, withdraw } from "@/utils/API"; import { saveProfileReqParam, withdrawReqParam } from "@/utils/Parameter"; @@ -37,19 +37,19 @@ const Test = () => { const userProfileDemo = () =>{ - fetchUserProfile(email) + fetchLoginUserProfile() .then((data) => {console.log(data)}); } const userWithdraw = (bool) =>{ - const reqParam = withdrawReqParam("dlxogml11235@naver.com", "Dlxogml!135", bool); + const reqParam = withdrawReqParam("Dlxogml!135", bool); withdraw(reqParam) .then(data => console.log(data)); } const saveUserProfile = () =>{ - const reqParam = saveProfileReqParam(email, "123","서울","ㄷㅈ매럊믇ㄹ",file); + const reqParam = saveProfileReqParam("123","서울","ㄷㅈ매럊믇ㄹ",file); saveProfile(reqParam) .then(response => console.log(response)); diff --git a/src/front/src/utils/API.js b/src/front/src/utils/API.js index 42258b7..4b304b2 100644 --- a/src/front/src/utils/API.js +++ b/src/front/src/utils/API.js @@ -112,7 +112,7 @@ export const login = async (loginReqParam) =>{ //비밀번호 찾기 질문 리스트 조회 /** - * @returns { {id: String, question: String} Array} + * @returns { {id: String, question: String}[]} */ export const fetchPasswordQuestions = async () =>{ const passwordQuestionURL = URL + "/api/passwordquestion"; @@ -133,10 +133,23 @@ export const changePassword = async (changePasswordReqParam) =>{ .then((response) => response.data); } -export const fetchUserProfile = async (email) =>{ - const fetchUserProfileURL = URL + `/api/user?email=${email}`; +/** + * @breif 로그인한 유저의 profile data load + */ +export const fetchLoginUserProfile = async () =>{ + const fetchLoginUserProfileURL = `${URL}/api/user`; + + return OneinkedGet(fetchLoginUserProfileURL) + .then((response) => response.data); +} + +/** + * @breif 다른 유저의 profile data load + */ +export const fetchAnotherUserProfile = async (email) =>{ + const fetchAnotherUserProfileURL = URL + `/api/user?email=${email}`; - return OneinkedGet(fetchUserProfileURL) + return OneinkedGet(fetchAnotherUserProfileURL) .then((response) => response.data); } diff --git a/src/front/src/utils/Parameter.js b/src/front/src/utils/Parameter.js index 6a5c96b..d85d06e 100644 --- a/src/front/src/utils/Parameter.js +++ b/src/front/src/utils/Parameter.js @@ -31,17 +31,15 @@ export const changePasswordReqParam = (email, passwordQuestionId, passwordQuesti /** * @brief 프로필 저장 API는 form데이터 형식을 받으므로 이렇게 변경 - * @param {String} email * @param {String} identity * @param {String} location * @param {String} description * @param {File} file * @returns */ -export const saveProfileReqParam = (email, identity, location, description, file) =>{ +export const saveProfileReqParam = (identity, location, description, file) =>{ const reqFormData = new FormData(); - reqFormData.append('email', email); reqFormData.append('identity', identity); reqFormData.append('location', location); reqFormData.append('description', description); @@ -52,13 +50,11 @@ export const saveProfileReqParam = (email, identity, location, description, file /** * - * @param {String} email * @param {String} password * @param {Boolean} withdraw */ -export const withdrawReqParam = (email, password, withdraw) =>{ +export const withdrawReqParam = (password, withdraw) =>{ const reqParam = {}; - reqParam.email = email; reqParam.password = password; reqParam.withdraw = withdraw; @@ -67,13 +63,11 @@ export const withdrawReqParam = (email, password, withdraw) =>{ /** * multipart/form-data형태로 호출하는 API이므로 - * @param {String} email * @param {File} file */ -export const userImageUploadReqParam = (email, file) =>{ +export const userImageUploadReqParam = (file) =>{ const reqFormData = new FormData(); - reqFormData.append('email', email); reqFormData.append('file', file); return reqFormData;