Skip to content

Conversation

@sunohkim
Copy link
Collaborator

@sunohkim sunohkim commented Feb 20, 2025

[BE] 수업 검색 기능 추가

#️⃣ 연관된 이슈

#187

📝 작업 내용

수업 검색 기능에서 일부 코드 리팩토링

  • keyword가 비어 있을 경우 명시적으로 처리할 수 있도록 수정

💬 리뷰 요구사항(선택)

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced the course search functionality by detecting when no search term is provided, thereby reducing unnecessary processing and improving performance.

@sunohkim sunohkim added 🔨 Refactor 코드 리팩토링 (로직 변경 없이 코드 개선) 🌱 BE 백엔드 관련 labels Feb 20, 2025
@sunohkim sunohkim requested a review from uri010 February 20, 2025 09:34
@sunohkim sunohkim self-assigned this Feb 20, 2025
@coderabbitai
Copy link

coderabbitai bot commented Feb 20, 2025

Walkthrough

The pull request updates the searchCourses method in the ProfessorCourseService class. The new implementation adds a conditional check to determine if the keyword parameter is null or empty, thereby differentiating between fetching all courses for a professor and applying a keyword filter search. The changes restructure the logic to avoid unnecessary database queries when no valid keyword is provided, without altering public API declarations.

Changes

File Change Summary
back-end/.../ProfessorCourseService.java Modified searchCourses method to include a conditional check for null or empty keywords; separates the logic for retrieving all courses versus performing a keyword-based search with an escaped keyword.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant PCService as ProfessorCourseService
    participant Database

    Client->>PCService: searchCourses(keyword)
    alt Keyword is null/empty
        PCService->>Database: Retrieve all courses for professor
    else Keyword provided
        PCService->>PCService: Escape keyword and construct search pattern
        PCService->>Database: Retrieve courses matching keyword filter
    end
    Database->>PCService: Return course list
    PCService->>Client: Return results
Loading

Possibly related PRs

Suggested labels

✨ Feat

Suggested reviewers

  • uri010

Poem

I'm a coding bunny, hopping through the code,
With a skip and a jump on this error-free road.
Checking each keyword with carrot-like care,
Ensuring smooth searches with flair to spare.
Hop along with me, as clean logic is our mode!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
back-end/reacton/src/main/java/com/softeer/reacton/domain/course/ProfessorCourseService.java (1)

108-122: Consider adding pagination for better performance.

Since the method eagerly loads schedules for all courses, it might impact performance with large datasets. Consider:

  1. Adding pagination parameters (page, size)
  2. Using Spring Data JPA's Pageable for both search cases

Example implementation:

- public List<CourseSummaryResponse> searchCourses(String oauthId, String keyword) {
+ public Page<CourseSummaryResponse> searchCourses(String oauthId, String keyword, Pageable pageable) {
     Professor professor = getProfessorByOauthId(oauthId);
     List<Course> searchCourses;
     if (keyword == null || keyword.isEmpty()) {
-        searchCourses = courseRepository.findCoursesWithSchedulesByProfessor(professor);
+        searchCourses = courseRepository.findCoursesWithSchedulesByProfessor(professor, pageable);
     } else {
         String escapedKeyword = escapeWildcard(keyword);
         String searchKeyword = "%" + escapedKeyword + "%";
-        searchCourses = courseRepository.findCoursesWithSchedulesByProfessorAndKeyword(professor, searchKeyword);
+        searchCourses = courseRepository.findCoursesWithSchedulesByProfessorAndKeyword(professor, searchKeyword, pageable);
     }
-    return getAllCoursesResponse(searchCourses);
+    return new PageImpl<>(getAllCoursesResponse(searchCourses.getContent()), pageable, searchCourses.getTotalElements());
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 51078e3 and becfe97.

📒 Files selected for processing (1)
  • back-end/reacton/src/main/java/com/softeer/reacton/domain/course/ProfessorCourseService.java (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
back-end/reacton/src/main/java/com/softeer/reacton/domain/course/ProfessorCourseService.java (1)
Learnt from: sunohkim
PR: softeer5th/Team3-PowerPenguin#94
File: back-end/reacton/src/main/java/com/softeer/reacton/domain/course/ProfessorCourseService.java:189-202
Timestamp: 2025-02-11T06:18:05.772Z
Learning: The team values clean code and well-structured refactoring, particularly when it involves breaking down complex stream operations into smaller, more focused methods for better maintainability and performance.
🔇 Additional comments (1)
back-end/reacton/src/main/java/com/softeer/reacton/domain/course/ProfessorCourseService.java (1)

112-119: LGTM! Clean implementation of the search functionality.

The changes effectively handle empty/null keywords while maintaining code clarity and security. The implementation:

  • Explicitly handles empty/null keywords by returning all courses
  • Properly escapes SQL wildcards to prevent injection
  • Maintains clean code structure with clear conditional logic

Copy link
Collaborator

@uri010 uri010 left a comment

Choose a reason for hiding this comment

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

오호 이렇게 하면 불필요한 과정이 없어져서 더 좋겠네요!

@sunohkim sunohkim merged commit b8617ea into dev Feb 23, 2025
2 checks passed
@sunohkim sunohkim deleted the fix/be/course-search branch February 23, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🌱 BE 백엔드 관련 🔨 Refactor 코드 리팩토링 (로직 변경 없이 코드 개선)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants