Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

평균 별점 통일 #125 #128

Merged
merged 4 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/java/io/oduck/api/domain/anime/dto/AnimeRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ public StarRatingAvg(Long starRatingScoreTotal, Long starRatingCount) {
}

private double calculateAvg(Long starRatingScoreTotal, Long starRatingCount) {
if(starRatingCount <= 0) {
return 0;

if (starRatingCount <= 0) {
return 0.0;
}
return starRatingScoreTotal / starRatingCount;

return Double.valueOf(starRatingScoreTotal) / starRatingCount;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface AnimeRepository extends JpaRepository<Anime,Long>, AnimeReposit

@Query("select a from Anime a where a.id = :id and a.deletedAt is null")
@Lock(LockModeType.PESSIMISTIC_WRITE)
@QueryHints({@QueryHint(name = "javax.persistence.lock.timeout", value ="3000")})
@QueryHints({@QueryHint(name = "jakarta.persistence.lock.timeout", value ="3000")})
Optional<Anime> findByIdForUpdate(@Param("id")Long id);

@Query("select a from Anime a where a.id = :id and a.deletedAt = null and a.isReleased = :isReleased")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class BookmarkRes implements EntityBased {
private Long animeId;
private String title;
private String thumbnail;
private double avgScore;
private Double avgScore;
private Integer myScore;
private LocalDateTime createdAt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.oduck.api.global.utils.HttpHeaderUtils.getClientIP;

import io.oduck.api.global.security.auth.dto.AuthUser;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -56,11 +57,11 @@ protected void doFilterWrapped(ContentCachingRequestWrapper request,

private static void logRequest(ContentCachingRequestWrapper request) throws IOException {
String queryString = request.getQueryString();
log.info("Request : \n {} {} uri=[{}]\n content-type[{}]\n client-ip[{}]\n user-agent[{}]",
log.info("Request : \n {} {} uri=[{}]\n content-type[{}]\n client-ip[{}]\n user-id[{}]\n user-agent[{}]",
request.getProtocol(),
request.getMethod(),
queryString == null ? request.getRequestURI() : request.getRequestURI() + "?" + queryString,
request.getContentType(), getClientIP(request), request.getHeader("User-Agent"));
request.getContentType(), getClientIP(request), getAuthUserId(request), request.getHeader("User-Agent"));
logPayload("Request", request.getContentType(), request.getContentAsByteArray());
}

Expand Down Expand Up @@ -97,4 +98,9 @@ private static boolean isVisible(MediaType mediaType) {
return VISIBLE_TYPES.stream()
.anyMatch(visibleType -> visibleType.includes(mediaType));
}

private static Long getAuthUserId(HttpServletRequest request) {
AuthUser user = (AuthUser) request.getSession() .getAttribute("user");
return user == null ? null : user.getId();
}
}