-
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.
Merge remote-tracking branch 'refs/remotes/origin/main'
- Loading branch information
Showing
56 changed files
with
984 additions
and
498 deletions.
There are no files selected for viewing
178 changes: 89 additions & 89 deletions
178
client/src/app/[locale]/(unauth)/api/guestbook/route.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 |
---|---|---|
@@ -1,89 +1,89 @@ | ||
import { eq, sql } from 'drizzle-orm'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
import { db } from '@/libs/DB'; | ||
import { logger } from '@/libs/Logger'; | ||
import { guestbookSchema } from '@/models/Schema'; | ||
import { | ||
DeleteGuestbookValidation, | ||
EditGuestbookValidation, | ||
GuestbookValidation, | ||
} from '@/validations/GuestbookValidation'; | ||
|
||
export const POST = async (request: Request) => { | ||
const json = await request.json(); | ||
const parse = GuestbookValidation.safeParse(json); | ||
|
||
if (!parse.success) { | ||
return NextResponse.json(parse.error.format(), { status: 422 }); | ||
} | ||
|
||
try { | ||
const guestbook = await db | ||
.insert(guestbookSchema) | ||
.values(parse.data) | ||
.returning(); | ||
|
||
logger.info('A new guestbook has been created'); | ||
|
||
return NextResponse.json({ | ||
id: guestbook[0]?.id, | ||
}); | ||
} catch (error) { | ||
logger.error(error, 'An error occurred while creating a guestbook'); | ||
|
||
return NextResponse.json({}, { status: 500 }); | ||
} | ||
}; | ||
|
||
export const PUT = async (request: Request) => { | ||
const json = await request.json(); | ||
const parse = EditGuestbookValidation.safeParse(json); | ||
|
||
if (!parse.success) { | ||
return NextResponse.json(parse.error.format(), { status: 422 }); | ||
} | ||
|
||
try { | ||
await db | ||
.update(guestbookSchema) | ||
.set({ | ||
...parse.data, | ||
updatedAt: sql`(strftime('%s', 'now'))`, | ||
}) | ||
.where(eq(guestbookSchema.id, parse.data.id)) | ||
.run(); | ||
|
||
logger.info('A guestbook entry has been updated'); | ||
|
||
return NextResponse.json({}); | ||
} catch (error) { | ||
logger.error(error, 'An error occurred while updating a guestbook'); | ||
|
||
return NextResponse.json({}, { status: 500 }); | ||
} | ||
}; | ||
|
||
export const DELETE = async (request: Request) => { | ||
const json = await request.json(); | ||
const parse = DeleteGuestbookValidation.safeParse(json); | ||
|
||
if (!parse.success) { | ||
return NextResponse.json(parse.error.format(), { status: 422 }); | ||
} | ||
|
||
try { | ||
await db | ||
.delete(guestbookSchema) | ||
.where(eq(guestbookSchema.id, parse.data.id)) | ||
.run(); | ||
|
||
logger.info('A guestbook entry has been deleted'); | ||
|
||
return NextResponse.json({}); | ||
} catch (error) { | ||
logger.error(error, 'An error occurred while deleting a guestbook'); | ||
|
||
return NextResponse.json({}, { status: 500 }); | ||
} | ||
}; | ||
// import { eq, sql } from 'drizzle-orm'; | ||
// import { NextResponse } from 'next/server'; | ||
|
||
// import { db } from '@/libs/DB'; | ||
// import { logger } from '@/libs/Logger'; | ||
// import { guestbookSchema } from '@/models/Schema'; | ||
// import { | ||
// DeleteGuestbookValidation, | ||
// EditGuestbookValidation, | ||
// GuestbookValidation, | ||
// } from '@/validations/GuestbookValidation'; | ||
|
||
// export const POST = async (request: Request) => { | ||
// const json = await request.json(); | ||
// const parse = GuestbookValidation.safeParse(json); | ||
|
||
// if (!parse.success) { | ||
// return NextResponse.json(parse.error.format(), { status: 422 }); | ||
// } | ||
|
||
// try { | ||
// const guestbook = await db | ||
// .insert(guestbookSchema) | ||
// .values(parse.data) | ||
// .returning(); | ||
|
||
// logger.info('A new guestbook has been created'); | ||
|
||
// return NextResponse.json({ | ||
// id: guestbook[0]?.id, | ||
// }); | ||
// } catch (error) { | ||
// logger.error(error, 'An error occurred while creating a guestbook'); | ||
|
||
// return NextResponse.json({}, { status: 500 }); | ||
// } | ||
// }; | ||
|
||
// export const PUT = async (request: Request) => { | ||
// const json = await request.json(); | ||
// const parse = EditGuestbookValidation.safeParse(json); | ||
|
||
// if (!parse.success) { | ||
// return NextResponse.json(parse.error.format(), { status: 422 }); | ||
// } | ||
|
||
// try { | ||
// await db | ||
// .update(guestbookSchema) | ||
// .set({ | ||
// ...parse.data, | ||
// updatedAt: sql`(strftime('%s', 'now'))`, | ||
// }) | ||
// .where(eq(guestbookSchema.id, parse.data.id)) | ||
// .run(); | ||
|
||
// logger.info('A guestbook entry has been updated'); | ||
|
||
// return NextResponse.json({}); | ||
// } catch (error) { | ||
// logger.error(error, 'An error occurred while updating a guestbook'); | ||
|
||
// return NextResponse.json({}, { status: 500 }); | ||
// } | ||
// }; | ||
|
||
// export const DELETE = async (request: Request) => { | ||
// const json = await request.json(); | ||
// const parse = DeleteGuestbookValidation.safeParse(json); | ||
|
||
// if (!parse.success) { | ||
// return NextResponse.json(parse.error.format(), { status: 422 }); | ||
// } | ||
|
||
// try { | ||
// await db | ||
// .delete(guestbookSchema) | ||
// .where(eq(guestbookSchema.id, parse.data.id)) | ||
// .run(); | ||
|
||
// logger.info('A guestbook entry has been deleted'); | ||
|
||
// return NextResponse.json({}); | ||
// } catch (error) { | ||
// logger.error(error, 'An error occurred while deleting a guestbook'); | ||
|
||
// return NextResponse.json({}, { status: 500 }); | ||
// } | ||
// }; |
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
Binary file not shown.
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
Empty file.
60 changes: 30 additions & 30 deletions
60
server/src/application/post/create-old/create-post.usecase.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 |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import { BaseUseCase } from '@application/shared'; | ||
import { CreatePostRequestDto } from '@contracts/dtos/posts/create/create-post.request'; | ||
import { CreatePostResponseDto } from '@contracts/dtos/posts/create/create-post.response'; | ||
import { Post } from '@domain/entities'; | ||
import { IPostRepository } from '@domain/repositories/post.repository'; | ||
// import { BaseUseCase } from '@application/shared'; | ||
// import { CreatePostResponseDto } from '@contracts/dtos/posts/create/create-post.response'; | ||
// import { Post } from '@domain/entities'; | ||
// import { IPostRepository } from '@domain/repositories/post.repository'; | ||
// import { CreatePostRequest } from '../create/create-post.request'; | ||
|
||
class CreatePostUseCase extends BaseUseCase< | ||
CreatePostRequestDto, | ||
CreatePostResponseDto | ||
> { | ||
protected async performOperation( | ||
request: CreatePostRequestDto, | ||
): Promise<CreatePostResponseDto> { | ||
const post = Post.create( | ||
request.title, | ||
request.content, | ||
request.authorId, | ||
request.author, | ||
); | ||
const createdPost = await this._postRepository.createPost(post); | ||
const result: CreatePostResponseDto = { | ||
author: createdPost.author, | ||
post: createdPost, | ||
}; | ||
return result; | ||
} | ||
constructor(private _postRepository: IPostRepository) { | ||
super(); | ||
} | ||
} | ||
// class CreatePostUseCase extends BaseUseCase< | ||
// CreatePostRequest, | ||
// CreatePostResponseDto | ||
// > { | ||
// protected async performOperation( | ||
// request: CreatePostRequest, | ||
// ): Promise<CreatePostResponseDto> { | ||
// const post = Post.create( | ||
// request.title, | ||
// request.content, | ||
// request.authorId, | ||
// request.author, | ||
// ); | ||
// const createdPost = await this._postRepository.createPost(post); | ||
// const result: CreatePostResponseDto = { | ||
// author: createdPost.author, | ||
// post: createdPost, | ||
// }; | ||
// return result; | ||
// } | ||
// constructor(private _postRepository: IPostRepository) { | ||
// super(); | ||
// } | ||
// } | ||
|
||
export { CreatePostUseCase }; | ||
// export { CreatePostUseCase }; |
This file was deleted.
Oops, something went wrong.
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.