Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
Daily Thought App
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COM3014-Coursework
Daily Thought App
Commits
6c89a09c
Commit
6c89a09c
authored
2 years ago
by
Talty-Kerr, Patrick (UG - Comp Sci & Elec Eng)
Browse files
Options
Downloads
Patches
Plain Diff
all response done for get request apart from 403
parent
6d05e389
No related branches found
No related tags found
1 merge request
!13
Create Comment service requirements
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
comment-service/src/controllers/Comment.ts
+19
-5
19 additions, 5 deletions
comment-service/src/controllers/Comment.ts
comment-service/src/routes/Comment.ts
+1
-1
1 addition, 1 deletion
comment-service/src/routes/Comment.ts
comment-service/src/server.ts
+1
-0
1 addition, 0 deletions
comment-service/src/server.ts
with
21 additions
and
6 deletions
comment-service/src/controllers/Comment.ts
+
19
−
5
View file @
6c89a09c
...
@@ -73,7 +73,7 @@ const createComment = async ( req: Request, res: Response, next: NextFunction,)
...
@@ -73,7 +73,7 @@ const createComment = async ( req: Request, res: Response, next: NextFunction,)
return
res
.
status
(
201
).
json
({
comment_1
});
return
res
.
status
(
201
).
json
({
comment_1
});
}
}
else
{
else
{
return
res
.
status
(
401
).
send
({
message
:
'
Unauthori
z
ed
'
});
return
res
.
status
(
401
).
send
({
message
:
'
Unauthori
s
ed
'
});
}
}
...
@@ -90,10 +90,27 @@ const readAllComments = async (req: Request, res: Response, next: NextFunction)
...
@@ -90,10 +90,27 @@ const readAllComments = async (req: Request, res: Response, next: NextFunction)
//401
//401
//403
//403
const
id
=
req
.
params
.
post_id
;
const
id
=
req
.
params
.
post_id
;
if
(
id
==
null
||
id
===
'
undefined
'
)
{
return
res
.
status
(
400
).
send
({
message
:
'
Bad Request
'
});
}
const
token
=
req
.
headers
.
authorization
?.
split
(
'
'
)[
1
];
if
(
!
token
)
{
return
res
.
status
(
401
).
send
({
message
:
'
Unauthorised
'
});
}
try
{
try
{
const
decodedToken
=
jwt
.
verify
(
token
,
config
.
server
.
token
.
secret
);
}
catch
{
return
res
.
status
(
401
).
send
({
message
:
'
Unauthorised
'
});
}
try
{
const
posts
=
{
post_id
:
new
mongoose
.
Types
.
ObjectId
(
id
)}
const
posts
=
{
post_id
:
new
mongoose
.
Types
.
ObjectId
(
id
)}
const
post_exist
=
await
Comment
.
countDocuments
(
posts
,
{
limit
:
1
})
const
post_exist
=
await
Comment
.
countDocuments
(
posts
,
{
limit
:
1
})
if
(
post_exist
==
0
)
{
if
(
post_exist
==
0
)
{
...
@@ -107,16 +124,13 @@ const readAllComments = async (req: Request, res: Response, next: NextFunction)
...
@@ -107,16 +124,13 @@ const readAllComments = async (req: Request, res: Response, next: NextFunction)
try
{
try
{
const
query
=
{
post_id
:
new
mongoose
.
Types
.
ObjectId
(
id
)}
const
query
=
{
post_id
:
new
mongoose
.
Types
.
ObjectId
(
id
)}
const
comments
=
await
Comment
.
find
(
query
).
limit
(
50
)
const
comments
=
await
Comment
.
find
(
query
).
limit
(
50
)
//const comments: object[] = await Comment.find({}, { _id: 1 }).toArray()
//const comments: object[] = await Comment.find({}, { _id: 1 }).toArray()
.
select
(
'
-__v
'
);
.
select
(
'
-__v
'
);
return
res
.
status
(
200
).
json
({
comments
});
return
res
.
status
(
200
).
json
({
comments
});
}
catch
(
error
)
{
}
catch
(
error
)
{
return
res
.
status
(
500
).
json
({
error
});
return
res
.
status
(
500
).
send
({
message
:
'
Internal server
error
s
'
});
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
comment-service/src/routes/Comment.ts
+
1
−
1
View file @
6c89a09c
...
@@ -5,6 +5,6 @@ const router = express.Router();
...
@@ -5,6 +5,6 @@ const router = express.Router();
router
.
post
(
'
/create
'
,
controller
.
createComment
);
router
.
post
(
'
/create
'
,
controller
.
createComment
);
router
.
get
(
'
/:post_id
'
,
controller
.
readAllComments
);
router
.
get
(
'
/:post_id
'
,
controller
.
readAllComments
);
router
.
get
(
'
/
'
,
controller
.
readAllComments
);
export
=
router
;
export
=
router
;
This diff is collapsed.
Click to expand it.
comment-service/src/server.ts
+
1
−
0
View file @
6c89a09c
...
@@ -65,6 +65,7 @@ const StartServer = () => {
...
@@ -65,6 +65,7 @@ const StartServer = () => {
message
:
error
.
message
message
:
error
.
message
});
});
});
});
http
.
createServer
(
router
).
listen
(
config
.
server
.
port
,
()
=>
Logging
.
info
(
`Server is running on port
${
config
.
server
.
port
}
`
));
http
.
createServer
(
router
).
listen
(
config
.
server
.
port
,
()
=>
Logging
.
info
(
`Server is running on port
${
config
.
server
.
port
}
`
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment