Skip to content

Commit

Permalink
배포 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
DHyeon98 committed Jun 24, 2024
2 parents adc8e06 + de093d9 commit 3406d93
Show file tree
Hide file tree
Showing 132 changed files with 3,461 additions and 817 deletions.
60 changes: 30 additions & 30 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
extends: ['eslint:recommended', 'plugin:prettier/recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
parser: '@typescript-eslint/parser', // ESLint 파서를 지정합니다.
parserOptions: {
ecmaFeatures: {
jsx: true, // JSX를 파싱할 수 있습니다.
env: {
browser: true,
es6: true,
node: true,
},
ecmaVersion: 12, // Modern ECMAScript를 파싱할 수 있습니다.
sourceType: 'module', // import, export를 사용할 수 있습니다.
},
plugins: ['@typescript-eslint', 'prettier'],

rules: {
// ESLint 규칙을 지정합니다. extends에서 지정된 규칙을 덮어 쓸수도 있습니다.
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
extends: ['eslint:recommended', 'plugin:prettier/recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
parser: '@typescript-eslint/parser', // ESLint 파서를 지정합니다.
parserOptions: {
ecmaFeatures: {
jsx: true, // JSX를 파싱할 수 있습니다.
},
],
},
settings: {
react: {
version: 'detect', // 현재 사용하고 있는 react 버전을 eslint-plugin-react가 자동으로 감지합니다.
ecmaVersion: 12, // Modern ECMAScript를 파싱할 수 있습니다.
sourceType: 'module', // import, export를 사용할 수 있습니다.
},
},
};
plugins: ['@typescript-eslint', 'prettier'],

rules: {
// ESLint 규칙을 지정합니다. extends에서 지정된 규칙을 덮어 쓸수도 있습니다.
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
},
settings: {
react: {
version: 'detect', // 현재 사용하고 있는 react 버전을 eslint-plugin-react가 자동으로 감지합니다.
},
},
};
15 changes: 15 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": ["$tsc"],
"group": {
"kind": "build",
"isDefault": true
},
"label": "tsc: 빌드 - tsconfig.json"
}
]
}
5 changes: 2 additions & 3 deletions apis/calendar/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ export async function deleteTodoById(calendarId: string) {
await axiosInstance.delete(`/calendar/${calendarId}`);
}

export async function fetchPets(): Promise<Pet[]> {
const { data } = await axiosInstance.get(`/my/pets`);
return data.data;
export async function fetchPets() {
return (await axiosInstance.get(`/my/pets`)).data.data as Pet[];
}

export async function putTodoFinished(calendarId: string) {
Expand Down
97 changes: 83 additions & 14 deletions apis/diaries/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { UpdateCommentData } from '@/types/story/details';
import { axiosInstance, axiosFileInstance } from '..';
import { DiaryData } from '@/types/diary/';

interface ImageUpload {
images: File[];
}

export interface FormFields {
pets: number[];
content: string;
weather: string;
images: number[];
isShare: boolean;
date: string;
}

interface DiaryPostType {
pets: number[];
images: number[];
Expand All @@ -14,8 +24,13 @@ interface DiaryPostType {
date: string;
}

interface UpdateDiaryData {
export interface UpdateDiaryData {
content: string;
weather: string;
isShare: boolean;
date: string;
pets: number[];
images: (number | File)[];
}

export interface Child {
Expand All @@ -38,18 +53,21 @@ export interface Comment {
children: Child[];
}

interface Diary {
export interface Diary {
authorImage: string;
author: string;
petImages: string[];
contentImages: never[];
contentImages: string[];
content: string;
date: string;
weather: string;
favoriteState: boolean;
favoriteCount: number;
comments: Comment[];
isMyDiary: boolean;
petIds: number[];
contentImageIds: number[];
isShare: boolean;
}

export async function postDiariesImage(ImageData: ImageUpload) {
Expand Down Expand Up @@ -90,8 +108,7 @@ export async function fetchDiaries(date: string): Promise<DiaryData[]> {

export async function fetchDiaryById(diaryId: string): Promise<Diary> {
try {
const response = await axiosInstance.get(`/diaries/${diaryId}`);
return response.data.data;
return (await axiosInstance.get<{ data: Diary }>(`/diaries/${diaryId}`)).data.data;
} catch (error) {
console.error(error);
throw error;
Expand All @@ -109,13 +126,51 @@ export const deleteDiary = async (diaryId: number) => {
};

export const updateDiary = async (diaryId: number, updateData: UpdateDiaryData) => {
try {
const response = await axiosInstance.put(`/diaries/${diaryId}`, updateData);
return response.data;
} catch (error) {
console.error('Failed to update diary', error);
throw error;
}
const transformedData = { ...updateData, pets: [Number(updateData.pets[0])] };
console.log(diaryId, transformedData);
return (await axiosInstance.put(`/diaries/${diaryId}`, transformedData)).data;

// const data = {
// pets:
// pedtsId: []
// images: []
// content:
// isShare:
// weather:
// date: updateData.data
// };

// const response = await axiosFileInstance.put(`/diaries/${diaryId}`, formData);

// const formData = new FormData();
// formData.append('content', updateData.content);
// formData.append('weather', updateData.weather);
// formData.append('isShare', updateData.isShare);
// formData.append('date', updateData.date);

// updateData.pets
// .filter((pet) => pet !== undefined)
// .forEach((pet, index) => {
// formData.append(`pets[${index}]`, pet.toString());
// });

// updateData.images
// .filter((image) => image !== undefined)
// .forEach((image, index) => {
// if (image instanceof File) {
// formData.append('images', image);
// } else {
// formData.append(`images[${index}]`, image.toString());
// }
// });

// try {

// return response.data;
// } catch (error) {
// console.error('Failed to update diary: ', error);
// throw error;
// }
};

export const postComment = async (diaryId: string, content: string, parentCommentId: number | null = null) => {
Expand All @@ -127,9 +182,9 @@ export const postComment = async (diaryId: string, content: string, parentCommen
}
};

export const putComment = async (commentId: number, content: string) => {
export const putComment = async ({ commentId, data }: UpdateCommentData) => {
try {
const response = await axiosInstance.put(`/comments/${commentId}`, { content });
const response = await axiosInstance.put(`/comments/${commentId}`, data);
console.log(response.data);
} catch (error) {
console.error('Failed to post comment', error);
Expand All @@ -153,3 +208,17 @@ export const deleteChildComment = async (commentId: number) => {
console.error('Failed to delete comment', error);
}
};

class DiaryAPI {
async fetchDiary(diaryId: number) {
return (await axiosInstance.get(`/diaries/${diaryId}`)).data.data as Diary;
}

async updateDiary({ diaryId, data }: { diaryId: number; data: FormFields }) {
return await axiosInstance.put(`/diaries/${diaryId}`, data);
}
}

const diaryApiInstance = new DiaryAPI();

export default diaryApiInstance;
8 changes: 7 additions & 1 deletion apis/image-api/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { axiosFileInstance } from '..';

interface ImageType {
files: File;
files?: File;
images?: File;
}

export const imageUpload = async (data: ImageType) => {
return await axiosFileInstance.post('/images', data);
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const diaryImageUpload = async (data: ImageType) => {
return await axiosFileInstance.post('/images/diaries', data);
};
2 changes: 1 addition & 1 deletion apis/my/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class MyPageAPI {
}

async updateProfile(data: { imageId: number | null; nickname: string }) {
console.log(data);
// console.log(data);
return await axiosInstance.put('my/profiles', data);
}
}
Expand Down
27 changes: 18 additions & 9 deletions apis/story/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { axiosInstance } from '../index';
import { StoryData } from '../../types/story/index';
import { StoryDetailsData } from '@/types/story/details';
import { CreateCommentData, StoryDetailsData, UpdateCommentData } from '@/types/story/details';

class StoryAPI {
export class StoryAPI {
async fetchStory(page = 0, size = 10) {
return (await axiosInstance.get(`stories?page=${page}&size=${size}`)).data.data as StoryData;
}
Expand All @@ -19,16 +19,25 @@ class StoryAPI {
return (await axiosInstance.delete(`hearts/${diaryId}`)).data;
}

async createCommentStory({ diaryId, data }: CommentData) {
async createCommentStory({ diaryId, data }: CreateCommentData) {
return (await axiosInstance.post(`comments/${diaryId}`, data)).data;
}
}

interface CommentData {
diaryId: number;
data: {
content: string;
};
async deleteCommentStory(commentId: number) {
return await axiosInstance.delete(`comments/parent/${commentId}`);
}

async updateCommentStory({ commentId, data }: UpdateCommentData) {
return await axiosInstance.put(`comments/${commentId}`, data);
}

async deleteReplyStroy(commentId: number) {
return await axiosInstance.delete(`comments/child/${commentId}`);
}

async deleteStory(diaryId: number) {
return await axiosInstance.delete(`stories/${diaryId}`);
}
}

const storyApiInstance = new StoryAPI();
Expand Down
Loading

0 comments on commit 3406d93

Please sign in to comment.