Skip to content

Commit

Permalink
feat(client/preset): preset 저장을 api를 사용하여 DB에 저장했습니다
Browse files Browse the repository at this point in the history
feat #292
  • Loading branch information
sonkang authored and sonkang committed Aug 5, 2022
1 parent 963f74b commit f61adcc
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 61 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ services:
- "5432:5432"
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "504201"
POSTGRES_PASSWORD: "postgres"
stdin_open: true
tty: true
networks:
Expand Down
23 changes: 22 additions & 1 deletion packages/client/src/dashboard/application/services/usePreset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
41 changes: 36 additions & 5 deletions packages/client/src/dashboard/infrastructure/preset.repository.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
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<PresetType | null> {
//여기가 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<void> {
presetStore.setPreset(preset);
}

public async addPreset(preset: PresetType): Promise<void> {
//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,
},
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PresetListType> {
// 여기가 http로 Preset List 받아오는거
const presetInfos = Array<PresetInfoType>();

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 };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ export default function Section(props: SectionProps) {
function drawStickers() {
return stickerLayouts.map((sticker: Layout, idx) => (
<div key={sticker.i}>
<Sticker
id={sticker.i}
data={stickerDatas[idx].data}
handleStickerRemove={(stickerId) => {
removeSticker(stickerId);
handleStickerRemove(id, stickerId);
}}
/>
{/* TODO(sonkang) : 나중에 더 좋은 방법을 찾아보기 */}
{stickerDatas[idx] && (
<Sticker
id={sticker.i}
data={stickerDatas[idx].data}
handleStickerRemove={(stickerId) => {
removeSticker(stickerId);
handleStickerRemove(id, stickerId);
}}
/>
)}
</div>
));
}
Expand Down
4 changes: 3 additions & 1 deletion packages/client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});

Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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되게 할 예정.
Expand Down
149 changes: 121 additions & 28 deletions packages/server/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -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!]!
Expand All @@ -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!
Expand All @@ -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!
Expand Down Expand Up @@ -297,4 +390,4 @@ type UserPersonalInformation {
region: String!
social_security_key: String!
validate_date: DateTime!
}
}
Loading

0 comments on commit f61adcc

Please sign in to comment.