diff --git a/src/api/employer.ts b/src/api/employer.ts index fe77fb8..314c4b9 100644 --- a/src/api/employer.ts +++ b/src/api/employer.ts @@ -2,49 +2,65 @@ import axios from '@/lib/axios'; import RegisterFormData from '@/types/myShop'; import { default as originAxios } from 'axios'; -export async function postShop(body: RegisterFormData) { - const { address1, address2, category, description, name, originalHourlyPay, image } = body; - - const imageUrl = image - ? `https://bootcamp-project-api.s3.ap-northeast-2.amazonaws.com/${image.name}` - : ''; - - const tmpBody = { - address1, - address2, - category, - description, - name, - originalHourlyPay, - imageUrl, - }; - const { data } = await axios.post('/shops', tmpBody); +export async function postShop(body: Omit) { + const accessToken = localStorage.getItem('thejulge-token'); + const { data } = await axios.post('/shops', body, { + headers: { Authorization: `Bearer ${accessToken}` }, + }); + return data; +} + +export async function getShop(shopId: string) { + const { data } = await axios.get(`/shops/${shopId}`); + return data; +} + +export async function putShop(shopId: string, body: RegisterFormData) { + const accessToken = localStorage.getItem('thejulge-token'); + const { data } = await axios.put(`/shops/${shopId}`, body, { + headers: { Authorization: `Bearer ${accessToken}` }, + }); + return data; } -export async function postPresignedUrl(imageName: string) { - const { data } = await axios.post('/images', { name: imageName }); - // console.log(data); +export async function getNotice(shopId: string) { + const { data } = await axios.get(`/shops/${shopId}/notices`); + return data; +} + +/////////////////////////////////////////////////////////////////////////////// + +export async function postPresignedUrl(imageUrl: string) { + const accessToken = localStorage.getItem('thejulge-token'); + const { data } = await axios.post( + '/images', + { name: imageUrl }, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + } + ); return data.item.url; } export async function uploadImage(presignedUrl: string, file: File) { - const result = await originAxios.put(presignedUrl, file); + try { + await originAxios.put(presignedUrl, file); + } catch (error) { + alert(error); + } } export async function getPresignedUrl(presignedUrl: string) { // 1. URL 객체 생성 const url = new URL(presignedUrl); - // 2. 쿼리 파라미터를 제거 (URL 객체의 search 속성을 비움) url.search = ''; // 3. 쿼리 파라미터가 제거된 새 URL 문자열을 얻습니다. const baseUrl = url.toString(); const result = await originAxios.get(baseUrl); -} - -export async function getShop(shopId: string) { - const { data } = await axios.get(`/shops/${shopId}`); - return data; + return result; } diff --git a/src/components/features/my-shop/registerImage.tsx b/src/components/features/my-shop/registerImage.tsx index c9a2a47..f982160 100644 --- a/src/components/features/my-shop/registerImage.tsx +++ b/src/components/features/my-shop/registerImage.tsx @@ -3,11 +3,12 @@ import Image from 'next/image'; import { ChangeEvent } from 'react'; interface Props { + mode: string; preview: string | null; handleImageChange: (e: ChangeEvent) => void; } -const RegisterImage = ({ preview, handleImageChange }: Props) => { +const RegisterImage = ({ mode, preview, handleImageChange }: Props) => { return ( <>
@@ -17,7 +18,23 @@ const RegisterImage = ({ preview, handleImageChange }: Props) => {