Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
hw92
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
5
Issues
5
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Болатов Ален
hw92
Commits
7b0a9395
Commit
7b0a9395
authored
Apr 04, 2023
by
Рахметова Альбина
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into '
#28
'
# Conflicts: # frontend/src/store/store.ts
parents
59860c5e
93956466
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
135 additions
and
36 deletions
+135
-36
comments.ts
backend/src/controllers/comments.ts
+0
-1
IComment.ts
backend/src/interfaces/IComment.ts
+2
-2
ICommentDto.ts
backend/src/interfaces/ICommentDto.ts
+2
-0
mongoose.ts
backend/src/repository/mongoose.ts
+3
-2
Comment.css
frontend/src/components/Comment/Comment.css
+9
-0
Comment.tsx
frontend/src/components/Comment/Comment.tsx
+27
-0
ICommentProps.ts
frontend/src/components/Comment/ICommentProps.ts
+6
-0
DetailsPost.css
frontend/src/containers/DetailsPost/DetailsPost.css
+0
-0
DetailsPost.tsx
frontend/src/containers/DetailsPost/DetailsPost.tsx
+39
-0
IComment.ts
frontend/src/interfaces/IComment.ts
+2
-2
comments.slice.ts
frontend/src/store/comments/comments.slice.ts
+37
-29
store.ts
frontend/src/store/store.ts
+8
-0
No files found.
backend/src/controllers/comments.ts
View file @
7b0a9395
...
...
@@ -30,7 +30,6 @@ export class CommentController {
}
private
addComment
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
>
=>
{
const
response
=
await
this
.
service
.
addComment
(
req
.
body
)
res
.
send
(
response
)
}
...
...
backend/src/interfaces/IComment.ts
View file @
7b0a9395
...
...
@@ -4,8 +4,8 @@ import IPost from "./IPost";
export
default
interface
IComment
extends
Document
{
_id
:
ObjectId
user
:
IUser
post
:
IPost
user
:
string
post
:
string
comment
:
string
datetime
:
Date
}
\ No newline at end of file
backend/src/interfaces/ICommentDto.ts
View file @
7b0a9395
...
...
@@ -2,4 +2,6 @@ import IComment from "./IComment"
export
default
interface
ICommentDto
{
comment
:
IComment
[
'comment'
]
post
:
string
user
:
string
}
\ No newline at end of file
backend/src/repository/mongoose.ts
View file @
7b0a9395
...
...
@@ -9,6 +9,7 @@ import IComment from '../interfaces/IComment';
import
ICommentDto
from
'../interfaces/ICommentDto'
;
import
{
Comment
}
from
'../models/Comments'
;
import
IUser
from
'../interfaces/IUser'
;
import
UserModel
from
'../models/User'
;
export
class
Mongo
implements
IDataBase
{
[
x
:
string
]:
any
;
...
...
@@ -26,7 +27,7 @@ export class Mongo implements IDataBase {
public
getPosts
=
async
():
Promise
<
IResponse
<
IPost
[]
|
undefined
>>
=>
{
try
{
const
data
=
await
Post
.
find
()
.
sort
({
datetime
:
-
1
})
const
data
=
await
Post
.
find
()
const
response
:
IResponse
<
IPost
[]
>
=
{
status
:
EStatuses
.
OK
,
result
:
data
as
any
,
...
...
@@ -141,7 +142,7 @@ export class Mongo implements IDataBase {
}
public
getCommentById
=
async
(
id
:
string
):
Promise
<
IResponse
<
IComment
|
undefined
>>
=>
{
try
{
const
data
=
await
Comment
.
findById
(
id
).
populate
(
'user'
).
populate
(
'post'
)
.
sort
({
datetime
:
-
1
})
const
data
=
await
Comment
.
findById
(
id
).
populate
(
'user'
).
populate
(
'post'
)
;
const
response
:
IResponse
<
IComment
>
=
{
status
:
EStatuses
.
OK
,
result
:
data
as
any
,
...
...
frontend/src/components/Comment/Comment.css
0 → 100644
View file @
7b0a9395
.comment_block
{
border
:
2px
solid
black
;
padding
:
10px
10px
;
margin-bottom
:
30px
;
}
.comment_btn
{
margin-left
:
500px
;
}
\ No newline at end of file
frontend/src/components/Comment/Comment.tsx
0 → 100644
View file @
7b0a9395
import
ICommentProps
from
"./ICommentProps"
;
import
React
,
{
FunctionComponent
,
ReactElement
}
from
"react"
;
import
{
AppDispatch
}
from
"../../store/store"
;
import
{
useDispatch
}
from
"react-redux"
;
import
'./Comment.css'
import
{
deleteCommentById
,
getCommentsByPost
}
from
"../../store/comments/comments.slice"
;
const
Comment
:
FunctionComponent
<
ICommentProps
>
=
(
props
):
ReactElement
=>
{
const
dispatch
:
AppDispatch
=
useDispatch
()
const
deleteComment
=
()
=>
{
try
{
dispatch
(
deleteCommentById
(
props
.
comments
.
_id
))
}
finally
{
dispatch
(
getCommentsByPost
(
props
.
params_id
))
}
}
return
(
<
div
className=
"comment_block"
>
<
span
>
{
props
.
comments
.
user
}
wrote:
{
props
.
comments
.
comment
}
</
span
>
<
button
className=
"comment_btn"
onClick=
{
deleteComment
}
>
Delete
</
button
>
</
div
>
)
}
export
default
Comment
\ No newline at end of file
frontend/src/components/Comment/ICommentProps.ts
0 → 100644
View file @
7b0a9395
import
IComment
from
"../../interfaces/IComment"
;
export
default
interface
ICommentProps
{
comments
:
IComment
params_id
:
any
}
\ No newline at end of file
frontend/src/containers/DetailsPost/DetailsPost.css
0 → 100644
View file @
7b0a9395
frontend/src/containers/DetailsPost/DetailsPost.tsx
0 → 100644
View file @
7b0a9395
import
React
,
{
ChangeEvent
,
FunctionComponent
,
ReactElement
,
useEffect
,
useState
}
from
"react"
;
import
{
useDispatch
}
from
"react-redux"
;
import
{
useParams
}
from
"react-router-dom"
;
import
{
getPostById
}
from
"../../store/posts/posts.slice"
;
import
{
useSelector
}
from
"react-redux"
;
import
{
RootState
}
from
"../../store/store"
;
import
{
getCommentsByPost
}
from
"../../store/comments/comments.slice"
;
import
Comment
from
"../../components/Comment/Comment"
;
const
Details
:
FunctionComponent
=
():
ReactElement
=>
{
const
params
:
any
=
useParams
();
const
dispatch
=
useDispatch
();
const
{
comments
}
=
useSelector
((
state
:
RootState
)
=>
state
.
comments
)
useEffect
(()
=>
{
dispatch
(
getPostById
(
params
.
id
))
},
[
params
])
useEffect
(()
=>
{
//@ts-ignore
dispatch
(
getCommentsByPost
(
params
.
id
))
},
[
params
.
id
])
return
(
<
div
className=
"details"
>
<
div
className=
"container"
>
{
comments
?
<
h1
>
Comments
</
h1
>
:
''
}
{
comments
.
map
(
c
=>
{
return
<
Comment
params_id=
{
params
.
id
}
comments=
{
c
}
/>
})
}
</
div
>
</
div
>
)
}
export
default
Details
\ No newline at end of file
frontend/src/interfaces/IComment.ts
View file @
7b0a9395
...
...
@@ -3,8 +3,8 @@ import IUser from "./IUser"
export
default
interface
IComment
{
_id
:
string
user
:
IUser
post
:
IPost
user
:
string
post
:
string
comment
:
string
datetime
:
Date
}
\ No newline at end of file
frontend/src/store/comments/comments.slice.ts
View file @
7b0a9395
import
{
createSlice
}
from
'@reduxjs/toolkit'
import
{
createAppAsyncThunk
}
from
'../createAppAsyncThunk'
import
{
createAsyncThunk
,
createSlice
}
from
'@reduxjs/toolkit'
import
IResponse
from
'../../interfaces/IResponse'
import
IComment
from
'../../interfaces/IComment'
import
ICommentState
from
'./ICommentState'
import
{
commentsApi
}
from
'../../api/commentApi'
import
ICommentDto
from
'../../interfaces/ICommentDto'
interface
CommentState
{
comments
:
IComment
[];
loading
:
boolean
;
}
const
namespace
=
'comments'
const
initialState
:
CommentState
=
{
comments
:
[]
as
IComment
[],
loading
:
false
};
export
const
getCommentsByPost
=
createA
ppA
syncThunk
(
`
${
namespace
}
/getCommentsByPost`
,
export
const
getCommentsByPost
=
createAsyncThunk
(
'getCommentsByPost'
,
async
(
postId
:
string
):
Promise
<
IResponse
<
IComment
[]
|
undefined
>>
=>
{
return
commentsApi
.
getCommentsByPost
(
postId
)
}
)
export
const
createComment
=
createA
ppA
syncThunk
(
`
${
namespace
}
/createComment`
,
export
const
createComment
=
createAsyncThunk
(
'createComment'
,
async
(
comment
:
ICommentDto
)
=>
{
return
commentsApi
.
createComment
(
comment
)
}
)
export
const
deleteCommentById
=
createA
ppA
syncThunk
(
`
${
namespace
}
/deleteCommentById`
,
export
const
deleteCommentById
=
createAsyncThunk
(
'deleteCommentById'
,
async
(
id
:
string
)
=>
{
return
commentsApi
.
deleteCommentById
(
id
)
}
)
export
const
commentsSlice
=
createSlice
({
name
:
namespace
,
initialState
:
{
comments
:
[]
as
IComment
[],
loadingComments
:
false
,
messageComments
:
''
}
as
ICommentState
,
reducers
:
{},
name
:
'comment'
,
initialState
,
reducers
:
{
setInitialComment
:
(
state
)
=>
{
state
.
comments
=
[];
state
.
loading
=
false
}
},
extraReducers
:
(
builder
)
=>
{
builder
.
addCase
(
getCommentsByPost
.
rejected
,
(
state
)
=>
{
state
.
loading
Comments
=
false
state
.
loading
=
false
})
.
addCase
(
getCommentsByPost
.
pending
,
(
state
)
=>
{
state
.
loading
Comments
=
true
state
.
loading
=
true
})
.
addCase
(
getCommentsByPost
.
fulfilled
,
(
state
,
action
)
=>
{
state
.
loading
Comments
=
false
state
.
loading
=
false
state
.
comments
=
action
.
payload
.
result
as
IComment
[]
state
.
messageComments
=
action
.
payload
.
message
})
.
addCase
(
createComment
.
rejected
,
(
state
)
=>
{
state
.
loading
Comments
=
false
state
.
loading
=
false
})
.
addCase
(
createComment
.
pending
,
(
state
)
=>
{
state
.
loading
Comments
=
true
state
.
loading
=
true
})
.
addCase
(
createComment
.
fulfilled
,
(
state
,
action
)
=>
{
state
.
loadingComments
=
false
state
.
messageComments
=
action
.
payload
.
message
state
.
loading
=
false
})
.
addCase
(
deleteCommentById
.
rejected
,
(
state
)
=>
{
state
.
loading
Comments
=
false
state
.
loading
=
false
})
.
addCase
(
deleteCommentById
.
pending
,
(
state
)
=>
{
state
.
loading
Comments
=
true
state
.
loading
=
true
})
.
addCase
(
deleteCommentById
.
fulfilled
,
(
state
,
action
)
=>
{
state
.
loadingComments
=
false
state
.
messageComments
=
action
.
payload
.
message
state
.
loading
=
false
})
}
})
\ No newline at end of file
})
export
const
{
setInitialComment
}
=
commentsSlice
.
actions
export
default
commentsSlice
.
reducer
\ No newline at end of file
frontend/src/store/store.ts
View file @
7b0a9395
import
{
configureStore
}
from
'@reduxjs/toolkit'
;
import
userSlice
from
'./users/users.slice'
;
<<<<<<<
frontend
/
src
/
store
/
store
.
ts
import
{
postsSlice
}
from
'./posts/posts.slice'
;
=======
import
commentsSlice
from
'./comments/comments.slice'
;
>>>>>>>
frontend
/
src
/
store
/
store
.
ts
export
const
store
=
configureStore
({
reducer
:
{
user
:
userSlice
,
<<<<<<<
frontend
/
src
/
store
/
store
.
ts
posts
:
postsSlice
.
reducer
,
=======
comments
:
commentsSlice
>>>>>>>
frontend
/
src
/
store
/
store
.
ts
},
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment