Skip to content

Commit 28df612

Browse files
authored
story에 userId부여 (#197)
* feat(schema): getStoryNames response에 storyId추가 * feat(server): story schema에 userId추가 * feat(core/server): story 생성 시 userId삽입 * feat(client): 스토리의 주인에게만 삭제/수정 아이콘이 보이도록 수정 * feat(client): StoryNameList의 렌더링 조건 수정 * docs: api 문서 업데이트 * chore: test action 환경변수 직접 추가
1 parent 56485d0 commit 28df612

File tree

9 files changed

+51
-28
lines changed

9 files changed

+51
-28
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
- name: set env var
1717
run: |
18-
echo "POCKET_TOKEN=${{ secrets.POCKET_TOKEN }}" >> $GITHUB_ENV
18+
echo "POCKET_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyTmFtZSI6InFrcmRtc3RscjMiLCJzZXJ2ZXJVcmwiOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJpYXQiOjE2NjE2OTQxMjV9.mZxJhIEcjtr-weC3Dmqjq5IWAt49DTONBLf2s-wr8K4" >> $GITHUB_ENV
1919
echo $POCKET_TOKEN
2020
2121
- name: test all

client/src/detail/components/StoryNameList/index.tsx

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as Sandpack from '@codesandbox/sandpack-react';
22
import { Icon, IconButton, Modal } from '@shared/components';
3+
import { localStorage } from '@shared/utils/localStorage';
34
import Transition from '@shared/utils/Transition';
45
import React, { useState } from 'react';
56

@@ -11,7 +12,7 @@ import * as style from './style.css';
1112
interface StoryNameListProps {
1213
codeId: string;
1314
codeName: string;
14-
pocketCodes: { storyName: string; storyId: string }[];
15+
pocketCodes: { storyName: string; storyId: string; userId: string }[];
1516
selectedStoryId?: string;
1617
selectStory: (storyName: string) => void;
1718
}
@@ -38,6 +39,14 @@ const StoryNameList: React.FC<StoryNameListProps> = (props) => {
3839
setStoryWantedDelete({ modal: 'update', storyId });
3940
};
4041

42+
const isValidUserId = (userId: string) => localStorage.getUserId() === userId;
43+
44+
const getModalMessage = () => {
45+
if (storyWantedDelete.modal === 'delete') return '정말로 스토리를 삭제하시겠어요?';
46+
if (storyWantedDelete.modal === 'update') return '정말로 스토리를 수정하시겠어요?';
47+
return '';
48+
};
49+
4150
const closeModal = () => setStoryWantedDelete({ modal: 'none' });
4251
const onCancel = () => closeModal();
4352
const onConfirm = () => {
@@ -55,33 +64,35 @@ const StoryNameList: React.FC<StoryNameListProps> = (props) => {
5564
return (
5665
<>
5766
<Modal isOpen={storyWantedDelete.modal !== 'none'} closeModal={closeModal}>
58-
<p className={style.modalParagraph}>정말로 스토리를 삭제하시겠어요?</p>
67+
<p className={style.modalParagraph}>{getModalMessage()}</p>
5968
<div className={style.buttonWrapper}>
6069
<Modal.CancelButton onCancel={onCancel} />
6170
<Modal.ConfirmButton onConfirm={onConfirm} />
6271
</div>
6372
</Modal>
6473
<ul className={style.list}>
65-
{props.pocketCodes.map(({ storyId, storyName }) => (
74+
{props.pocketCodes.map(({ storyId, storyName, userId }) => (
6675
<li key={storyId} className={style.item} onClick={() => props.selectStory(storyId)}>
67-
<Transition isOn={props.selectedStoryId === storyId} timeout={100}>
68-
{() => (
69-
<div
70-
className={style.controlButtonsWrapper({
71-
selected: props.selectedStoryId === storyId,
72-
})}
73-
>
74-
<IconButton
75-
icon={<Icon icon="edit" />}
76-
onClick={(event) => onClickUpdateBtn(event, storyId)}
77-
/>
78-
<IconButton
79-
icon={<Icon icon="delete" />}
80-
onClick={(event) => onClickDeleteBtn(event, storyId)}
81-
/>
82-
</div>
83-
)}
84-
</Transition>
76+
{isValidUserId(userId) && (
77+
<Transition isOn={props.selectedStoryId === storyId} timeout={100}>
78+
{() => (
79+
<div
80+
className={style.controlButtonsWrapper({
81+
selected: props.selectedStoryId === storyId,
82+
})}
83+
>
84+
<IconButton
85+
icon={<Icon icon="edit" />}
86+
onClick={(event) => onClickUpdateBtn(event, storyId)}
87+
/>
88+
<IconButton
89+
icon={<Icon icon="delete" />}
90+
onClick={(event) => onClickDeleteBtn(event, storyId)}
91+
/>
92+
</div>
93+
)}
94+
</Transition>
95+
)}
8596
<button
8697
className={style.storyButton({
8798
selected: props.selectedStoryId === storyId,

core/server/src/createStory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ export default async <T, Response>(request: T, modules: CreateStoryType<Response
2121
if (!createStoryRequestValidate(request)) throw modules.validateError;
2222
const { pocketToken, codeId, storyName, codes } = request.body;
2323

24-
const { userName: storyAuthor } = await modules.getUserInfo({ pocketToken });
24+
const { userName: storyAuthor, userId } = await modules.getUserInfo({ pocketToken });
2525

2626
const isStoryExist = await modules.isStoryExist({ codeId, storyAuthor, storyName });
2727
if (isStoryExist) throw modules.existStoryErrorFunc;
28-
const storyId = await modules.createStory({ codeId, storyAuthor, storyName, codes });
28+
const storyId = await modules.createStory({ codeId, storyAuthor, storyName, userId, codes });
2929

3030
return modules.successResponseFunc({ message: '', storyId });
3131
};

core/server/src/getStoryNames.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface GetStoryNamesType<Response> {
66
validateError?: Response;
77
/* 성공했을 경우 */
88
successResponseFunc: (body: GetStoryNamesResponse) => Response;
9+
910
/* 스토리 이름들을 가져오는 함수 */
1011
getStoryNames: (params: CodeId) => Promise<StoryNamesWithCodeId[]>;
1112
}

core/server/src/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ export interface StoryIdWithCode {
5252
export interface StoryNamesWithCodeId {
5353
storyName: string;
5454
storyId: string;
55+
userId: string;
5556
}
5657

5758
export interface StoryInfoWithCode {
5859
codeId: string;
60+
userId: string;
5961
storyName: string;
6062
storyAuthor: string;
6163
codes: { [x: string]: string };

schema/json/getStoryNamesResponse.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
},
1616
"storyId": {
1717
"type": "string"
18+
},
19+
"userId": {
20+
"type": "string"
1821
}
1922
},
2023
"additionalProperties": false,
2124
"required": [
2225
"storyName",
23-
"storyId"
26+
"storyId",
27+
"userId"
2428
]
2529
}
2630
}

server/API.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@
447447
"message": "string",
448448
"storyNames": {
449449
"storyName": "string",
450-
"storyId": "string"
450+
"storyId": "string",
451+
"userId": "string",
451452
}[]
452453
}
453454
```

server/src/dbModule/story.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export const getStoryFullNames =
6868
const { codeAuthor, codeName } = await getCodeInfoById(server)({ codeId });
6969
const stories = await getStories(server)({ codeAuthor, codeName });
7070

71-
const storyNames = stories.map(({ storyAuthor, storyName, _id }) => ({
71+
const storyNames = stories.map(({ storyAuthor, storyName, userId, _id }) => ({
72+
userId,
7273
storyName: `${storyAuthor}-${storyName}`,
7374
storyId: String(_id),
7475
}));
@@ -89,12 +90,13 @@ export const getStoryCode =
8990

9091
export const createStory =
9192
(server: FastifyInstance) =>
92-
async ({ codeId, storyAuthor, storyName, codes }: Types.StoryInfoWithCode) => {
93+
async ({ codeId, storyAuthor, storyName, userId, codes }: Types.StoryInfoWithCode) => {
9394
const { codeAuthor, codeName } = await getCodeInfoById(server)({ codeId });
9495
const [createError, story] = await to(
9596
(async () =>
9697
await server.store.Story.create({
9798
codeId,
99+
userId,
98100
codeName,
99101
codeAuthor,
100102
storyName,

server/src/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface Code {
2323
export interface Story {
2424
codes: string;
2525
codeId: string;
26+
userId: string;
2627
codeName: string;
2728
codeAuthor: string;
2829
storyName: string;
@@ -68,6 +69,7 @@ export const StorySchema = new Schema<Story>({
6869
codeId: String,
6970
codeName: String,
7071
codeAuthor: String,
72+
userId: String,
7173
storyName: String,
7274
storyAuthor: String,
7375
createdAt: Date,

0 commit comments

Comments
 (0)