-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
23 changed files
with
264 additions
and
7 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
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,8 +1,13 @@ | ||
import RouterProvider from "./providers/RouterProvider"; | ||
import { QueryClientProvider } from "./providers/query-client.provider"; | ||
import { RouterProvider } from "./providers/router.provider"; | ||
import "./styles/normalize.css"; | ||
|
||
const App = () => { | ||
return <RouterProvider />; | ||
return ( | ||
<QueryClientProvider> | ||
<RouterProvider /> | ||
</QueryClientProvider> | ||
); | ||
}; | ||
|
||
export default App; |
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,15 @@ | ||
import { | ||
QueryClient, | ||
QueryClientProvider as TanstackQueryClientProvider, | ||
} from "@tanstack/react-query"; | ||
import { PropsWithChildren } from "react"; | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
export const QueryClientProvider = ({ children }: PropsWithChildren) => { | ||
return ( | ||
<TanstackQueryClientProvider client={queryClient}> | ||
{children} | ||
</TanstackQueryClientProvider> | ||
); | ||
}; |
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,7 @@ | ||
import { HttpMethod, fetcher } from "@/shared/lib/fetcher"; | ||
import type { CreateLinkBookDto } from "./dto/create-link-book.dto"; | ||
|
||
export const createLinkBook = (dto: CreateLinkBookDto) => | ||
fetcher.fetch(HttpMethod.POST, "/link-books", { | ||
body: dto, | ||
}); |
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,6 @@ | ||
import { HttpMethod, fetcher } from "@/shared/lib/fetcher"; | ||
import type { GetLinkBooksDto } from "./dto/get-link-books.dto"; | ||
|
||
export const deleteLinkBook = (id: string) => { | ||
return fetcher.fetch<GetLinkBooksDto>(HttpMethod.DELETE, `/link-books/${id}`); | ||
}; |
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,6 @@ | ||
export type CreateLinkBookDto = { | ||
backgroundColor: string; | ||
illustration: string; | ||
title: string; | ||
titleColor: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export interface GetLinkBooksDto { | ||
linkBooks: { | ||
backgroundColor: string; | ||
createdAt: string; | ||
illustration: string; | ||
isDefault: string; | ||
lastSavedAt: string; | ||
linkBookId: string; | ||
linkCount: number; | ||
title: string; | ||
titleColor: string; | ||
userId: string; | ||
}[]; | ||
totalLinkCount: number; | ||
} |
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,6 @@ | ||
export type UpdateLinkBookDto = { | ||
backgroundColor: string; | ||
illustration: string; | ||
title: string; | ||
titleColor: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { HttpMethod, fetcher } from "@/shared/lib/fetcher"; | ||
import { mapLinkBooks } from "@/entities/link-book/api/mapper/link-books.map"; | ||
import type { GetLinkBooksDto } from "./dto/get-link-books.dto"; | ||
|
||
export const getLinkBooks = (query: { | ||
sort: "created_at" | "last_saved_at" | "title"; | ||
}) => | ||
fetcher | ||
.fetch<GetLinkBooksDto>(HttpMethod.GET, "/api/link-books", { | ||
query, | ||
}) | ||
.then(mapLinkBooks); |
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,18 @@ | ||
import type { LinkBook } from "../../model/link-book"; | ||
import type { GetLinkBooksDto } from "../dto/get-link-books.dto"; | ||
|
||
export const mapLinkBooks = ( | ||
response: GetLinkBooksDto, | ||
): { | ||
linkBooks: LinkBook[]; | ||
totalLinkCount: number; | ||
} => { | ||
return { | ||
linkBooks: response.linkBooks.map((linkBook) => ({ | ||
...linkBook, | ||
createdAt: new Date(linkBook.createdAt), | ||
lastSavedAt: new Date(linkBook.lastSavedAt), | ||
})), | ||
totalLinkCount: response.totalLinkCount, | ||
}; | ||
}; |
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,9 @@ | ||
import { HttpMethod, fetcher } from "@/shared/lib/fetcher"; | ||
import type { GetLinkBooksDto } from "./dto/get-link-books.dto"; | ||
import type { UpdateLinkBookDto } from "./dto/update-link-book.dto"; | ||
|
||
export const updateLinkBook = (id: string, dto: UpdateLinkBookDto) => { | ||
return fetcher.fetch<GetLinkBooksDto>(HttpMethod.PUT, `/link-books/${id}`, { | ||
body: dto, | ||
}); | ||
}; |
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,12 @@ | ||
export interface LinkBook { | ||
backgroundColor: string; | ||
createdAt: Date; | ||
illustration: string; | ||
isDefault: string; | ||
lastSavedAt: Date; | ||
linkBookId: string; | ||
linkCount: number; | ||
title: string; | ||
titleColor: string; | ||
userId: string; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/entities/notification/api/dto/get-notifications.dto.ts
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,21 @@ | ||
export interface GetNotificationsDto { | ||
notifications: [ | ||
{ | ||
body: string; | ||
createdAt: string; | ||
isRead: boolean; | ||
notificationId: string; | ||
title: string; | ||
type: string; | ||
userId: string; | ||
}, | ||
]; | ||
page: { | ||
next: number; | ||
page: number; | ||
perPage: number; | ||
prev: number; | ||
total: number; | ||
totalPage: number; | ||
}; | ||
} |
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,12 @@ | ||
import { HttpMethod, fetcher } from "@/shared/lib/fetcher"; | ||
import type { GetNotificationsDto } from "./dto/get-notifications.dto"; | ||
import { mapNotifications } from "./mapper/notifications.map"; | ||
|
||
export const getNotifications = (page: number) => | ||
fetcher | ||
.fetch<GetNotificationsDto>(HttpMethod.GET, "/notifications", { | ||
query: { | ||
page, | ||
}, | ||
}) | ||
.then(mapNotifications); |
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,17 @@ | ||
import { Notification } from "../../model/notification"; | ||
import type { GetNotificationsDto } from "../dto/get-notifications.dto"; | ||
|
||
export const mapNotifications = ( | ||
response: GetNotificationsDto, | ||
): { | ||
notifications: Notification[]; | ||
page: GetNotificationsDto["page"]; | ||
} => { | ||
return { | ||
notifications: response.notifications.map((notification) => ({ | ||
...notification, | ||
createdAt: new Date(notification.createdAt), | ||
})), | ||
page: response.page, | ||
}; | ||
}; |
File renamed without changes.
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,9 @@ | ||
export interface Notification { | ||
body: string; | ||
createdAt: Date; | ||
isRead: boolean; | ||
notificationId: string; | ||
title: string; | ||
type: string; | ||
userId: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const RootPage = () => { | ||
return <>Root Page</>; | ||
return <></>; | ||
}; | ||
|
||
export default RootPage; |
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,59 @@ | ||
export enum HttpMethod { | ||
GET = "GET", | ||
POST = "POST", | ||
PUT = "PUT", | ||
DELETE = "DELETE", | ||
} | ||
|
||
export type FetchQuery = Record<string, string | number>; | ||
export type FetchBody = Record<string, unknown>; | ||
|
||
export type FetchOptions = { | ||
query?: FetchQuery; | ||
body?: FetchBody; | ||
}; | ||
|
||
type FetcherConfig = { | ||
baseUrl?: string; | ||
}; | ||
|
||
class Fetcher { | ||
constructor(private config: FetcherConfig) {} | ||
|
||
public async fetch<T>( | ||
method: HttpMethod, | ||
endpoint: string, | ||
options?: FetchOptions, | ||
): Promise<T> { | ||
const response = await fetch(this.getUrl(endpoint, options?.query), { | ||
method, | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: import.meta.env.AUTHORIZATION, | ||
}, | ||
body: options?.body ? JSON.stringify(options.body) : undefined, | ||
}); | ||
|
||
if (!response.ok) { | ||
// | ||
} | ||
return await response.json(); | ||
} | ||
|
||
private getUrl( | ||
endpoint: string, | ||
query?: Record<string, string | number>, | ||
): string { | ||
const url = new URL(endpoint, this.config.baseUrl); | ||
if (query) { | ||
Object.entries(query).forEach(([key, value]) => { | ||
url.searchParams.append(key, value.toString()); | ||
}); | ||
} | ||
return url.toString(); | ||
} | ||
} | ||
|
||
export const fetcher = new Fetcher({ | ||
baseUrl: import.meta.env.BASE_URL, | ||
}); |
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