From f61adcc4e67a2c4e5679f820033848bbb74fa564 Mon Sep 17 00:00:00 2001 From: sonkang Date: Wed, 3 Aug 2022 21:24:38 +0900 Subject: [PATCH] =?UTF-8?q?feat(client/preset):=20preset=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=9D=84=20api=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=97=AC=20DB=EC=97=90=20=EC=A0=80=EC=9E=A5=ED=96=88=EC=8A=B5?= =?UTF-8?q?=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat #292 --- docker-compose.yml | 2 +- .../application/services/usePreset.tsx | 23 ++- .../http/axios/axios.instance.ts | 3 +- .../infrastructure/preset.repository.ts | 41 ++++- .../infrastructure/presetList.repository.ts | 18 ++- .../presentation/components/Board/Section.tsx | 19 ++- packages/client/src/index.tsx | 4 +- packages/server/src/auth/auth.controller.ts | 2 +- packages/server/src/schema.gql | 149 ++++++++++++++---- .../user_information.controller.ts | 21 ++- 10 files changed, 221 insertions(+), 61 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1e72caf..2ddf061 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,7 @@ services: - "5432:5432" environment: POSTGRES_USER: "postgres" - POSTGRES_PASSWORD: "504201" + POSTGRES_PASSWORD: "postgres" stdin_open: true tty: true networks: diff --git a/packages/client/src/dashboard/application/services/usePreset.tsx b/packages/client/src/dashboard/application/services/usePreset.tsx index 46ea58b..8756bda 100644 --- a/packages/client/src/dashboard/application/services/usePreset.tsx +++ b/packages/client/src/dashboard/application/services/usePreset.tsx @@ -15,6 +15,8 @@ import StickerDataType from '../../domain/stickerDatas/stickerData.type'; import presetListRepository from '../../infrastructure/presetList.repository'; import PresetListService from '../../domain/presetList/presetList.service'; import useMode from '../../application/services/useMode'; +import { log } from 'console'; +import axios from 'axios'; const presetService = new PresetService(presetRepository); const presetListService = new PresetListService(presetListRepository); @@ -39,6 +41,25 @@ 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) { @@ -52,7 +73,7 @@ function usePreset() { }, []); useEffect(() => { - if (preset) { + if (preset && preset.data) { boardDataStore.setBoardData(preset.data.boardData); sectionDatasStore.setSectionDatas(preset.data.sectionDatas); stickerDatasStore.setStickerDatas(preset.data.stickerDatas); diff --git a/packages/client/src/dashboard/infrastructure/http/axios/axios.instance.ts b/packages/client/src/dashboard/infrastructure/http/axios/axios.instance.ts index 9d4c686..fe29cde 100644 --- a/packages/client/src/dashboard/infrastructure/http/axios/axios.instance.ts +++ b/packages/client/src/dashboard/infrastructure/http/axios/axios.instance.ts @@ -1,7 +1,8 @@ import axios from 'axios'; export const instance = axios.create({ - baseURL: 'http://dashboard42.com:3000', + // baseURL: 'http://dashboard42.com:3000', + baseURL: 'http://localhost:3000', withCredentials: true, timeout: 5000, validateStatus: function (status) { diff --git a/packages/client/src/dashboard/infrastructure/preset.repository.ts b/packages/client/src/dashboard/infrastructure/preset.repository.ts index 9596920..83edda7 100644 --- a/packages/client/src/dashboard/infrastructure/preset.repository.ts +++ b/packages/client/src/dashboard/infrastructure/preset.repository.ts @@ -1,12 +1,18 @@ import PresetRepositoryInterface from '../domain/preset/preset.repository.interface'; import PresetType from '../domain/preset/preset.type'; import presetStore from './store/preset.store'; +import axios from 'axios'; class PresetRepository implements PresetRepositoryInterface { public async getPreset(id: string): Promise { - //여기가 http로 Preset Type 받아오는거 - const preset = localStorage.getItem(`preset-${id}`); - return preset ? (JSON.parse(preset) as PresetType) : null; + const preset = await axios + .get(`http://localhost:3000/user-information/getOnePreSet/${id}`, { + withCredentials: true, + }) + .then((res) => { + return res.data[0]; + }); + return preset; } public async setPreset(preset: PresetType): Promise { @@ -14,9 +20,34 @@ class PresetRepository implements PresetRepositoryInterface { } public async addPreset(preset: PresetType): Promise { - //graphQl로 프리셋 데이터 저장 const { id } = preset; - localStorage.setItem(`preset-${id}`, JSON.stringify(preset)); + let isExist = false; + await axios + .get('http://localhost:3000/user-information/getAllPreSet', { + withCredentials: true, + }) + .then((res) => { + for (let i = 0; i < res.data.length; i++) { + if (res.data[i].id === id) isExist = true; + } + }); + if (isExist) { + await axios.put( + 'http://localhost:3000/user-information/updateOnePreSet/${id}', + preset, + { + withCredentials: true, + }, + ); + } else { + await axios.post( + 'http://localhost:3000/user-information/addPreSet', + preset, + { + withCredentials: true, + }, + ); + } } } diff --git a/packages/client/src/dashboard/infrastructure/presetList.repository.ts b/packages/client/src/dashboard/infrastructure/presetList.repository.ts index 9c3ec75..19eea5b 100644 --- a/packages/client/src/dashboard/infrastructure/presetList.repository.ts +++ b/packages/client/src/dashboard/infrastructure/presetList.repository.ts @@ -2,19 +2,21 @@ import PresetType, { PresetInfoType } from './../domain/preset/preset.type'; import PresetListRepositoryInterface from '../domain/presetList/presetList.repository.interface'; import PresetListType from '../domain/presetList/presetList.type'; import presetlistStore from './store/presetList.store'; +import axios from 'axios'; class PresetListRepository implements PresetListRepositoryInterface { public async getPresetList(): Promise { - // 여기가 http로 Preset List 받아오는거 const presetInfos = Array(); - for (let i = 0; i < localStorage.length; ++i) { - const key = localStorage.key(i); - if (key && key.includes('preset')) { - const preset = JSON.parse(localStorage.getItem(key)!) as PresetType; - presetInfos.push(preset.info); - } - } + await axios + .get('http://localhost:3000/user-information/getAllPreSet', { + withCredentials: true, + }) + .then((res) => { + for (let i = 0; i < res.data.length; i++) { + presetInfos.push(res.data[i].info); + } + }); return { presetInfos }; } diff --git a/packages/client/src/dashboard/presentation/components/Board/Section.tsx b/packages/client/src/dashboard/presentation/components/Board/Section.tsx index 8576e70..60bc218 100644 --- a/packages/client/src/dashboard/presentation/components/Board/Section.tsx +++ b/packages/client/src/dashboard/presentation/components/Board/Section.tsx @@ -35,14 +35,17 @@ export default function Section(props: SectionProps) { function drawStickers() { return stickerLayouts.map((sticker: Layout, idx) => (
- { - removeSticker(stickerId); - handleStickerRemove(id, stickerId); - }} - /> + {/* TODO(sonkang) : 나중에 더 좋은 방법을 찾아보기 */} + {stickerDatas[idx] && ( + { + removeSticker(stickerId); + handleStickerRemove(id, stickerId); + }} + /> + )}
)); } diff --git a/packages/client/src/index.tsx b/packages/client/src/index.tsx index 588d370..c66171f 100644 --- a/packages/client/src/index.tsx +++ b/packages/client/src/index.tsx @@ -9,7 +9,9 @@ import store from './dashboard/infrastructure/store/redux/store'; import { ApolloClient, ApolloProvider, InMemoryCache } from '@apollo/client'; const client = new ApolloClient({ - uri: 'http://ec2-43-200-57-82.ap-northeast-2.compute.amazonaws.com:3000/graphql', + // uri: 'http://ec2-43-200-57-82.ap-northeast-2.compute.amazonaws.com:3000/graphql', + // uri: 'http://dashboard42.com:3000/graphql', + uri: 'http://localhost:3000/graphql', cache: new InMemoryCache(), }); diff --git a/packages/server/src/auth/auth.controller.ts b/packages/server/src/auth/auth.controller.ts index a23036e..8f0f33b 100644 --- a/packages/server/src/auth/auth.controller.ts +++ b/packages/server/src/auth/auth.controller.ts @@ -44,7 +44,7 @@ export class AuthController { const access_token = await this.authService.authentication(code); res.cookie('access_token', `${access_token}`, { httpOnly: true, - // domain: 'dashboard42.com', + domain: 'localhost', }); //res.cookie()는 하나만 적용됨. 여러개 호출하면 제일 마지막에 호출된것만 적용됨(??) // res.setHeader('WWW-authenticate', `Bearer: realm="DashBoard"`); res.redirect('http://localhost:3000/auth/test'); //redirection해도 됨. 나중에 front Home으로 redirection되게 할 예정. diff --git a/packages/server/src/schema.gql b/packages/server/src/schema.gql index 6358d67..ad6e223 100644 --- a/packages/server/src/schema.gql +++ b/packages/server/src/schema.gql @@ -46,37 +46,130 @@ 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!]! @@ -93,7 +186,7 @@ type User { expired_date: DateTime! grade: String! intra_id: String! - intra_no: Int! + intra_no: Float! name: String! start_process_date: DateTime! uniqueness: String! @@ -104,9 +197,9 @@ type UserAccessCardInformation { created_date: DateTime! deleted_date: DateTime! expired_date: DateTime! - lapiscine_logical_number: Int! - lapiscine_physical_number: Int! - logical_number_for_main_course: Int! + lapiscine_logical_number: String! + lapiscine_physical_number: String! + logical_number_for_main_course: String! name_of_entry_card_for_main_course: String! pk: Int! profile_picture_path: String! @@ -297,4 +390,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 77bdec6..f8d236e 100644 --- a/packages/server/src/user_information/user_information.controller.ts +++ b/packages/server/src/user_information/user_information.controller.ts @@ -128,7 +128,7 @@ export class UserInformationController { for (const index in bocal['preSetArray']) { ret[index] = {}; const onePreSet = bocal['preSetArray'][index]; - ret[index]['id'] = JSON.parse(onePreSet['id']); + ret[index]['id'] = onePreSet['id']; ret[index]['data'] = JSON.parse(onePreSet['preSetData']); ret[index]['info'] = JSON.parse(onePreSet['info']); } @@ -153,7 +153,7 @@ export class UserInformationController { for (const index in bocal['preSetArray']) { ret[index] = {}; const onePreSet = bocal['preSetArray'][index]; - ret[index]['id'] = JSON.parse(onePreSet['id']); + ret[index]['id'] = onePreSet['id']; ret[index]['data'] = JSON.parse(onePreSet['preSetData']); ret[index]['info'] = JSON.parse(onePreSet['info']); } @@ -178,23 +178,30 @@ export class UserInformationController { } @Put('/updateOnePreSet/:uuid') - @ApiParam({ + // @ApiParam({ + // required: true, + // name: 'uuid', + // }) + @ApiBody({ required: true, - name: 'uuid', }) @UseGuards(AuthGuard('jwt')) - async updateOnePreSet(@Param('uuid') uuid, @Body() body) { + async updateOnePreSet(@Body() body) { + const uuid = body['id']; const preSetRepository = await this.dataSource.getRepository(PreSet); + if (!(await preSetRepository.findOne({ where: { id: Equal(uuid) } }))) { + return 'entity not found'; + } const preSet = await preSetRepository.update( { - id: Equal(uuid), + id: uuid, }, { preSetData: JSON.stringify(body['data']), info: JSON.stringify(body['info']), }, ); - if (!preSet) return 'entity not found'; + console.log(preSet); return 'update success'; } }