-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
204 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,39 @@ | ||
import { privateAxios } from "../utils/customAxios"; | ||
import {privateAxios} from "../utils/customAxios"; | ||
|
||
export const postJobPosting = async (accessToken, dispatch, formData) => { | ||
const headers = { | ||
Authorization: `Bearer ${accessToken}`, // Bearer 토큰 설정 | ||
}; | ||
/*---- 게시글 등록 ----*/ | ||
export const postJobPosting = async (payload) => { | ||
|
||
const { workLocation = "" } = formData; | ||
const [doName = "", siName = "", detailName = ""] = workLocation.split(" "); | ||
const { start = "09:00", end = "18:00" } = formData.workTime || {}; | ||
const endpoint = `/api/v1/post`; | ||
|
||
const [startHour, startMinute] = start.split(":").map(Number); | ||
const [endHour, endMinute] = end.split(":").map(Number); | ||
|
||
const body = { | ||
postId: 0, | ||
userId: 1, | ||
storeName: formData.storeName, | ||
workPlaceAddress: formData.workLocation, //주소 필드 해뒀음 | ||
postData: { | ||
doName, | ||
siName, | ||
detailName, | ||
workType: formData.workTags[0] || "기타", | ||
title: formData.title, | ||
content: formData.description, | ||
pay: parseInt(formData.pay, 10), | ||
workStartHour: startHour, | ||
workStartMinute: startMinute, | ||
workEndHour: endHour, | ||
workEndTimeMinute: endMinute, | ||
isNegotiable: formData.isNegotiable || false, | ||
applyNumber: formData.applyNumber, | ||
workDays: formData.workDays.join(","), | ||
isShortTermJob: formData.workPeriod === "단기", | ||
payType: formData.payType, | ||
isNumberPublic: formData.isNumberPublic, | ||
imageList: formData.imageList || [""], // 이미지 리스트 | ||
imageUrlList: [""], // Swagger 요청 구조에 따라서 빈 리스트 추가 | ||
lastUpdatedTime: new Date().toISOString(), | ||
}, | ||
}; | ||
try { | ||
const result = await privateAxios.post(endpoint, payload); | ||
return { | ||
isSuccess: true, | ||
message: result.data.message, | ||
postId: result.data.postId, | ||
}; | ||
} catch (error) { | ||
return { | ||
isSuccess: false, | ||
message: error.response?.data?.message || "API 요청 실패", | ||
}; | ||
} | ||
}; | ||
|
||
const response = { isSuccess: false, message: "" }; | ||
/*---- 게시글 수정 ----*/ | ||
export const updateJobPosting = async (payload) => { | ||
const endpoint = `api/v1/post/update`; | ||
|
||
try { | ||
const result = await privateAxios(accessToken, dispatch).post("/post", body, { headers }); | ||
if (result.status === 200) { | ||
response.isSuccess = true; | ||
response.message = result.data.message; | ||
} | ||
const result = await privateAxios.post(endpoint, payload); | ||
return { | ||
isSuccess: true, | ||
message: result.data.message, | ||
}; | ||
} catch (error) { | ||
response.message = error.response?.data?.message || error.message; | ||
console.error("API 요청 실패:", error); | ||
return { | ||
isSuccess: false, | ||
message: error.response?.data?.message || "API 요청 실패", | ||
}; | ||
} | ||
|
||
return response; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { useLocation, useNavigate } from "react-router-dom"; | ||
const ModifyPost = () => { | ||
navigate(`/post`, { | ||
state: { | ||
mode: "modify", // 수정 모드 설정 | ||
postData: {//세 게시글 데이터 | ||
}, // 현재 게시글 데이터 전달 | ||
}, | ||
}); | ||
}; | ||
// const ModifyPost = () => { | ||
// const location = useLocation(); | ||
// const navigate = useNavigate(); | ||
// const { postId } = location.state || {}; | ||
// const [formData, setFormData] = useState(null); // 기존 게시글 데이터를 담을 state | ||
|
||
// // 게시글 상세 정보 가져오기 | ||
// useEffect(() => { | ||
// if (postId) { | ||
// getPostDetails(postId).then((data) => { | ||
// setFormData(data.postData); // 서버에서 받은 데이터 중 postData만 폼 데이터로 설정 | ||
// }); | ||
// } | ||
// }, [postId]); | ||
|
||
// const handleChange = (key, value) => { | ||
// setFormData((prevData) => ({ | ||
// ...prevData, | ||
// [key]: value, | ||
// })); | ||
// }; | ||
|
||
// // 게시글 수정 API 호출 | ||
// const handleSubmit = async (e) => { | ||
// e.preventDefault(); | ||
// const response = await updatePost(postId, formData); | ||
// if (response.isSuccess) { | ||
// alert("게시글이 성공적으로 수정되었습니다."); | ||
// navigate(`/post/detail/${postId}`); // 수정된 게시글 상세 페이지로 이동하도록 설정 | ||
// } else { | ||
// alert("게시글 수정에 실패했습니다."); | ||
// } | ||
// }; | ||
|
||
// return ( | ||
// formData && ( | ||
// <form onSubmit={handleSubmit}> | ||
// {/* 수정할 폼들을 넣을 필드 이후에 작성 예정, 여기서 handlChange*/} | ||
// {/* <label>내용</label> | ||
// <textarea | ||
// value={formData.content} | ||
// onChange={(e) => handleChange("content", e.target.value)} | ||
// ></textarea> */} | ||
|
||
// <button type="submit">저장</button> | ||
// </form> | ||
// ) | ||
// ); | ||
// }; | ||
|
||
export default ModifyPost; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters