Skip to content
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "05. Admin")
@WebAdapter
@RestController
Expand All @@ -35,9 +33,15 @@ public class LogController {
public ResponseEntity<PageResponse<AnonymousLogResponse>> getLoginAttempts(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "20") int pageSize,
@RequestParam(defaultValue = "timestamp") String sortBy,
@RequestParam(defaultValue = "desc") String sortDirection,
@ModelAttribute FilterLogRequest anonymousLogRequest,
@AuthenticationPrincipal SecurityUserDetails userInfo) {
Pageable pageable = PageRequest.of(page, pageSize);
Pageable pageable = PageRequest.of(
page,
Comment on lines 35 to +43
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timestamp가 어디 정의되어있나요?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default value의 경우 requestAt으로 해야할 것 같습니다.
추가로 .orderBy(memberLogEntity.createdAt.desc()) 속성이 이미 설정되어있는데 pagable로 설정했을때 pagable이 적용되는지 확인해주시고 안되시면 pagable 대신 orderBy를 동적으로 적용하는 방식으로 진행하면 될 것 같습니다.

    List<MemberLogEntity> result = queryFactory
                .selectFrom(memberLogEntity)
                .where(builder)
                .leftJoin(memberLogEntity.member, memberEntity)
                .orderBy(memberLogEntity.createdAt.desc())
                .offset(pageable.getOffset())
                .limit(pageable.getPageSize())
                .fetch();
        long total = queryFactory
                .selectFrom(memberLogEntity)
                .where(builder)
                .fetch().size();
        return new PageImpl<>(result, pageable, total);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하였습니다. 확인부탁드립니다!
@parkjaehak

pageSize,
"asc".equalsIgnoreCase(sortDirection) ? Sort.by(sortBy).ascending() : Sort.by(sortBy).descending()
);
return ResponseEntity.ok(findApiLogsUsecase.filterAnonymousLogs(anonymousLogRequest, pageable));
}

Expand All @@ -47,9 +51,15 @@ public ResponseEntity<PageResponse<AnonymousLogResponse>> getLoginAttempts(
public ResponseEntity<PageResponse<MemberLogResponse>> getApiCalls(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "20") int pageSize,
@RequestParam(defaultValue = "timestamp") String sortBy,
@RequestParam(defaultValue = "desc") String sortDirection,
@ModelAttribute FilterLogRequest memberLogRequest,
@AuthenticationPrincipal SecurityUserDetails userInfo) {
Pageable pageable = PageRequest.of(page, pageSize);
Pageable pageable = PageRequest.of(
page,
pageSize,
"asc".equalsIgnoreCase(sortDirection) ? Sort.by(sortBy).ascending() : Sort.by(sortBy).descending()
);
return ResponseEntity.ok(findApiLogsUsecase.filterMemberLogs(memberLogRequest, pageable));
}
}