Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design2
/
2015104215
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
장재혁
2021-05-13 05:34:03 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b1c7694a205e3f352a4cbed8b528e5c7a7bb8934
b1c7694a
1 parent
08155d09
Add Post CR
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
78 additions
and
42 deletions
project/packages/api/database.db
project/packages/api/src/post/dto/post.input.ts
project/packages/api/src/post/model/post.entity.ts
project/packages/api/src/post/post.resolver.ts
project/packages/api/src/post/post.service.ts
project/packages/api/src/schema.gql
project/packages/api/src/shared/utils.ts
project/packages/api/database.db
View file @
b1c7694
No preview for this file type
project/packages/api/src/post/dto/post.input.ts
View file @
b1c7694
import
{
Field
,
InputType
,
PartialType
,
PickType
}
from
'@nestjs/graphql'
;
import
{
IsNumber
}
from
'class-validator'
;
import
{
Post
}
from
'../model/post.entity'
;
import
{
Field
,
InputType
,
PartialType
,
PickType
}
from
'@nestjs/graphql'
import
{
IsNumber
}
from
'class-validator'
import
{
Post
}
from
'../model/post.entity'
@
InputType
()
export
class
GetPostInput
{
@
Field
()
id
:
number
;
@
Field
(
{
nullable
:
true
}
)
id
?:
number
@
Field
({
nullable
:
true
})
author
?:
string
;
author
?:
string
@
Field
({
nullable
:
true
})
category
?:
string
;
category
?:
string
}
@
InputType
()
...
...
@@ -25,5 +25,5 @@ export class CreatePostInput extends PickType(
export
class
UpdatePostInput
extends
PartialType
(
CreatePostInput
)
{
@
Field
()
@
IsNumber
()
id
:
number
;
id
:
number
}
...
...
project/packages/api/src/post/model/post.entity.ts
View file @
b1c7694
/* eslint-disable @typescript-eslint/no-unused-vars */
import
{
ObjectType
,
Field
,
Int
}
from
'@nestjs/graphql'
;
import
{
Column
,
Entity
,
PrimaryGeneratedColumn
}
from
'typeorm'
;
import
{
ObjectType
,
Field
,
Int
}
from
'@nestjs/graphql'
import
{
Column
,
Entity
,
PrimaryGeneratedColumn
}
from
'typeorm'
@
Entity
({
name
:
'post'
})
@
ObjectType
()
export
class
Post
{
@
PrimaryGeneratedColumn
()
@
Field
((
type
)
=>
Int
)
id
:
number
;
id
:
number
@
Column
()
@
Field
()
author
:
string
;
author
:
string
@
Column
()
@
Field
()
created_date
:
string
;
created_date
:
string
@
Column
({
nullable
:
true
})
@
Field
({
nullable
:
true
})
updated_date
?:
string
;
updated_date
?:
string
@
Column
()
@
Field
()
title
:
string
;
title
:
string
@
Column
()
@
Field
()
content
:
string
;
content
:
string
@
Column
()
@
Field
()
category
:
string
;
category
:
string
}
...
...
project/packages/api/src/post/post.resolver.ts
View file @
b1c7694
import
{
Args
,
Mutation
,
Query
,
Resolver
}
from
'@nestjs/graphql'
import
{
PostService
}
from
'./post.service'
import
{
Post
}
from
'./model/post.entity'
import
{
GetPostInput
}
from
'./dto/post.input'
import
{
CreatePostInput
,
GetPostInput
}
from
'./dto/post.input'
@
Resolver
((
of
)
=>
Post
)
export
class
PostResolver
{
constructor
(
private
postService
:
PostService
)
{}
@
Query
((
returns
)
=>
[
Post
])
getPosts
():
Promise
<
Post
[]
>
{
get
All
Posts
():
Promise
<
Post
[]
>
{
return
this
.
postService
.
findAll
()
}
@
Query
((
returns
)
=>
[
Post
])
getSomePosts
(
@
Args
(
'input'
)
input
:
GetPostInput
):
Promise
<
Post
[]
>
{
return
this
.
postService
.
findSome
(
input
)
}
@
Query
((
returns
)
=>
Post
)
getPost
(
@
Args
(
'id'
)
id
:
number
):
Promise
<
Post
>
{
return
this
.
postService
.
findOne
(
id
)
}
@
Mutation
(()
=>
Post
,
{
name
:
'createPost'
})
createPost
(
@
Args
(
'input'
)
input
:
CreatePostInput
):
Promise
<
Post
>
{
return
this
.
postService
.
createOne
(
input
)
}
}
...
...
project/packages/api/src/post/post.service.ts
View file @
b1c7694
...
...
@@ -7,6 +7,7 @@ import {
UpdatePostInput
,
}
from
'./dto/post.input'
import
{
Post
}
from
'./model/post.entity'
import
{
getCurrentDate
}
from
'../shared/utils'
@
Injectable
()
export
class
PostService
{
...
...
@@ -26,7 +27,9 @@ export class PostService {
async
findSome
(
input
:
Partial
<
GetPostInput
>
):
Promise
<
Post
[]
>
{
return
this
.
postRepository
.
createQueryBuilder
(
'post'
)
.
where
(
'post.author like :author'
,
{
author
:
input
.
author
})
.
where
(
'post.id like :id'
,
{
id
:
input
.
id
})
.
orWhere
(
'post.author like :author'
,
{
author
:
input
.
author
})
.
orWhere
(
'post.category like :category'
,
{
category
:
input
.
category
})
.
getMany
()
}
...
...
@@ -37,28 +40,14 @@ export class PostService {
await
queryRunner
.
startTransaction
()
try
{
result
=
await
queryRunner
.
manager
.
save
(
this
.
postRepository
.
create
(
input
))
await
queryRunner
.
commitTransaction
()
}
catch
(
err
)
{
await
queryRunner
.
rollbackTransaction
()
throw
err
}
finally
{
await
queryRunner
.
release
()
}
return
result
const
newInput
=
{
...
input
,
created_date
:
getCurrentDate
(),
author
:
'test'
,
}
async
updateOne
(
input
:
UpdatePostInput
):
Promise
<
Post
>
{
let
result
const
queryRunner
:
QueryRunner
=
this
.
connection
.
createQueryRunner
()
await
queryRunner
.
connect
()
await
queryRunner
.
startTransaction
()
try
{
const
before
=
await
this
.
postRepository
.
findOne
(
input
.
id
)
result
=
await
queryRunner
.
manager
.
save
(
this
.
postRepository
.
create
(
input
))
result
=
await
queryRunner
.
manager
.
save
(
this
.
postRepository
.
create
(
newInput
),
)
await
queryRunner
.
commitTransaction
()
}
catch
(
err
)
{
await
queryRunner
.
rollbackTransaction
()
...
...
project/packages/api/src/schema.gql
View file @
b1c7694
...
...
@@ -7,8 +7,21 @@ input CreateMyInput {
type: String
}
input CreatePostInput {
category: String!
content: String!
title: String!
}
input GetPostInput {
author: String
category: String
id: Float
}
type Mutation {
createMyPage(createMyInput: CreateMyInput!): MyPage!
createPost(input: CreatePostInput!): Post!
}
type MyPage {
...
...
@@ -28,7 +41,8 @@ type Post {
}
type Query {
getAllPosts: [Post!]!
getPost(id: Float!): Post!
get
Posts
: [Post!]!
get
SomePosts(input: GetPostInput!)
: [Post!]!
myPage: [MyPage!]!
}
...
...
project/packages/api/src/shared/utils.ts
0 → 100644
View file @
b1c7694
export
function
getCurrentDate
()
{
const
now
=
new
Date
()
const
MM
=
now
.
getMonth
()
+
1
const
DD
=
now
.
getDate
()
const
yyyymmdd
=
[
now
.
getFullYear
(),
(
MM
>
9
?
''
:
'0'
)
+
MM
,
(
DD
>
9
?
''
:
'0'
)
+
DD
,
].
join
(
'-'
)
const
hh
=
now
.
getHours
()
const
mm
=
now
.
getMinutes
()
const
ss
=
now
.
getSeconds
()
const
hhmmss
=
[
(
hh
>
9
?
''
:
'0'
)
+
hh
,
(
mm
>
9
?
''
:
'0'
)
+
mm
,
(
ss
>
9
?
''
:
'0'
)
+
ss
,
].
join
(
':'
)
return
`
${
yyyymmdd
}
${
hhmmss
}
`
}
Please
register
or
login
to post a comment