Toggle navigation
Toggle navigation
This project
Loading...
Sign in
엄성진
/
learn-in-web-backend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
sungjin
2021-12-05 15:54:50 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
97b75cf9437db5a35e05f8e56f806eb5022b98a6
97b75cf9
1 parent
a4747ff2
Add post searching api with prisma beta feature
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
2 deletions
prisma/schema.prisma
src/post/post.controller.ts
src/post/post.service.ts
prisma/schema.prisma
View file @
97b75cf
...
...
@@ -3,6 +3,7 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch"]
}
datasource db {
...
...
@@ -24,7 +25,7 @@ model User {
}
model Post {
id Int @id @unique @default(autoincrement())
id Int
@id @unique @default(autoincrement())
title String
createdAt DateTime @default(now())
private Boolean @default(false)
...
...
@@ -55,7 +56,7 @@ model Comment {
model PostLike {
id String @id @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
post Post @relation(fields: [postId], references: [id])
postId
Int
postId Int
user User @relation(fields: [userId], references: [id])
userId String @db.Uuid
}
...
...
src/post/post.controller.ts
View file @
97b75cf
...
...
@@ -85,4 +85,9 @@ export class PostController {
getComments
(
@
Param
(
'id'
)
id
)
{
return
this
.
postService
.
getComments
(
id
);
}
@
Post
(
'search'
)
search
(
@
Body
()
body
)
{
return
this
.
postService
.
searchPost
(
body
.
search
);
}
}
...
...
src/post/post.service.ts
View file @
97b75cf
...
...
@@ -258,4 +258,34 @@ export class PostService {
});
return
comments
;
}
async
searchPost
(
search
:
string
)
{
const
query
:
string
=
search
.
split
(
' '
).
join
(
' | '
);
const
posts
=
await
this
.
prisma
.
post
.
findMany
({
where
:
{
OR
:
[
{
title
:
{
search
:
query
,
},
},
{
explain
:
{
search
:
query
,
},
},
{
example
:
{
search
:
query
,
},
},
],
},
orderBy
:
{
postlikes
:
{
_count
:
'desc'
,
},
},
});
return
posts
;
}
}
...
...
Please
register
or
login
to post a comment