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-27 00:50:04 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e6c5651de26422cff4bdeeab250489877601a785
e6c5651d
1 parent
b1c7694a
Add likeable API
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
356 additions
and
21 deletions
project/packages/api/database.db
project/packages/api/src/app.module.ts
project/packages/api/src/comment/comment.entity.ts
project/packages/api/src/comment/comment.module.ts
project/packages/api/src/comment/comment.resolver.ts
project/packages/api/src/comment/comment.service.ts
project/packages/api/src/comment/dto/comment.input.ts
project/packages/api/src/comment/model/comment.entity.ts
project/packages/api/src/likeable/dto/likeable.input.ts
project/packages/api/src/likeable/likeable.entity.ts
project/packages/api/src/likeable/likeable.module.ts
project/packages/api/src/likeable/likeable.resolver.ts
project/packages/api/src/likeable/likeable.service.spec.ts
project/packages/api/src/likeable/likeable.service.ts
project/packages/api/src/likeable/model/likeable.entity.ts
project/packages/api/src/post/post.service.ts
project/packages/api/src/schema.gql
project/packages/api/src/shared/const.ts
project/packages/api/database.db
View file @
e6c5651
No preview for this file type
project/packages/api/src/app.module.ts
View file @
e6c5651
...
...
@@ -8,7 +8,6 @@ import { MypageModule } from './mypage/mypage.module'
import
{
PostModule
}
from
'./post/post.module'
import
{
CommentModule
}
from
'./comment/comment.module'
import
{
UserModule
}
from
'./user/user.module'
import
{
LikeableService
}
from
'./likeable/likeable.service'
import
{
LikeableModule
}
from
'./likeable/likeable.module'
@
Module
({
...
...
@@ -31,6 +30,6 @@ import { LikeableModule } from './likeable/likeable.module'
LikeableModule
,
],
controllers
:
[
AppController
],
providers
:
[
AppService
,
LikeableService
],
providers
:
[
AppService
],
})
export
class
AppModule
{}
...
...
project/packages/api/src/comment/comment.entity.ts
deleted
100644 → 0
View file @
b1c7694
File mode changed
project/packages/api/src/comment/comment.module.ts
View file @
e6c5651
import
{
Module
}
from
'@nestjs/common'
import
{
CommentService
}
from
'./comment.service'
import
{
CommentResolver
}
from
'./comment.resolver'
import
{
TypeOrmModule
}
from
'@nestjs/typeorm'
import
{
Comment
}
from
'./model/comment.entity'
@
Module
({
imports
:
[
TypeOrmModule
.
forFeature
([
Comment
])],
providers
:
[
CommentService
,
CommentResolver
],
})
export
class
CommentModule
{}
...
...
project/packages/api/src/comment/comment.resolver.ts
View file @
e6c5651
import
{
Resolver
}
from
'@nestjs/graphql'
import
{
Args
,
Mutation
,
Query
,
Resolver
}
from
'@nestjs/graphql'
import
{
CommentService
}
from
'./comment.service'
import
{
Comment
}
from
'./model/comment.entity'
import
{
CreateCommentInput
,
GetCommentInput
}
from
'./dto/comment.input'
@
Resolver
()
export
class
CommentResolver
{}
@
Resolver
((
of
)
=>
Comment
)
export
class
CommentResolver
{
constructor
(
private
commentService
:
CommentService
)
{}
@
Query
((
returns
)
=>
[
Comment
])
getAllComments
():
Promise
<
Comment
[]
>
{
return
this
.
commentService
.
findAll
()
}
@
Query
((
returns
)
=>
[
Comment
])
getSomeComments
(
@
Args
(
'input'
)
input
:
GetCommentInput
):
Promise
<
Comment
[]
>
{
return
this
.
commentService
.
findSome
(
input
)
}
@
Query
((
returns
)
=>
Comment
)
getComment
(
@
Args
(
'id'
)
id
:
number
):
Promise
<
Comment
>
{
return
this
.
commentService
.
findOne
(
id
)
}
@
Mutation
(()
=>
Comment
,
{
name
:
'createComment'
})
createComment
(
@
Args
(
'input'
)
input
:
CreateCommentInput
):
Promise
<
Comment
>
{
return
this
.
commentService
.
createOne
(
input
)
}
}
...
...
project/packages/api/src/comment/comment.service.ts
View file @
e6c5651
import
{
Injectable
}
from
'@nestjs/common'
import
{
InjectRepository
}
from
'@nestjs/typeorm'
import
{
QueryRunner
,
Repository
,
getConnection
}
from
'typeorm'
import
{
Comment
}
from
'./model/comment.entity'
import
{
getCurrentDate
}
from
'../shared/utils'
import
{
CreateCommentInput
,
GetCommentInput
}
from
'./dto/comment.input'
import
{
MASTER_TEST
}
from
'src/shared/const'
@
Injectable
()
export
class
CommentService
{}
export
class
CommentService
{
constructor
(
@
InjectRepository
(
Comment
)
private
commentRepository
:
Repository
<
Comment
>
,
)
{}
private
connection
=
getConnection
()
async
findAll
():
Promise
<
Comment
[]
>
{
return
this
.
commentRepository
.
find
()
}
async
findOne
(
id
:
number
):
Promise
<
Comment
>
{
return
this
.
commentRepository
.
findOne
(
id
)
}
async
findSome
(
input
:
Partial
<
GetCommentInput
>
):
Promise
<
Comment
[]
>
{
return
this
.
commentRepository
.
createQueryBuilder
(
'comment'
)
.
where
(
'comment.post_id = :post_id'
,
{
post_id
:
input
.
post_id
})
.
orWhere
(
'comment.author = :author'
,
{
author
:
input
.
author
})
.
orWhere
(
'comment.parent = :parent'
,
{
parent
:
input
.
parent
})
.
getMany
()
}
async
createOne
(
input
:
CreateCommentInput
):
Promise
<
Comment
>
{
let
result
const
queryRunner
:
QueryRunner
=
this
.
connection
.
createQueryRunner
()
await
queryRunner
.
connect
()
await
queryRunner
.
startTransaction
()
try
{
const
newInput
=
{
...
input
,
created_date
:
getCurrentDate
(),
author
:
MASTER_TEST
,
}
result
=
await
queryRunner
.
manager
.
save
(
this
.
commentRepository
.
create
(
newInput
),
)
await
queryRunner
.
commitTransaction
()
}
catch
(
err
)
{
await
queryRunner
.
rollbackTransaction
()
throw
err
}
finally
{
await
queryRunner
.
release
()
}
return
result
}
}
...
...
project/packages/api/src/comment/dto/comment.input.ts
View file @
e6c5651
import
{
Field
,
InputType
,
PickType
}
from
'@nestjs/graphql'
import
{
Comment
}
from
'../model/comment.entity'
@
InputType
()
export
class
GetCommentInput
{
@
Field
({
nullable
:
true
})
post_id
?:
number
@
Field
({
nullable
:
true
})
author
?:
string
@
Field
({
nullable
:
true
})
parent
?:
string
}
@
InputType
()
export
class
CreateCommentInput
extends
PickType
(
Comment
,
[
'post_id'
,
'content'
],
InputType
,
)
{
@
Field
({
nullable
:
true
})
parent
?:
number
}
...
...
project/packages/api/src/comment/model/comment.entity.ts
0 → 100644
View file @
e6c5651
/* eslint-disable @typescript-eslint/no-unused-vars */
import
{
ObjectType
,
Field
,
Int
}
from
'@nestjs/graphql'
import
{
Column
,
Entity
,
PrimaryGeneratedColumn
}
from
'typeorm'
@
Entity
({
name
:
'comment'
})
@
ObjectType
()
export
class
Comment
{
@
PrimaryGeneratedColumn
()
@
Field
((
type
)
=>
Int
)
id
:
number
@
Column
()
@
Field
()
author
:
string
@
Column
()
@
Field
((
type
)
=>
Int
)
post_id
:
number
@
Column
()
@
Field
((
type
)
=>
Int
)
parent
:
number
@
Column
()
@
Field
()
content
:
string
@
Column
()
@
Field
()
created_date
:
string
@
Column
({
nullable
:
true
})
@
Field
({
nullable
:
true
})
updated_date
?:
string
}
project/packages/api/src/likeable/dto/likeable.input.ts
View file @
e6c5651
import
{
Field
,
InputType
,
PickType
}
from
'@nestjs/graphql'
import
{
Likeable
}
from
'../model/likeable.entity'
@
InputType
()
export
class
GetLikeableInput
{
@
Field
({
nullable
:
true
})
likeable_id
?:
number
@
Field
({
nullable
:
true
})
user_id
?:
string
@
Field
()
likeable_type
:
string
}
@
InputType
()
export
class
CreateLikeableInput
extends
PickType
(
Likeable
,
[
'likeable_id'
,
'like_dislike'
,
'likeable_type'
],
InputType
,
)
{}
...
...
project/packages/api/src/likeable/likeable.entity.ts
deleted
100644 → 0
View file @
b1c7694
File mode changed
project/packages/api/src/likeable/likeable.module.ts
View file @
e6c5651
import
{
Module
}
from
'@nestjs/common'
import
{
LikeableResolver
}
from
'./likeable.resolver'
import
{
LikeableService
}
from
'./likeable.service'
import
{
TypeOrmModule
}
from
'@nestjs/typeorm'
import
{
Likeable
}
from
'./model/likeable.entity'
@
Module
({
providers
:
[
LikeableResolver
],
imports
:
[
TypeOrmModule
.
forFeature
([
Likeable
])],
providers
:
[
LikeableService
,
LikeableResolver
],
})
export
class
LikeableModule
{}
...
...
project/packages/api/src/likeable/likeable.resolver.ts
View file @
e6c5651
import
{
Resolver
}
from
'@nestjs/graphql'
import
{
Args
,
Mutation
,
Query
,
Resolver
}
from
'@nestjs/graphql'
import
{
CreateLikeableInput
,
GetLikeableInput
}
from
'./dto/likeable.input'
import
{
LikeableService
}
from
'./likeable.service'
import
{
Likeable
}
from
'./model/likeable.entity'
@
Resolver
()
export
class
LikeableResolver
{}
@
Resolver
((
of
)
=>
Likeable
)
export
class
LikeableResolver
{
constructor
(
private
likeableService
:
LikeableService
)
{}
@
Query
((
returns
)
=>
[
Likeable
])
getAllLikes
():
Promise
<
Likeable
[]
>
{
return
this
.
likeableService
.
findAll
()
}
@
Query
((
returns
)
=>
Number
)
getTotalLikes
(
@
Args
(
'input'
)
input
:
GetLikeableInput
):
Promise
<
number
>
{
return
this
.
likeableService
.
findSome
(
input
).
then
((
res
)
=>
res
.
length
)
}
@
Query
((
returns
)
=>
Likeable
)
getLikeable
(
@
Args
(
'id'
)
id
:
number
):
Promise
<
Likeable
>
{
return
this
.
likeableService
.
findOne
(
id
)
}
@
Mutation
(()
=>
Likeable
,
{
name
:
'createLikeable'
})
createLikeable
(
@
Args
(
'input'
)
input
:
CreateLikeableInput
):
Promise
<
Likeable
>
{
return
this
.
likeableService
.
createOne
(
input
)
}
}
...
...
project/packages/api/src/likeable/likeable.service.spec.ts
View file @
e6c5651
import
{
Test
,
TestingModule
}
from
'@nestjs/testing'
;
import
{
LikeableService
}
from
'./likeable.service'
;
import
{
Test
,
TestingModule
}
from
'@nestjs/testing'
import
{
LikeableService
}
from
'./likeable.service'
describe
(
'LikeableService'
,
()
=>
{
let
service
:
LikeableService
;
let
service
:
LikeableService
beforeEach
(
async
()
=>
{
const
module
:
TestingModule
=
await
Test
.
createTestingModule
({
providers
:
[
LikeableService
],
}).
compile
()
;
}).
compile
()
service
=
module
.
get
<
LikeableService
>
(
LikeableService
)
;
})
;
service
=
module
.
get
<
LikeableService
>
(
LikeableService
)
})
it
(
'should be defined'
,
()
=>
{
expect
(
service
).
toBeDefined
()
;
})
;
})
;
expect
(
service
).
toBeDefined
()
})
})
...
...
project/packages/api/src/likeable/likeable.service.ts
View file @
e6c5651
import
{
Injectable
}
from
'@nestjs/common'
import
{
InjectRepository
}
from
'@nestjs/typeorm'
import
{
QueryRunner
,
Repository
,
getConnection
}
from
'typeorm'
import
{
Likeable
}
from
'./model/likeable.entity'
import
{
getCurrentDate
}
from
'../shared/utils'
import
{
GetLikeableInput
,
CreateLikeableInput
}
from
'./dto/likeable.input'
import
{
MASTER_TEST
}
from
'src/shared/const'
@
Injectable
()
export
class
LikeableService
{}
export
class
LikeableService
{
constructor
(
@
InjectRepository
(
Likeable
)
private
likeableRepository
:
Repository
<
Likeable
>
,
)
{}
private
connection
=
getConnection
()
async
findAll
():
Promise
<
Likeable
[]
>
{
return
this
.
likeableRepository
.
find
()
}
async
findOne
(
id
:
number
):
Promise
<
Likeable
>
{
return
this
.
likeableRepository
.
findOne
(
id
)
}
async
findSome
(
input
:
Partial
<
GetLikeableInput
>
):
Promise
<
Likeable
[]
>
{
return
this
.
likeableRepository
.
createQueryBuilder
(
'likeable'
)
.
where
(
'likeable.user_id = :user_id'
,
{
user_id
:
input
.
user_id
})
.
orWhere
(
'likeable.likeable_id = :likeable_id'
,
{
likeable_id
:
input
.
likeable_id
,
})
.
andWhere
(
'likeable.likeable_type = :likeable_type'
,
{
likeable_type
:
input
.
likeable_type
,
})
.
getMany
()
}
async
createOne
(
input
:
CreateLikeableInput
):
Promise
<
Likeable
>
{
let
result
const
queryRunner
:
QueryRunner
=
this
.
connection
.
createQueryRunner
()
await
queryRunner
.
connect
()
await
queryRunner
.
startTransaction
()
try
{
const
newInput
=
{
...
input
,
like_dislike
:
input
.
like_dislike
>
0
?
1
:
-
1
,
user_id
:
MASTER_TEST
,
created_date
:
getCurrentDate
(),
}
result
=
await
queryRunner
.
manager
.
save
(
this
.
likeableRepository
.
create
(
newInput
),
)
await
queryRunner
.
commitTransaction
()
}
catch
(
err
)
{
await
queryRunner
.
rollbackTransaction
()
throw
err
}
finally
{
await
queryRunner
.
release
()
}
return
result
}
}
...
...
project/packages/api/src/likeable/model/likeable.entity.ts
0 → 100644
View file @
e6c5651
/* eslint-disable @typescript-eslint/no-unused-vars */
import
{
ObjectType
,
Field
,
Int
}
from
'@nestjs/graphql'
import
{
Column
,
Entity
,
PrimaryGeneratedColumn
}
from
'typeorm'
@
Entity
({
name
:
'likeable'
})
@
ObjectType
()
export
class
Likeable
{
@
PrimaryGeneratedColumn
()
@
Field
((
type
)
=>
Int
)
id
:
number
@
Column
()
@
Field
()
user_id
:
string
@
Column
()
@
Field
((
type
)
=>
Int
)
likeable_id
:
number
@
Column
()
@
Field
((
type
)
=>
Int
)
like_dislike
:
number
@
Column
()
@
Field
()
created_date
:
string
@
Column
()
@
Field
()
likeable_type
:
string
}
project/packages/api/src/post/post.service.ts
View file @
e6c5651
...
...
@@ -8,6 +8,7 @@ import {
}
from
'./dto/post.input'
import
{
Post
}
from
'./model/post.entity'
import
{
getCurrentDate
}
from
'../shared/utils'
import
{
MASTER_TEST
}
from
'src/shared/const'
@
Injectable
()
export
class
PostService
{
...
...
@@ -43,7 +44,7 @@ export class PostService {
const
newInput
=
{
...
input
,
created_date
:
getCurrentDate
(),
author
:
'test'
,
author
:
MASTER_TEST
,
}
result
=
await
queryRunner
.
manager
.
save
(
this
.
postRepository
.
create
(
newInput
),
...
...
project/packages/api/src/schema.gql
View file @
e6c5651
...
...
@@ -2,6 +2,28 @@
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
# ------------------------------------------------------
type Comment {
author: String!
content: String!
created_date: String!
id: Int!
parent: Int!
post_id: Int!
updated_date: String
}
input CreateCommentInput {
content: String!
parent: Float
post_id: Int!
}
input CreateLikeableInput {
like_dislike: Int!
likeable_id: Int!
likeable_type: String!
}
input CreateMyInput {
name: String!
type: String
...
...
@@ -13,13 +35,36 @@ input CreatePostInput {
title: String!
}
input GetCommentInput {
author: String
parent: String
post_id: Float
}
input GetLikeableInput {
likeable_id: Float
likeable_type: String!
user_id: String
}
input GetPostInput {
author: String
category: String
id: Float
}
type Likeable {
created_date: String!
id: Int!
like_dislike: Int!
likeable_id: Int!
likeable_type: String!
user_id: String!
}
type Mutation {
createComment(input: CreateCommentInput!): Comment!
createLikeable(input: CreateLikeableInput!): Likeable!
createMyPage(createMyInput: CreateMyInput!): MyPage!
createPost(input: CreatePostInput!): Post!
}
...
...
@@ -41,8 +86,14 @@ type Post {
}
type Query {
getAllComments: [Comment!]!
getAllLikes: [Likeable!]!
getAllPosts: [Post!]!
getComment(id: Float!): Comment!
getLikeable(id: Float!): Likeable!
getPost(id: Float!): Post!
getSomeComments(input: GetCommentInput!): [Comment!]!
getSomePosts(input: GetPostInput!): [Post!]!
getTotalLikes(input: GetLikeableInput!): Float!
myPage: [MyPage!]!
}
...
...
project/packages/api/src/shared/const.ts
View file @
e6c5651
...
...
@@ -2,3 +2,5 @@ export enum CATEGORY {
test
=
'test_category'
,
test2
=
'test2_category'
,
}
export
const
MASTER_TEST
=
'test_admin'
...
...
Please
register
or
login
to post a comment