-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/64 65 66/columns cards comments api #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e98e759
:sparkles: feat : /columns 타입 정의
ToKyun02 7008a39
:sparkles: feat : /columns API 함수 구현
ToKyun02 2b3f7d5
:sparkles: feat : /cards 타입 정의
ToKyun02 3ca9927
:sparkles: feat : /cards API 구현 및 타입 수정
ToKyun02 5741ee9
:recylce: refactor : putCard 파라미터 수정
ToKyun02 fdef679
:recycle: refactor : card 상세 조회 params 수정
ToKyun02 bae1a4e
:sparkles: feat : /comments 타입 정의
ToKyun02 b7691bf
:sparkles: /comments API 구현
ToKyun02 f6fe3b1
:bug: fix : card 삭제 API return 타입 수정
ToKyun02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,36 @@ | ||
| import axiosClientHelper from '@/utils/network/axiosClientHelper'; | ||
| import { Card, CardForm, cardSchema, CardsResponse, cardsResponseSchema, GetCardsParams } from './types'; | ||
|
|
||
| const RESPONSE_INVALID_MESSAGE = '서버에서 받은 데이터가 예상과 다릅니다'; | ||
|
|
||
| export const postCard = async (cardForm: CardForm) => { | ||
| const response = await axiosClientHelper.post<Card>('/cards', cardForm); | ||
| const result = cardSchema.safeParse(response.data); | ||
| if (!result.success) throw new Error(RESPONSE_INVALID_MESSAGE); | ||
| return result.data; | ||
| }; | ||
|
|
||
| export const getCards = async (params: GetCardsParams) => { | ||
| const response = await axiosClientHelper.get<CardsResponse>('/cards', { params }); | ||
| const result = cardsResponseSchema.safeParse(response.data); | ||
| if (!result.success) throw new Error(RESPONSE_INVALID_MESSAGE); | ||
| return result.data; | ||
| }; | ||
|
|
||
| export const putCard = async (cardId: number, cardForm: CardForm) => { | ||
| const response = await axiosClientHelper.put<Card>(`/cards/${cardId}`, cardForm); | ||
| const result = cardSchema.safeParse(response.data); | ||
| if (!result.success) throw new Error(RESPONSE_INVALID_MESSAGE); | ||
| return result.data; | ||
| }; | ||
|
|
||
| export const getCard = async (cardId: number) => { | ||
| const response = await axiosClientHelper.get<Card>(`/cards/${cardId}`); | ||
| const result = cardSchema.safeParse(response.data); | ||
| if (!result.success) throw new Error(RESPONSE_INVALID_MESSAGE); | ||
| return result.data; | ||
| }; | ||
|
|
||
| export const deleteCard = async (cardId: number) => { | ||
| await axiosClientHelper.delete<void>(`/cards/${cardId}`); | ||
| }; |
This file contains hidden or 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,57 @@ | ||
| import isValidDate from '@/utils/isValidDate'; | ||
| import { z } from 'zod'; | ||
|
|
||
| const IMAGE_URL = 'https://sprint-fe-project.s3.ap-northeast-2.amazonaws.com/taskify/task_image/'; | ||
|
|
||
| const cardBaseSchema = z.object({ | ||
| dashboardId: z.number(), | ||
| columnId: z.number(), | ||
| title: z.string(), | ||
| description: z.string(), | ||
| dueDate: z.string().refine((date) => isValidDate(date), { | ||
| message: '유효하지 않은 날짜 형식입니다.', | ||
| }), | ||
| tags: z.array(z.string()), | ||
| imageUrl: z | ||
| .string() | ||
| .url() | ||
| .refine((val) => val.startsWith(IMAGE_URL), { | ||
| message: '올바르지 않은 이미지 경로입니다.', | ||
| }), | ||
| }); | ||
|
|
||
| export const cardSchema = cardBaseSchema.extend({ | ||
| id: z.number(), | ||
| assignee: z.object({ | ||
| id: z.number(), | ||
| nickname: z.string(), | ||
| profileImageUrl: z.union([z.string(), z.null(), z.instanceof(URL)]), | ||
| }), | ||
| teamId: z.string(), | ||
| createdAt: z.union([z.string(), z.date()]), | ||
| updatedAt: z.union([z.string(), z.date()]), | ||
| }); | ||
|
|
||
| export type Card = z.infer<typeof cardSchema>; | ||
|
|
||
| export const cardFormSchema = cardBaseSchema.extend({ | ||
| assigneeUserId: z.number(), | ||
| }); | ||
|
|
||
| export type CardForm = z.infer<typeof cardFormSchema>; | ||
|
|
||
| export const cardsResponseSchema = z.object({ | ||
| cursorId: z.number().nullable(), | ||
| totalCount: z.number(), | ||
| cards: z.array(cardSchema), | ||
| }); | ||
|
|
||
| export type CardsResponse = z.infer<typeof cardsResponseSchema>; | ||
|
|
||
| export const getCardsParamsSchema = z.object({ | ||
| size: z.number().optional(), | ||
| cursorId: z.number().optional(), | ||
| columnId: z.number(), | ||
| }); | ||
|
|
||
| export type GetCardsParams = z.infer<typeof getCardsParamsSchema>; |
This file contains hidden or 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,47 @@ | ||
| import axiosClientHelper from '@/utils/network/axiosClientHelper'; | ||
| import { CardImageForm, CardImageResponse, cardImageResponseSchema, Column, ColumnForm, columnSchema, ColumnsResponse, columnsResponseSchema, GetColumnsParams } from './types'; | ||
|
|
||
| const RESPONSE_INVALID_MESSAGE = '서버에서 받은 데이터가 예상과 다릅니다'; | ||
|
|
||
| export const postColumn = async (dashboardId: number, columnForm: ColumnForm) => { | ||
| const response = await axiosClientHelper.post<Column>('/columns', { | ||
| ...columnForm, | ||
| dashboardId, | ||
| }); | ||
| const result = columnSchema.safeParse(response.data); | ||
| if (!result.success) throw new Error(RESPONSE_INVALID_MESSAGE); | ||
| return result.data; | ||
| }; | ||
|
|
||
| export const getColumns = async (params: GetColumnsParams) => { | ||
| const response = await axiosClientHelper.get<ColumnsResponse>('/columns', { | ||
| params, | ||
| }); | ||
|
|
||
| const result = columnsResponseSchema.safeParse(response.data); | ||
| if (!result.success) throw new Error(RESPONSE_INVALID_MESSAGE); | ||
| return result.data; | ||
| }; | ||
|
|
||
| export const putColumn = async (columnId: number, columnForm: ColumnForm) => { | ||
| const response = await axiosClientHelper.put<Column>(`/columns/${columnId}`, columnForm); | ||
| const result = columnSchema.safeParse(response.data); | ||
| if (!result.success) throw new Error(RESPONSE_INVALID_MESSAGE); | ||
| return result.data; | ||
| }; | ||
|
|
||
| export const deleteColumn = async (columnId: number) => { | ||
| await axiosClientHelper.delete<void>(`/columns/${columnId}`); | ||
| }; | ||
|
|
||
| export const postCardImage = async (columnId: number, cardImageForm: CardImageForm) => { | ||
| const response = await axiosClientHelper.post<CardImageResponse>(`/columns/${columnId}/card-image`, cardImageForm, { | ||
| headers: { | ||
| 'Content-Type': 'multipart/form-data', | ||
| }, | ||
| }); | ||
|
|
||
| const result = cardImageResponseSchema.safeParse(response.data); | ||
| if (!result.success) throw new Error(RESPONSE_INVALID_MESSAGE); | ||
| return result.data; | ||
| }; |
This file contains hidden or 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,43 @@ | ||
| import { z } from 'zod'; | ||
|
|
||
| export const columnSchema = z.object({ | ||
| id: z.number(), | ||
| title: z.string(), | ||
| teamId: z.string(), | ||
| dashboardId: z.number(), | ||
| createdAt: z.union([z.string(), z.instanceof(URL)]), | ||
| updatedAt: z.union([z.string(), z.instanceof(URL)]), | ||
| }); | ||
|
|
||
| export type Column = z.infer<typeof columnSchema>; | ||
|
|
||
| export const columnsResponseSchema = z.object({ | ||
| result: z.string(), | ||
| data: z.array(columnSchema), | ||
| }); | ||
|
|
||
| export type ColumnsResponse = z.infer<typeof columnsResponseSchema>; | ||
|
|
||
| export const getColumnsParamsSchema = z.object({ | ||
| dashboardId: z.number(), | ||
| }); | ||
|
|
||
| export type GetColumnsParams = z.infer<typeof getColumnsParamsSchema>; | ||
|
|
||
| export const columnFormSchema = z.object({ | ||
| title: z.string(), | ||
| }); | ||
|
|
||
| export type ColumnForm = z.infer<typeof columnFormSchema>; | ||
|
|
||
| export const cardImageFormSchema = z.object({ | ||
| image: z.instanceof(File), | ||
| }); | ||
|
|
||
| export type CardImageForm = z.infer<typeof cardImageFormSchema>; | ||
|
|
||
| export const cardImageResponseSchema = z.object({ | ||
| imageUrl: z.union([z.string(), z.instanceof(URL)]), | ||
| }); | ||
|
|
||
| export type CardImageResponse = z.infer<typeof cardImageResponseSchema>; |
This file contains hidden or 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,29 @@ | ||
| import axiosClientHelper from '@/utils/network/axiosClientHelper'; | ||
| import { Comment, CommentForm, commentSchema, CommentsResponse, commentsResponseSchema, GetCommentsParams, PutCommentForm } from './types'; | ||
|
|
||
| const RESPONSE_INVALID_MESSAGE = '서버에서 받은 데이터가 예상과 다릅니다'; | ||
|
|
||
| export const postComment = async (commentForm: CommentForm) => { | ||
| const response = await axiosClientHelper.post<Comment>('/comments', commentForm); | ||
| const result = commentSchema.safeParse(response.data); | ||
| if (!result.success) throw new Error(RESPONSE_INVALID_MESSAGE); | ||
| return result.data; | ||
| }; | ||
|
|
||
| export const getComments = async (params: GetCommentsParams) => { | ||
| const response = await axiosClientHelper.get<CommentsResponse>('/comments', { params }); | ||
| const result = commentsResponseSchema.safeParse(response.data); | ||
| if (!result.success) throw new Error(RESPONSE_INVALID_MESSAGE); | ||
| return result.data; | ||
| }; | ||
|
|
||
| export const putComment = async (commentId: number, putCommentForm: PutCommentForm) => { | ||
| const response = await axiosClientHelper.put<Comment>(`/comments/${commentId}`, putCommentForm); | ||
| const result = commentSchema.safeParse(response.data); | ||
| if (!result.success) throw new Error(RESPONSE_INVALID_MESSAGE); | ||
| return result.data; | ||
| }; | ||
|
|
||
| export const deleteComment = async (commentId: number) => { | ||
| await axiosClientHelper.delete<void>(`/comments/${commentId}`); | ||
| }; |
This file contains hidden or 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,46 @@ | ||
| import { z } from 'zod'; | ||
|
|
||
| export const commentSchema = z.object({ | ||
| id: z.number(), | ||
| content: z.string(), | ||
| createdAt: z.union([z.string(), z.date()]), | ||
| updatedAt: z.union([z.string(), z.date()]), | ||
| cardId: z.number(), | ||
| author: z.object({ | ||
| id: z.number(), | ||
| nickname: z.string(), | ||
| profileImageUrl: z.union([z.null(), z.string(), z.instanceof(URL)]), | ||
| }), | ||
| }); | ||
|
|
||
| export type Comment = z.infer<typeof commentSchema>; | ||
|
|
||
| export const commentFormSchema = z.object({ | ||
| content: z.string(), | ||
| cardId: z.number(), | ||
| columnId: z.number(), | ||
| dashboardId: z.number(), | ||
| }); | ||
|
|
||
| export type CommentForm = z.infer<typeof commentFormSchema>; | ||
|
|
||
| export const getCommentsParamsSchema = z.object({ | ||
| cursorId: z.number().optional(), | ||
| size: z.number().optional(), | ||
| cardId: z.number(), | ||
| }); | ||
|
|
||
| export type GetCommentsParams = z.infer<typeof getCommentsParamsSchema>; | ||
|
|
||
| export const commentsResponseSchema = z.object({ | ||
| cursorId: z.number().nullable(), | ||
| comments: z.array(commentSchema), | ||
| }); | ||
|
|
||
| export type CommentsResponse = z.infer<typeof commentsResponseSchema>; | ||
|
|
||
| export const putCommentFormSchema = z.object({ | ||
| content: z.string(), | ||
| }); | ||
|
|
||
| export type PutCommentForm = z.infer<typeof putCommentFormSchema>; |
This file contains hidden or 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,13 @@ | ||
| import dayjs from 'dayjs'; | ||
|
|
||
| const isValidDate = (date: string | Date) => { | ||
| const format = 'YYYY-MM-DD HH:mm'; | ||
| if (date instanceof Date) { | ||
| const formattedDate = dayjs(date).format(format); | ||
| return dayjs(formattedDate, format, true).isValid(); | ||
| } | ||
|
|
||
| return dayjs(date, format, true).isValid(); | ||
| }; | ||
|
|
||
| export default isValidDate; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.