-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8057bea
commit 1e3597f
Showing
11 changed files
with
273 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,50 @@ | ||
export interface GetCommentRequest { | ||
id: string; | ||
//post | ||
export interface PostCommentRequest { | ||
sectionId: number; | ||
commentContent: string; | ||
} | ||
|
||
export interface GetCommentResponse { | ||
export interface PostCommentResponse { | ||
code: number; | ||
message: string; | ||
data: { | ||
id: number; | ||
content: string; | ||
}; | ||
data: PostCommentData; | ||
} | ||
|
||
//put | ||
export interface PutCommentRequest { | ||
export interface PostCommentData { | ||
id: number; | ||
userId: number; | ||
sectionId: number; | ||
commentContent: string; | ||
} | ||
|
||
//delete | ||
export interface DeleteCommentRequest { | ||
id: number; | ||
//put | ||
export interface PutCommentRequest { | ||
commentId: number; | ||
commentContent: string; | ||
} | ||
|
||
export interface DeleteCommentResponse { | ||
export interface PutCommentResponse { | ||
code: number; | ||
message: string; | ||
data: object; | ||
data: PutCommentData; | ||
} | ||
|
||
//GetAllComment | ||
export interface AllGetCommentResponse { | ||
code: number; | ||
message: string; | ||
data: CommentData[]; | ||
export interface PutCommentData { | ||
commentId: number; | ||
content: string; | ||
} | ||
|
||
export interface CommentData { | ||
id: number; | ||
comment: string; | ||
//delete | ||
export interface DeleteCommentRequest { | ||
commentId: number; | ||
} | ||
|
||
//Post | ||
export interface DeleteCommentResponse { | ||
code: number; | ||
} | ||
|
||
export interface CommentClient { | ||
getComment(request: GetCommentRequest): Promise<GetCommentResponse>; | ||
post(request: PostCommentRequest): Promise<PostCommentResponse>; | ||
delete(request: DeleteCommentRequest): Promise<DeleteCommentResponse>; | ||
getAllComment(): Promise<AllGetCommentResponse>; | ||
put(request: PutCommentRequest): Promise<PutCommentResponse>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
import { CommentClient } from '../@types/Comment'; | ||
import { mswInstance } from '../client'; | ||
import { CommentClient, DeleteCommentRequest, PostCommentRequest, PostCommentResponse } from '../@types/Comment'; | ||
import axiosInstance from '../axiosConfig'; | ||
|
||
const ROUTE = '/comments'; | ||
|
||
export const CommentService: CommentClient = { | ||
getComment: async id => { | ||
return await mswInstance.get(`/api/${ROUTE}/${id}`); | ||
post: async (request: PostCommentRequest): Promise<PostCommentResponse> => { | ||
try { | ||
const response = await axiosInstance.post(`${ROUTE}`, request); | ||
return response.data; | ||
} catch (error) { | ||
throw new Error(error as string); | ||
} | ||
}, | ||
delete: async id => { | ||
return await mswInstance.delete(`/api/${ROUTE}/${id}`); | ||
delete: async ({ commentId }: DeleteCommentRequest) => { | ||
try { | ||
const response = await axiosInstance.delete(`${ROUTE}/${commentId}`); | ||
return response.data; | ||
} catch (error) { | ||
throw new Error(error as string); | ||
} | ||
}, | ||
getAllComment: async () => { | ||
return await mswInstance.get(`api/${ROUTE}`); | ||
put: async ({ commentId, ...request }) => { | ||
try { | ||
const response = await axiosInstance.put(`${ROUTE}/${commentId}`, request); | ||
return response.data; | ||
} catch (error) { | ||
throw new Error(error as string); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { ChangeEvent, FC, useState } from 'react'; | ||
import { Button } from '@chakra-ui/react'; | ||
import { CommentData } from '@/api/@types/Section'; | ||
import { CommentService } from '@/api/services/Comment'; | ||
import * as S from '@/styles/writeRetroStyles/Layout.style'; | ||
|
||
interface Props { | ||
comment: CommentData; | ||
} | ||
|
||
const ReviseCommentModal: FC<Props> = ({ comment }) => { | ||
// Input 높이 자동 조절 | ||
const [value, setValue] = useState(''); | ||
const handleChange = (e: ChangeEvent<HTMLTextAreaElement>) => { | ||
setValue(e.target.value); | ||
e.target.style.height = 'auto'; | ||
e.target.style.height = `${e.target.scrollHeight}px`; | ||
}; | ||
|
||
const ChangeContent = async () => { | ||
try { | ||
const data = await CommentService.put({ commentId: comment.commentId, commentContent: value }); | ||
console.log(data); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}; | ||
return ( | ||
<> | ||
<S.ReviseModalStyle> | ||
<S.ReviseModalLine> | ||
<S.ReviseModalTitle>수정</S.ReviseModalTitle> | ||
</S.ReviseModalLine> | ||
<S.ReviseModalInput | ||
value={value} | ||
onChange={handleChange} | ||
placeholder={comment.content} | ||
rows={1} | ||
></S.ReviseModalInput> | ||
|
||
<S.ReviseModalButtonBox> | ||
{/* <S.ReviseModalButton>삭제</S.ReviseModalButton> */} | ||
|
||
<Button colorScheme="brand" marginRight={10} onClick={ChangeContent}> | ||
확인 | ||
</Button> | ||
</S.ReviseModalButtonBox> | ||
</S.ReviseModalStyle> | ||
</> | ||
); | ||
}; | ||
|
||
export default ReviseCommentModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.