Skip to content

Commit

Permalink
Merge pull request #565 from bounswe/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mmtftr authored Nov 24, 2024
2 parents 7227ea9 + 8f28da4 commit fcb6698
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ public CreateAnswerResponseDto updateAnswer(Long answerId, CreateAnswerRequestDt
.build();
}

public GetAnswersResponseDto getAnswersForQuestion(Long questionId) throws UnauthorizedAccessException {
public GetAnswersResponseDto getAnswersForQuestion(Long questionId) {
Question question = questionService.findById(questionId).orElseThrow();
User currentUser = userContextService.getCurrentUser();
final User currentUser = getCurrentUserOrNull();

return GetAnswersResponseDto.builder()
.items(question.getAnswers().stream().map(answer -> GetAnswersResponseDto.AnswerResponseDto.builder()
.id(answer.getId())
Expand All @@ -90,9 +91,17 @@ public GetAnswersResponseDto getAnswersForQuestion(Long questionId) throws Unaut
.updatedAt(answer.getUpdatedAt())
.upvoteCount(answer.getUpvoteCount())
.downvoteCount(answer.getDownvoteCount())
.selfAnswer(currentUser!=null && currentUser.getId().equals(answer.getAnsweredBy().getId()))
.selfAnswer(currentUser != null && currentUser.getId().equals(answer.getAnsweredBy().getId()))
.build()).toList())
.totalItems(question.getAnswers().size())
.build();
}

private User getCurrentUserOrNull() {
try {
return userContextService.getCurrentUser();
} catch (UnauthorizedAccessException e) {
return null;
}
}
}
2 changes: 1 addition & 1 deletion frontend/src/services/exercism.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as reactQuery from "@tanstack/react-query";
const SERVER_URL = "http://64.226.72.194:8000";
const SERVER_URL = "https://exercism.mmtf.workers.dev";

interface SearchResult {
slug: string;
Expand Down

0 comments on commit fcb6698

Please sign in to comment.