Skip to content

Commit

Permalink
Merge pull request #146 from Garodden/hotfix/user
Browse files Browse the repository at this point in the history
Feat: User API 수정
  • Loading branch information
lth01 authored May 12, 2024
2 parents 03261c6 + 1955658 commit 9cb4d83
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/front/src/components/Layout/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -39,7 +40,7 @@ const Header = () =>{
<ArticleDialog>
<Button className="bg-[#6866EB] hover:bg-violet-600">Create</Button>
</ArticleDialog>
<Button className="bg-[#6866EB] hover:bg-violet-600">Logout</Button>
<Button onClick={logout} className="bg-[#6866EB] hover:bg-violet-600">Logout</Button>
</div>
</header>
);
Expand Down
6 changes: 3 additions & 3 deletions src/front/src/routes/Mypage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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인지 판단한 후 구별이 가능
Expand All @@ -28,7 +28,7 @@ const MyPage = () => {
const [file, setFile] = useState(null);

useEffect(() =>{
fetchUserProfile("[email protected]")
fetchLoginUserProfile()
.then(async (userInfo) => {
setUsername(userInfo.realName);
setIdentity(userInfo.identity);
Expand All @@ -46,7 +46,7 @@ const MyPage = () => {

//프로필 변경 사항 저장 API
const doSaveProfile = () =>{
const reqParam = saveProfileReqParam("[email protected]", identity, location, description, file);
const reqParam = saveProfileReqParam(identity, location, description, file);

saveProfile(reqParam)
.then((response) => {
Expand Down
2 changes: 1 addition & 1 deletion src/front/src/routes/Resign.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Resign = () => {

const handleResign = () => {
//가데이터
const reqParam = withdrawReqParam("[email protected]", currentPassword, true);
const reqParam = withdrawReqParam(currentPassword, true);

withdraw(reqParam)
.then((response) => {
Expand Down
2 changes: 1 addition & 1 deletion src/front/src/routes/Signup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const Signup = () =>{
}

const doLogin = () =>{
nevigate("/");
nevigate("/login");
};

return (
Expand Down
8 changes: 4 additions & 4 deletions src/front/src/routes/Test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";


Expand All @@ -37,19 +37,19 @@ const Test = () => {

const userProfileDemo = () =>{

fetchUserProfile(email)
fetchLoginUserProfile()
.then((data) => {console.log(data)});
}

const userWithdraw = (bool) =>{
const reqParam = withdrawReqParam("[email protected]", "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));
Expand Down
21 changes: 17 additions & 4 deletions src/front/src/utils/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
}

Expand Down
12 changes: 3 additions & 9 deletions src/front/src/utils/Parameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit 9cb4d83

Please sign in to comment.