Skip to content

Commit

Permalink
Merge pull request #74 from dongkyun0713/dongkyun
Browse files Browse the repository at this point in the history
ν”„λ‘œν•„ μˆ˜μ •
  • Loading branch information
dongkyun0713 authored Feb 20, 2024
2 parents 91c8a03 + bf4b653 commit 9b3d6c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class MatchingPostResponseDto {

private Long matchingPostId;
private String authorNickName;
private String profile;
private String category;
private String status;
private String title;
Expand All @@ -24,12 +25,13 @@ public class MatchingPostResponseDto {
private Integer reviewCount;
private LocalDateTime updateDate;

public static MatchingPostResponseDto of(
public static MatchingPostResponseDto of(
MatchingPost matchingPost,
Integer reviewCount) {
return new MatchingPostResponseDto(
matchingPost.getMatchingPostId(),
matchingPost.getUser().getNickname(),
matchingPost.getUser().getProfile(),
String.valueOf(matchingPost.getCategory()),
String.valueOf(matchingPost.getStatus()),
matchingPost.getTitle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.security.Principal;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.AuthorizationServiceException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.security.Principal;

@Service
@RequiredArgsConstructor
public class MatchingPostService {
Expand All @@ -32,7 +31,8 @@ public class MatchingPostService {

//κ²Œμ‹œλ¬Ό μž‘μ„±
@Transactional
public MatchingPostCreateResponseDto createMatchingPost(Principal principal, MatchingPostCreateRequestDto matchingPostCreateRequestDto) {
public MatchingPostCreateResponseDto createMatchingPost(Principal principal,
MatchingPostCreateRequestDto matchingPostCreateRequestDto) {
String userEmail = principal.getName();
User user = userRepository.findByEmail(userEmail).orElseThrow(
() -> new IllegalArgumentException("μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” μ‚¬μš©μžμž…λ‹ˆλ‹€"));
Expand All @@ -42,8 +42,10 @@ public MatchingPostCreateResponseDto createMatchingPost(Principal principal, Mat

return MatchingPostCreateResponseDto.of(matchingPost);
}

// κ²Œμ‹œλ¬Ό 쑰회
public MatchingPostResponseDto getMatchingPostByMatchingPostId(Long matchingPostId, HttpServletRequest request, HttpServletResponse response) {
public MatchingPostResponseDto getMatchingPostByMatchingPostId(Long matchingPostId, HttpServletRequest request,
HttpServletResponse response) {
MatchingPost matchingPost = matchingPostRepository.findById(matchingPostId).orElseThrow(
() -> new IllegalArgumentException("μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” κ²Œμ‹œλ¬Όμž…λ‹ˆλ‹€"));

Expand All @@ -54,6 +56,7 @@ public MatchingPostResponseDto getMatchingPostByMatchingPostId(Long matchingPost

return MatchingPostResponseDto.of(matchingPost, reviewCount);
}

// κ²Œμ‹œλ¬Ό μ‚­μ œ
@Transactional
public MatchingPostDeleteResponseDto deleteMatchingPostByMatchingPostId(Long matchingPostId) {
Expand All @@ -63,9 +66,11 @@ public MatchingPostDeleteResponseDto deleteMatchingPostByMatchingPostId(Long mat

return MatchingPostDeleteResponseDto.of(matchingPostId);
}

// κ²Œμ‹œλ¬Ό μˆ˜μ •
@Transactional
public MatchingPostUpdateResponseDto updateMatchingPost(Long matchingPostId, Principal principal, MatchingPostUpdateRequestDto matchingPostUpdateRequestDto) {
public MatchingPostUpdateResponseDto updateMatchingPost(Long matchingPostId, Principal principal,
MatchingPostUpdateRequestDto matchingPostUpdateRequestDto) {
MatchingPost matchingPost = matchingPostRepository.findById(matchingPostId).orElseThrow(
() -> new IllegalArgumentException("μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” κ²Œμ‹œλ¬Όμž…λ‹ˆλ‹€"));

Expand All @@ -87,12 +92,11 @@ public MatchingPostUpdateResponseDto updateMatchingPost(Long matchingPostId, Pri
return MatchingPostUpdateResponseDto.of(
matchingPost,
reviewCount);
} else {
throw new AuthorizationServiceException("잘λͺ»λœ μ ‘κ·Όμž…λ‹ˆλ‹€");
}
else throw new AuthorizationServiceException("잘λͺ»λœ μ ‘κ·Όμž…λ‹ˆλ‹€");
}



// κ²Œμ‹œκΈ€ 쑰회수 μ—°μ‚°
private void countViews(MatchingPost matchingPost, HttpServletRequest request, HttpServletResponse response) {
Cookie cookie = null;
Expand Down Expand Up @@ -124,6 +128,7 @@ private void countViews(MatchingPost matchingPost, HttpServletRequest request, H
matchingPostRepository.save(matchingPost); // κ²Œμ‹œλ¬Όμ„ μ €μž₯ν•˜μ—¬ 쑰회수λ₯Ό μ—…λ°μ΄νŠΈν•©λ‹ˆλ‹€.
}
}

// μΏ ν‚€ μ„€μ •
private Cookie setCookieValue(Cookie cookie) {
cookie.setPath("/");
Expand Down

0 comments on commit 9b3d6c6

Please sign in to comment.