From 2448608cb6a06d6a46adfa6c2a6ef6b9267eed5b Mon Sep 17 00:00:00 2001 From: sonkang Date: Thu, 4 Aug 2022 19:52:41 +0900 Subject: [PATCH] feat(client/preset): add preset delete button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 백엔드 api를 사용하여 preset을 삭제할 수 있는 버튼을 만들었습니다 feat #368 --- .../application/services/useBoard.tsx | 9 ++ .../application/services/usePreset.tsx | 32 ++-- .../preset/preset.repository.interface.ts | 2 +- .../dashboard/domain/preset/preset.service.ts | 6 +- .../infrastructure/preset.repository.ts | 12 +- .../infrastructure/presetList.repository.ts | 1 + .../components/SideBar/PresetListItem.tsx | 16 +- packages/server/src/schema.gql | 142 +++--------------- .../user_information.controller.ts | 4 +- 9 files changed, 77 insertions(+), 147 deletions(-) diff --git a/packages/client/src/dashboard/application/services/useBoard.tsx b/packages/client/src/dashboard/application/services/useBoard.tsx index 9ea330c..9d37e68 100644 --- a/packages/client/src/dashboard/application/services/useBoard.tsx +++ b/packages/client/src/dashboard/application/services/useBoard.tsx @@ -9,6 +9,8 @@ import PresetService from '../../domain/preset/preset.service'; import sectionDatasStore from '../../infrastructure/store/sectionDatas.store'; import stickerDatasStore from '../../infrastructure/store/stickerDatas.store'; import presetStore from '../../infrastructure/store/preset.store'; +import PresetListService from '../../domain/presetList/presetList.service'; +import presetListRepository from '../../infrastructure/presetList.repository'; const boardDataService = new BoardDataService(boardDataRepository); const presetService = new PresetService(presetRepository); @@ -19,6 +21,7 @@ function useBoard() { boardDataStore.subscribeToBoardData((newBoardData: BoardDataType) => { setBoardData(newBoardData); }); + const handleSavePreset = () => { const preset = presetStore.getPreset(); if (!preset) return; @@ -36,6 +39,11 @@ function useBoard() { info: preset.info, }); }; + + const handleDeletePreset = async (id: string) => { + await presetService.deletePreset(id); + }; + const handleSectionAdd = (sectionId: string | undefined) => { if (sectionId === undefined) return; const newLayout = [ @@ -74,6 +82,7 @@ function useBoard() { handleSectionLayoutChange, handleSectionRemove, handleSavePreset, + handleDeletePreset, }; } diff --git a/packages/client/src/dashboard/application/services/usePreset.tsx b/packages/client/src/dashboard/application/services/usePreset.tsx index 8756bda..f4bf23b 100644 --- a/packages/client/src/dashboard/application/services/usePreset.tsx +++ b/packages/client/src/dashboard/application/services/usePreset.tsx @@ -41,25 +41,6 @@ function usePreset() { }); useEffect(() => { - // 나중에 지울 코드! - // await axios - // .get('http://localhost:3000/user-information/getAllPreSet', { - // withCredentials: true, - // }) - // .then((res) => { - // const deletePreset = async (id: string) => { - // await axios.delete( - // 'http://localhost:3000/user-information/deleteOnePreSet/${id}', - // { - // withCredentials: true, - // }, - // ); - // }; - // for (let i = 0; i < res.data.length; i++) { - // deletePreset(res.data[i].id); - // console.log('deletePreset : ', res.data[i].id); - // } - // }); const fetchPresetList = async () => { const presetList = await presetListService.getPresetList(); if (presetList.presetInfos.length !== 0) { @@ -116,6 +97,10 @@ function usePreset() { setControlMode('edit'); }; + // const deletePreset = async (id: string) => { + // await presetService.deletePreset(id); + // }; + const changePresetLabel = async (id: string, label: string) => { const presetData = await presetService.getPreset(id); if (presetData && presetList) { @@ -137,7 +122,14 @@ function usePreset() { }); } }; - return { preset, presetList, createPreset, changePreset, changePresetLabel }; + return { + preset, + presetList, + createPreset, + changePreset, + // deletePreset, + changePresetLabel, + }; } export default usePreset; diff --git a/packages/client/src/dashboard/domain/preset/preset.repository.interface.ts b/packages/client/src/dashboard/domain/preset/preset.repository.interface.ts index 14eb7a6..f6b2072 100644 --- a/packages/client/src/dashboard/domain/preset/preset.repository.interface.ts +++ b/packages/client/src/dashboard/domain/preset/preset.repository.interface.ts @@ -4,7 +4,7 @@ interface PresetRepositoryInterface { getPreset(id: string): Promise; setPreset(preset: PresetType): Promise; addPreset(preset: PresetType): Promise; - // deletePreset(id: string): Promise; + deletePreset(id: string): Promise; } export default PresetRepositoryInterface; diff --git a/packages/client/src/dashboard/domain/preset/preset.service.ts b/packages/client/src/dashboard/domain/preset/preset.service.ts index 2ec8678..077cba8 100644 --- a/packages/client/src/dashboard/domain/preset/preset.service.ts +++ b/packages/client/src/dashboard/domain/preset/preset.service.ts @@ -16,9 +16,9 @@ class PresetService { return this.presetRepository.addPreset(preset); } - // deletePreset(id: string): Promise { - // return this.presetRepository.deletePreset(id); - // } + public async deletePreset(id: string): Promise { + return this.presetRepository.deletePreset(id); + } } export default PresetService; diff --git a/packages/client/src/dashboard/infrastructure/preset.repository.ts b/packages/client/src/dashboard/infrastructure/preset.repository.ts index 83edda7..ff72629 100644 --- a/packages/client/src/dashboard/infrastructure/preset.repository.ts +++ b/packages/client/src/dashboard/infrastructure/preset.repository.ts @@ -33,7 +33,7 @@ class PresetRepository implements PresetRepositoryInterface { }); if (isExist) { await axios.put( - 'http://localhost:3000/user-information/updateOnePreSet/${id}', + `http://localhost:3000/user-information/updateOnePreSet/${id}`, preset, { withCredentials: true, @@ -49,6 +49,16 @@ class PresetRepository implements PresetRepositoryInterface { ); } } + + public async deletePreset(id: string): Promise { + await axios + .delete(`http://localhost:3000/user-information/deleteOnePreset/${id}`, { + withCredentials: true, + }) + .then((res) => { + console.log('delete result: ', res); + }); + } } export default new PresetRepository(); diff --git a/packages/client/src/dashboard/infrastructure/presetList.repository.ts b/packages/client/src/dashboard/infrastructure/presetList.repository.ts index 19eea5b..c1387d5 100644 --- a/packages/client/src/dashboard/infrastructure/presetList.repository.ts +++ b/packages/client/src/dashboard/infrastructure/presetList.repository.ts @@ -17,6 +17,7 @@ class PresetListRepository implements PresetListRepositoryInterface { presetInfos.push(res.data[i].info); } }); + console.log('presetList: ', presetInfos); return { presetInfos }; } diff --git a/packages/client/src/dashboard/presentation/components/SideBar/PresetListItem.tsx b/packages/client/src/dashboard/presentation/components/SideBar/PresetListItem.tsx index d2b2456..9219f1b 100644 --- a/packages/client/src/dashboard/presentation/components/SideBar/PresetListItem.tsx +++ b/packages/client/src/dashboard/presentation/components/SideBar/PresetListItem.tsx @@ -1,10 +1,12 @@ import { SvgIconComponent } from '@mui/icons-material'; import { ListItemButton, ListItemIcon, ListItemText } from '@mui/material'; import EditIcon from '@mui/icons-material/Edit'; +import DeleteIcon from '@mui/icons-material/Delete'; import useMode from '../../../application/services/useMode'; import { useState } from 'react'; import TextField from '@mui/material/TextField'; - +import useBoard from '../../../application/services/useBoard'; +import usePreset from '../../../application/services/usePreset'; export interface PresetListItemProps { icon: SvgIconComponent; // mui/icons-material 에 있는 아이콘 타입 label: string; @@ -20,6 +22,7 @@ function PresetListItem(props: PresetListItemProps) { const [edit, setEdit] = useState(false); const [presetLabel, setPresetLabel] = useState(label); const { getControlMode } = useMode(); + const { handleDeletePreset } = useBoard(); const IconType = icon; function myOnClickHandler(e: any) { @@ -29,6 +32,11 @@ function PresetListItem(props: PresetListItemProps) { setEdit(!edit); } + async function deletePreset(id: string) { + await handleDeletePreset(id); + console.log('deletePreset: ', id); + } + const handleChange = (event: React.ChangeEvent) => { setPresetLabel(event.target.value); }; @@ -39,7 +47,11 @@ function PresetListItem(props: PresetListItemProps) { selected={selected || false} > - + {selected && getControlMode() === 'edit' && !edit ? ( + deletePreset(id)} /> + ) : ( + + )} {selected && getControlMode() === 'edit' && !edit ? ( <> diff --git a/packages/server/src/schema.gql b/packages/server/src/schema.gql index ad6e223..15f94c2 100644 --- a/packages/server/src/schema.gql +++ b/packages/server/src/schema.gql @@ -25,7 +25,6 @@ type JoinedTable { intra_no: Int! name: String start_process_date: DateTime - start_process: DateTime uniqueness: String userAccessCardInformation: [UserAccessCardInformation!] userBlackhole: [UserBlackhole!] @@ -46,130 +45,37 @@ type JoinedTable { } type Mutation { - deleteUserInformation( - column: String! - entityName: String! - intra_no: Int! - pk: Int! - value: String! - ): Boolean! - recoverUserInformaiton( - column: String! - entityName: String! - intra_no: Int! - pk: Int! - value: String! - ): Boolean! - softDeleteRemoveWithdrawTest( - column: String! - entityName: String! - intra_no: Int! - pk: Int! - value: String! - ): [JoinedTable!]! - updateUserInformation( - column: String! - entityName: String! - intra_no: Int! - pk: Int! - value: String! - ): Boolean! + deleteUserInformation(column: String!, entityName: String!, intra_no: Int!, pk: Int!, value: String!): Boolean! + recoverUserInformaiton(column: String!, entityName: String!, intra_no: Int!, pk: Int!, value: String!): Boolean! + softDeleteRemoveWithdrawTest(column: String!, entityName: String!, intra_no: Int!, pk: Int!, value: String!): [JoinedTable!]! + updateUserInformation(column: String!, entityName: String!, intra_no: Int!, pk: Int!, value: String!): Boolean! } type Query { extractDataIntoSpreadsheet: String! getDataToModifyFromDB(sheetName: String!): String! - getDomainOfColumnFilter( - endDate: DateTime - filters: [Filter!]! - skip: Int - startDate: DateTime - take: Int - ): [JoinedTable!]! + getDomainOfColumnFilter(endDate: DateTime, filters: [Filter!]!, skip: Int, startDate: DateTime, take: Int): [JoinedTable!]! getLatestData: String! - getNumOfPeopleByFilter( - endDate: DateTime - filters: [Filter!]! - skip: Int - startDate: DateTime - take: Int - ): Int! - getPeopleByFilter( - endDate: DateTime - filters: [Filter!]! - skip: Int - startDate: DateTime - take: Int - ): [JoinedTable!]! - getPeopleByFilterForAdmin( - endDate: DateTime - filters: [Filter!]! - skip: Int - startDate: DateTime - take: Int - ): [JoinedTable!]! + getNumOfPeopleByFilter(endDate: DateTime, filters: [Filter!]!, skip: Int, startDate: DateTime, take: Int): Int! + getPeopleByFilter(endDate: DateTime, filters: [Filter!]!, skip: Int, startDate: DateTime, take: Int): [JoinedTable!]! + getPeopleByFilterForAdmin(endDate: DateTime, filters: [Filter!]!, skip: Int, startDate: DateTime, take: Int): [JoinedTable!]! getUser(column: String, duplicated: String!): [User!]! - getUserAccessCardInformation( - column: String - duplicated: String! - ): [UserAccessCardInformation!]! + getUserAccessCardInformation(column: String, duplicated: String!): [UserAccessCardInformation!]! getUserBlackhole(column: String, duplicated: String!): [UserBlackhole!]! - getUserComputationFund( - column: String - duplicated: String! - ): [UserComputationFund!]! - getUserCourseExtension( - column: String - duplicated: String! - ): [UserCourseExtension!]! - getUserEducationFundState( - column: String - duplicated: String! - ): [UserEducationFundState!]! - getUserEmploymentStatus( - column: String - duplicated: String! - ): [UserEmploymentStatus!]! - getUserHrdNetUtilize( - column: String - duplicated: String! - ): [UserHrdNetUtilize!]! - getUserHrdNetUtilizeConsent( - column: String - duplicated: String! - ): [UserHrdNetUtilizeConsent!]! - getUserInterruptionOfCourse( - column: String - duplicated: String! - ): [UserInterruptionOfCourse!]! - getUserLapiscineInformation( - column: String - duplicated: String! - ): [UserLapiscineInformation!]! - getUserLearningDataAPI( - column: String - duplicated: String! - ): [UserLearningDataAPI!]! - getUserLeaveOfAbsence( - column: String - duplicated: String! - ): [UserLeaveOfAbsence!]! - getUserLoyaltyManagement( - column: String - duplicated: String! - ): [UserLoyaltyManagement!]! - getUserOtherEmploymentStatus( - column: String - duplicated: String! - ): [UserOtherEmploymentStatus!]! - getUserOtherInformation( - column: String - duplicated: String! - ): [UserOtherInformation!]! - getUserPersonalInformation( - column: String - duplicated: String! - ): [UserPersonalInformation!]! + getUserComputationFund(column: String, duplicated: String!): [UserComputationFund!]! + getUserCourseExtension(column: String, duplicated: String!): [UserCourseExtension!]! + getUserEducationFundState(column: String, duplicated: String!): [UserEducationFundState!]! + getUserEmploymentStatus(column: String, duplicated: String!): [UserEmploymentStatus!]! + getUserHrdNetUtilize(column: String, duplicated: String!): [UserHrdNetUtilize!]! + getUserHrdNetUtilizeConsent(column: String, duplicated: String!): [UserHrdNetUtilizeConsent!]! + getUserInterruptionOfCourse(column: String, duplicated: String!): [UserInterruptionOfCourse!]! + getUserLapiscineInformation(column: String, duplicated: String!): [UserLapiscineInformation!]! + getUserLearningDataAPI(column: String, duplicated: String!): [UserLearningDataAPI!]! + getUserLeaveOfAbsence(column: String, duplicated: String!): [UserLeaveOfAbsence!]! + getUserLoyaltyManagement(column: String, duplicated: String!): [UserLoyaltyManagement!]! + getUserOtherEmploymentStatus(column: String, duplicated: String!): [UserOtherEmploymentStatus!]! + getUserOtherInformation(column: String, duplicated: String!): [UserOtherInformation!]! + getUserPersonalInformation(column: String, duplicated: String!): [UserPersonalInformation!]! saveModifiedDataFromSheet(sheetName: String!): String! sendRequestToSpreadWithGoogleAPI: String! tempFunction: [JoinedTable!]! @@ -390,4 +296,4 @@ type UserPersonalInformation { region: String! social_security_key: String! validate_date: DateTime! -} +} \ No newline at end of file diff --git a/packages/server/src/user_information/user_information.controller.ts b/packages/server/src/user_information/user_information.controller.ts index f8d236e..9c500d1 100644 --- a/packages/server/src/user_information/user_information.controller.ts +++ b/packages/server/src/user_information/user_information.controller.ts @@ -171,9 +171,9 @@ export class UserInformationController { // 당연히 bocal에서도 삭제될것. (실제 DB에서 fk를 가진 튜플을 삭제한거니까) // 이 경우는 onDelete 옵션 안써도 되는거 const preSet = await preSetRepository.delete({ - id: Equal(uuid), + id: uuid, }); - if (preSet) return 'entity not found!'; + if (!preSet) return 'entity not found!'; return 'delete success'; }