Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SicDoRak
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
2023_2_WebPromgramming_8
SicDoRak
Commits
47c2a6cd
Commit
47c2a6cd
authored
1 year ago
by
Hyun Woo Jeong
Browse files
Options
Downloads
Plain Diff
see posts in main page
parents
632e102b
7db5ba67
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
backend/src/data/articleService.js
+64
-0
64 additions, 0 deletions
backend/src/data/articleService.js
backend/src/data/userService.js
+18
-0
18 additions, 0 deletions
backend/src/data/userService.js
backend/src/index.js
+1
-1
1 addition, 1 deletion
backend/src/index.js
with
83 additions
and
1 deletion
backend/src/data/articleService.js
+
64
−
0
View file @
47c2a6cd
...
@@ -13,7 +13,71 @@ const articleService = {
...
@@ -13,7 +13,71 @@ const articleService = {
async
findArticleById
(
articleId
)
{
async
findArticleById
(
articleId
)
{
try
{
try
{
const
article
=
await
Article
.
findById
(
articleId
)
.
populate
(
'
author
'
)
.
populate
(
'
comments.author
'
)
.
populate
(
'
likes
'
);
return
article
;
}
catch
(
err
)
{
throw
err
;
}
},
async
findArticlesByAuthor
(
authorId
)
{
try
{
const
articles
=
await
Article
.
find
({
author
:
authorId
})
.
populate
(
'
author
'
)
.
populate
(
'
likes
'
);
return
articles
;
}
catch
(
err
)
{
throw
err
;
}
},
async
deleteArticle
(
articleId
)
{
try
{
const
article
=
await
Article
.
findByIdAndDelete
(
articleId
);
return
article
;
}
catch
(
err
)
{
throw
err
;
}
},
async
createComment
(
articleId
,
commentData
)
{
try
{
const
article
=
await
Article
.
findById
(
articleId
);
article
.
comments
.
push
(
commentData
);
await
article
.
save
();
return
article
;
}
catch
(
err
)
{
throw
err
;
}
},
async
deleteComment
(
articleId
,
commentId
)
{
try
{
const
article
=
await
Article
.
findById
(
articleId
);
article
.
comments
.
pull
({
_id
:
commentId
});
await
article
.
save
();
return
article
;
}
catch
(
err
)
{
throw
err
;
}
},
async
setLike
(
articleId
,
userId
)
{
try
{
const
article
=
await
Article
.
findById
(
articleId
);
if
(
article
.
likes
.
includes
(
userId
))
{
article
.
likes
.
pull
({
_id
:
userId
});
}
else
{
article
.
likes
.
push
(
userId
);
}
await
article
.
save
();
return
article
;
}
catch
(
err
)
{
}
catch
(
err
)
{
throw
err
;
throw
err
;
}
}
...
...
This diff is collapsed.
Click to expand it.
backend/src/data/userService.js
+
18
−
0
View file @
47c2a6cd
...
@@ -11,6 +11,15 @@ const userService = {
...
@@ -11,6 +11,15 @@ const userService = {
}
}
},
},
async
findUserById
(
userId
)
{
try
{
const
user
=
await
User
.
findById
(
userId
);
return
user
;
}
catch
(
err
)
{
throw
err
;
}
},
async
findUserByEmail
(
email
)
{
async
findUserByEmail
(
email
)
{
try
{
try
{
const
user
=
await
User
.
findOne
({
email
});
const
user
=
await
User
.
findOne
({
email
});
...
@@ -19,6 +28,15 @@ const userService = {
...
@@ -19,6 +28,15 @@ const userService = {
throw
err
;
throw
err
;
}
}
},
},
async
existsByEmail
(
email
)
{
try
{
const
user
=
await
User
.
exists
({
email
});
return
user
!==
null
;
}
catch
(
err
)
{
throw
err
;
}
}
};
};
export
default
userService
;
export
default
userService
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
backend/src/index.js
+
1
−
1
View file @
47c2a6cd
...
@@ -53,7 +53,7 @@ app.post('/login', async (req, res) => {
...
@@ -53,7 +53,7 @@ app.post('/login', async (req, res) => {
const
expires
=
moment
().
add
(
sessionTime
.
toString
(),
'
m
'
).
toDate
();
const
expires
=
moment
().
add
(
sessionTime
.
toString
(),
'
m
'
).
toDate
();
// 정보가 없다면 회원 가입 (강제?)
// 정보가 없다면 회원 가입 (강제?)
const
user
=
await
userService
.
findUser
ByEmail
(
req
.
body
.
email
);
const
user
=
await
userService
.
exists
ByEmail
(
req
.
body
.
email
);
if
(
!
user
)
{
// 유저가 없다면 회원 가입 후 세션 생성
if
(
!
user
)
{
// 유저가 없다면 회원 가입 후 세션 생성
let
userProfilePicture
=
req
.
body
.
picture
||
null
;
let
userProfilePicture
=
req
.
body
.
picture
||
null
;
await
userService
.
createUser
({
await
userService
.
createUser
({
...
...
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