Skip to content

Commit

Permalink
fix: Detail Question
Browse files Browse the repository at this point in the history
  • Loading branch information
dd-jiyun committed Mar 4, 2024
1 parent 140ea03 commit ec0989b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ public ResponseEntity<Page<QuestionDTO.Response>> getAllQuestions(@RequestParam(
public ResponseEntity<QuestionDTO.Response> getQuestionById(@PathVariable("postId") Long postId,
HttpServletRequest request,
HttpServletResponse response) {
try {
QuestionDTO.Response question = questionService.findById(postId, request, response);
return ResponseEntity.ok(question);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}
QuestionDTO.Response question = questionService.findById(postId, request, response);
return ResponseEntity.ok(question);
}

@GetMapping("/category/{category}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -150,30 +149,30 @@ private void validateAuthorIsLoggedInUser(Long id, User user) {
// 쑰회수 증가
private void validViewCount(Question question, HttpServletRequest request, HttpServletResponse response) {
Cookie[] cookies = request.getCookies();
System.out.println("cookies = " + Arrays.toString(cookies));
Cookie cookie = null;
boolean isCookie = false;
for (Cookie value : cookies) {
if (value.getName().equals("viewCookie")) {
cookie = value;
if (!cookie.getValue().contains("[" + question.getId() + "]")) {
question.addViewCount();
cookie.setValue(cookie.getValue() + "[" + question.getId() + "]");
if (cookies != null) {
for (Cookie value : cookies) {
if (value.getName().equals("viewCookie")) {
cookie = value;
if (!cookie.getValue().contains("[" + question.getId() + "]")) {
question.addViewCount();
cookie.setValue(cookie.getValue() + "[" + question.getId() + "]");
}
isCookie = true;
break;
}
isCookie = true;
break;
}
System.out.println("isCookie = " + isCookie);
if (!isCookie) {
question.addViewCount();
cookie = new Cookie("viewCookie", "[" + question.getId() + "]");
}
long todayEndSecond = LocalDate.now().atTime(LocalTime.MAX).toEpochSecond(ZoneOffset.UTC);
long currentSecond = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
cookie.setPath("/");
cookie.setMaxAge((int) (todayEndSecond - currentSecond));
response.addCookie(cookie);
}
System.out.println("isCookie = " + isCookie);
if (!isCookie) {
question.addViewCount();
cookie = new Cookie("viewCookie", "[" + question.getId() + "]");
}
long todayEndSecond = LocalDate.now().atTime(LocalTime.MAX).toEpochSecond(ZoneOffset.UTC);
long currentSecond = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
cookie.setPath("/");
cookie.setMaxAge((int) (todayEndSecond - currentSecond));
response.addCookie(cookie);
}

}

0 comments on commit ec0989b

Please sign in to comment.