Skip to content

Commit

Permalink
merge :: 배너 API 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
은지 committed Jun 8, 2024
2 parents dabfe1f + 38ad910 commit 048d539
Show file tree
Hide file tree
Showing 18 changed files with 1,005 additions and 216 deletions.
78 changes: 38 additions & 40 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
name: node.js CI

on:
push:
branches:
- "feature/**"
- "hotfixes"
- "develop"
- "main"
pull_request:
branches:
- "develop"
push:
branches:
- 'feature/**'
- 'hotfixes'
- 'develop'
- 'main'
pull_request:
branches:
- 'develop'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3

- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: "**/node_modules"
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
# 이전의 cache가 없다면 의존성을 설치합니다.
if: steps.cache.outputs.cache-hit != 'true'
run: npm ci

- name: Build Packages
run: npm run build
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3

- name: Cache dependencies
id: cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
run: npm install

- name: Build Packages
run: npm run build
50 changes: 50 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions src/Apis/Banners/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { MutationOptions, useMutation, useQuery } from 'react-query';
import { instance } from '../axios';
import { BannerListResponse } from './response';
import { useToastStore } from '@team-return/design-system';

const router = '/banners';

export const useCreateBanners = (
detail_id: number,
banner_type: string,
start_date: string,
end_date: string
) => {
const data = {
detail_id,
banner_type,
start_date,
end_date,
};
const { append } = useToastStore();

return useMutation(
async (banner_url: string) =>
instance.post(`${router}`, { ...data, banner_url }),
{
onSuccess: () => {
append({
title: '성공적으로 추가되었습니다.',
message: '',
type: 'GREEN',
});
},
onError: () => {
append({
title: '추가에 실패했습니다.',
message: '',
type: 'RED',
});
},
}
);
};

export const useGetBannerList = (is_opened: boolean) => {
const params = {
is_opened,
};
return useQuery(['getBannerList', is_opened], async () => {
const { data } = await instance.get<BannerListResponse>(
`${router}/teacher`,
{
params,
}
);
return data;
});
};

export const useDeleteBanner = (
banner_id: number,
options: MutationOptions
) => {
return useMutation(
async () => {
const { data } = await instance.delete(`${router}/${banner_id}`);
return data;
},
{
...options,
}
);
};
10 changes: 10 additions & 0 deletions src/Apis/Banners/request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface DateProps {
banner_url: string;
start_date: string;
end_date: string;
banner_type: string;
}

export interface BannerProps {
banner_id: number;
}
19 changes: 19 additions & 0 deletions src/Apis/Banners/response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface BannerListProps {
id: number;
banner_url: string;
start_date: string;
end_date: string;
banner_type: string;
}

export interface BannerListResponse {
banners: BannerListProps[];
}

export interface BannerNameType {
RECRUITMENT: string;
BOOKMARK: string;
NONE: string;
INTERNSHIP: string;
COMPANY: string;
}
48 changes: 35 additions & 13 deletions src/Apis/Files/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,54 @@ import { PresignedUrlResponse } from './response';
import { instance } from '../axios';
import axios from 'axios';

const EXTENSION_FILE = 'EXTENSION_FILE';

export const usePresignedUrl = () => {
const res = useMutation(
return useMutation(
async (attachments: File[]) => {
const files = attachments.map((item) => ({
type: 'EXTENSION_FILE',
type: EXTENSION_FILE,
file_name: item.name,
}));

const { data: presignedUrls } =
await instance.post<PresignedUrlResponse>(
`${process.env.REACT_APP_BASE_URL}/files/pre-signed`,
{ files }
);
await instance.post<PresignedUrlResponse>(`/files/pre-signed`, {
files,
});
return { presignedUrls, attachments };
},
{
onSuccess: async ({ presignedUrls, attachments }) => {
const uploadPromises = await Promise.all(
presignedUrls.urls.map(({ pre_signed_url }, idx) => {
return axios.put(pre_signed_url, attachments[idx]);
})
onSuccess: async ({
presignedUrls,
attachments,
}: {
presignedUrls: PresignedUrlResponse;
attachments: File[];
}) => {
const uploadPromises = presignedUrls.urls.map(
// eslint-disable-next-line
({ pre_signed_url }, idx) => {
(async () =>
await axios.put(
pre_signed_url,
attachments[idx]
))();
}
);
await Promise.all(uploadPromises);
return;
},
}
);
return res;
};

// const readFileAsBinaryString = (file: File): Promise<string> => {
// return new Promise((resolve, reject) => {
// const reader = new FileReader();
// reader.onload = () => {
// const result = reader.result as string;
// resolve(result);
// };
// reader.onerror = reject;
// reader.readAsBinaryString(file);
// });
// }
12 changes: 7 additions & 5 deletions src/Apis/Files/request.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface PresignedUrlRequest {
files: {
type: string
file_name: string
}[]
}
files: FileInfoType[];
}

export interface FileInfoType {
type: string;
file_name: string;
}
10 changes: 5 additions & 5 deletions src/Apis/Files/response.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface PresignedUrlResponse {
urls: {
file_path: string,
pre_signed_url: string,
}[]
}
urls: {
file_path: string;
pre_signed_url: string;
}[];
}
3 changes: 3 additions & 0 deletions src/Assets/SVG/delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 048d539

Please sign in to comment.