Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
backend
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
umc team 1
backend
Commits
1daa72dd
Commit
1daa72dd
authored
1 year ago
by
Gwan Ju
Browse files
Options
Downloads
Patches
Plain Diff
refactor: Updated code in PostServiceImpl.java
parent
d80f1f39
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/umc/spring/post/service/PostServiceImpl.java
+13
-5
13 additions, 5 deletions
src/main/java/umc/spring/post/service/PostServiceImpl.java
with
13 additions
and
5 deletions
src/main/java/umc/spring/post/service/PostServiceImpl.java
+
13
−
5
View file @
1daa72dd
...
@@ -3,10 +3,15 @@ package umc.spring.post.service;
...
@@ -3,10 +3,15 @@ package umc.spring.post.service;
import
jakarta.servlet.http.HttpServletResponse
;
import
jakarta.servlet.http.HttpServletResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.userdetails.UsernameNotFoundException
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
umc.spring.post.config.security.SecurityUtil
;
import
umc.spring.post.data.dto.CommentDto
;
import
umc.spring.post.data.dto.CommentDto
;
import
umc.spring.post.data.dto.PostDto
;
import
umc.spring.post.data.dto.PostDto
;
import
umc.spring.post.data.dto.PostResDto
;
import
umc.spring.post.data.dto.PostResDto
;
import
umc.spring.post.data.dto.UserInfoDto
;
import
umc.spring.post.data.entity.Comment
;
import
umc.spring.post.data.entity.Comment
;
import
umc.spring.post.data.entity.Post
;
import
umc.spring.post.data.entity.Post
;
import
umc.spring.post.repository.CommentRepository
;
import
umc.spring.post.repository.CommentRepository
;
...
@@ -32,6 +37,8 @@ public class PostServiceImpl implements PostService{
...
@@ -32,6 +37,8 @@ public class PostServiceImpl implements PostService{
@Override
@Override
public
void
upload
(
PostDto
postDto
){
public
void
upload
(
PostDto
postDto
){
UserInfoDto
userInfoDto
=
SecurityUtil
.
getCurrentMemberId
();
Post
post
=
new
Post
();
Post
post
=
new
Post
();
setPost
(
postDto
,
post
);
setPost
(
postDto
,
post
);
post
.
setUserId
(
postDto
.
getUserId
());
post
.
setUserId
(
postDto
.
getUserId
());
...
@@ -54,13 +61,13 @@ public class PostServiceImpl implements PostService{
...
@@ -54,13 +61,13 @@ public class PostServiceImpl implements PostService{
@Override
@Override
public
PostResDto
getPostById
(
Long
id
){
public
PostResDto
getPostById
(
Long
id
){
Post
post
=
postRepository
.
findById
(
id
).
get
()
;
Post
post
=
postRepository
.
findById
(
id
).
orElseThrow
(()
->
new
RuntimeException
(
"id가 존재하지 않습니다."
));
;
return
PostResDto
.
toDTO
(
post
);
return
PostResDto
.
toDTO
(
post
);
}
}
@Override
@Override
public
void
likeCrew
(
Long
id
)
{
public
void
likeCrew
(
Long
id
)
{
Post
post
=
postRepository
.
findById
(
id
).
get
(
);
Post
post
=
postRepository
.
findById
(
id
).
orElseThrow
(()
->
new
RuntimeException
(
"id가 존재하지 않습니다."
)
);
int
likeCount
=
post
.
getLikeCount
();
int
likeCount
=
post
.
getLikeCount
();
post
.
setLikeCount
(++
likeCount
);
post
.
setLikeCount
(++
likeCount
);
postRepository
.
save
(
post
);
postRepository
.
save
(
post
);
...
@@ -68,7 +75,7 @@ public class PostServiceImpl implements PostService{
...
@@ -68,7 +75,7 @@ public class PostServiceImpl implements PostService{
@Override
@Override
public
void
dislikeCrew
(
Long
id
)
{
public
void
dislikeCrew
(
Long
id
)
{
Post
post
=
postRepository
.
findById
(
id
).
get
(
);
Post
post
=
postRepository
.
findById
(
id
).
orElseThrow
(()
->
new
RuntimeException
(
"id가 존재하지 않습니다."
)
);
int
likeCount
=
post
.
getLikeCount
();
int
likeCount
=
post
.
getLikeCount
();
if
(
likeCount
!=
0
){
if
(
likeCount
!=
0
){
post
.
setLikeCount
(--
likeCount
);
post
.
setLikeCount
(--
likeCount
);
...
@@ -88,7 +95,7 @@ public class PostServiceImpl implements PostService{
...
@@ -88,7 +95,7 @@ public class PostServiceImpl implements PostService{
@Override
@Override
public
boolean
editPost
(
PostDto
postDto
,
Long
id
)
{
public
boolean
editPost
(
PostDto
postDto
,
Long
id
)
{
Post
post
=
postRepository
.
findById
(
id
).
get
()
;
Post
post
=
postRepository
.
findById
(
id
).
orElseThrow
(()
->
new
RuntimeException
(
"id가 존재하지 않습니다."
));
;
if
(
post
!=
null
){
if
(
post
!=
null
){
post
.
setTitle
(
postDto
.
getTitle
()
!=
null
?
postDto
.
getTitle
()
:
post
.
getTitle
());
post
.
setTitle
(
postDto
.
getTitle
()
!=
null
?
postDto
.
getTitle
()
:
post
.
getTitle
());
post
.
setBody
(
postDto
.
getBody
()
!=
null
?
postDto
.
getBody
()
:
post
.
getBody
());
post
.
setBody
(
postDto
.
getBody
()
!=
null
?
postDto
.
getBody
()
:
post
.
getBody
());
...
@@ -139,7 +146,8 @@ public class PostServiceImpl implements PostService{
...
@@ -139,7 +146,8 @@ public class PostServiceImpl implements PostService{
private
Comment
setComment
(
CommentDto
commentDto
)
{
private
Comment
setComment
(
CommentDto
commentDto
)
{
Comment
comment
=
new
Comment
();
Comment
comment
=
new
Comment
();
Post
post
=
postRepository
.
findById
(
commentDto
.
getPostId
()).
get
();
Post
post
=
postRepository
.
findById
(
commentDto
.
getPostId
()).
orElseThrow
(()
->
new
RuntimeException
(
"id가 존재하지 않습니다."
));
post
.
getComments
().
add
(
comment
);
post
.
getComments
().
add
(
comment
);
comment
.
setPost
(
post
);
comment
.
setPost
(
post
);
comment
.
setUserId
(
commentDto
.
getUserId
());
comment
.
setUserId
(
commentDto
.
getUserId
());
...
...
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