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

fix : 요청시 지역 타입 변경 #13

Merged
merged 1 commit into from
Feb 5, 2025
Merged

fix : 요청시 지역 타입 변경 #13

merged 1 commit into from
Feb 5, 2025

Conversation

ywj9811
Copy link
Contributor

@ywj9811 ywj9811 commented Feb 5, 2025

🐈 PR 요약

PR 내용 한 줄로 요약
요청시 지역 타입 변경

✨ PR 상세

PR 상세 내용 개조식으로 작성

  • enum -> String
  • 경기도를 포함하는 방식으로 변경

🚨 참고사항

리뷰어들이 알아야 하거나 알면 좋은 참고사항 작성

✅ 체크리스트

  • Label 지정했나요?
  • 관련 테크스펙 링크 연결했나요?

Summary by CodeRabbit

  • Refactor
    • Updated teacher filtering to accept plain text for district values, simplifying input and providing greater flexibility.
    • Adjusted data processing logic to ensure consistent handling of district information across search and management features.

@ywj9811 ywj9811 self-assigned this Feb 5, 2025
@ywj9811 ywj9811 added the 🐞BugFix 버그 수정 label Feb 5, 2025
Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

This pull request updates how district information is represented across several application modules. The primary change is converting the districts field from a typed List<District> to a generic List<String> in request/response DTOs, controllers, mappers, use cases, and repository methods. Additionally, mapping logic has been adjusted to convert district objects to their string descriptions or vice versa when necessary.

Changes

File(s) Change Summary
src/…/dto/req/TeacherSearchRequest.java
src/…/dto/res/AllFilteringTeacher.java
Updated districts field type from List<District> to List<String>. Removed dependency on District in the response DTO.
src/…/mapper/AdminMapper.java
src/…/presentation/AdminController.java
Modified method signatures to change the districts parameter from List<District> to List<String>.
src/…/usecase/AdminInfoUseCase.java Adjusted internal mapping logic in searchAllTeacher to extract district descriptions using getDistrict().getDescription() instead of directly referencing District.
src/…/repository/TeacherDslRepositoryImpl.java Changed the districtSpecifier method parameter to List<String> and updated the logic to convert strings to District enums using District.fromString(district).

Sequence Diagram(s)

sequenceDiagram
    participant C as AdminController
    participant U as AdminInfoUseCase
    participant M as AdminMapper
    participant R as TeacherDslRepositoryImpl

    C->>U: searchAllTeacher(request with districts as List<String>)
    U->>M: mapToAllFilteringTeacherResponse(teacher, districts)
    M-->>U: FilteringTeacher response
    U->>R: districtSpecifier(List<String> districts)
    R->>R: Convert each district string to District enum (District.fromString)
    R-->>U: BooleanExpression for filtering
    U-->>C: AllFilteringTeacher response
Loading

Possibly related PRs

Poem

In a garden of code, I happily hop,
From districts of enums, I’ve made a clean swap.
Strings now dance where enums did reside,
A sweet little shift on this coding ride.
Carrots and code, together we cheer,
Hop along, dear devs, the change is here!
🥕🐇 Happy hopping through the refactored code!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ 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: 3

🧹 Nitpick comments (1)
src/main/java/com/yedu/backend/admin/application/usecase/AdminInfoUseCase.java (1)

76-78: Add null safety checks in the district mapping.

The current implementation might throw NullPointerException if either teacherDistrict or getDistrict() returns null.

 List<String> districts = teacherDistricts.stream()
-        .map(teacherDistrict -> teacherDistrict.getDistrict().getDescription())
+        .map(teacherDistrict -> Optional.ofNullable(teacherDistrict)
+            .map(TeacherDistrict::getDistrict)
+            .map(District::getDescription)
+            .orElse(""))
+        .filter(district -> !district.isEmpty())
         .toList();
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7021391 and 14f9e05.

📒 Files selected for processing (6)
  • src/main/java/com/yedu/backend/admin/application/dto/req/TeacherSearchRequest.java (1 hunks)
  • src/main/java/com/yedu/backend/admin/application/dto/res/AllFilteringTeacher.java (1 hunks)
  • src/main/java/com/yedu/backend/admin/application/mapper/AdminMapper.java (1 hunks)
  • src/main/java/com/yedu/backend/admin/application/usecase/AdminInfoUseCase.java (1 hunks)
  • src/main/java/com/yedu/backend/admin/presentation/AdminController.java (1 hunks)
  • src/main/java/com/yedu/backend/domain/teacher/domain/repository/TeacherDslRepositoryImpl.java (1 hunks)
🔇 Additional comments (3)
src/main/java/com/yedu/backend/admin/application/dto/req/TeacherSearchRequest.java (1)

9-9: Add validation for district values.

Consider adding validation to ensure that the district strings match expected values and formats, especially for special cases like "경기도" (Gyeonggi-do).

@Pattern(regexp = "^[가-힣]+도?$", message = "Invalid district format")
List<String> districts,
✅ Verification successful

Error: No shell scripts or web queries found


Validation for district field in TeacherSearchRequest DTO

The current DTO now accepts district names as simple strings without enforcing any format. It’s a good idea to add validation—such as using a @pattern annotation—to ensure inputs match expected patterns (e.g., only valid Korean district names like "경기도").

  • Consider adding a validation annotation (e.g., @Pattern) to the districts field.
  • Use a regex (like "^[가-힣]+도?$") to allow only valid Korean district names.
  • This will help catch any client-side input errors early.
src/main/java/com/yedu/backend/admin/application/dto/res/AllFilteringTeacher.java (1)

20-20: LGTM!

The change to List<String> is consistent with the request DTO and makes sense for client consumption.

src/main/java/com/yedu/backend/admin/presentation/AdminController.java (1)

68-68: LGTM!

The parameter type change is consistent with the DTO changes, and the optional nature is appropriate for search functionality.

@@ -103,7 +102,7 @@ else if (count.equals("주 4회"))
);
}

public static FilteringTeacher mapToAllFilteringTeacherResponse(Teacher teacher, List<District> districts) {
public static FilteringTeacher mapToAllFilteringTeacherResponse(Teacher teacher, List<String> districts) {
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Add validation for district strings.

The method accepts raw strings without validating if they represent valid districts. Consider adding validation to ensure the strings match valid district values.


🏁 Script executed:

#!/bin/bash
# Check if District enum has a fromString method with proper validation
ast-grep --pattern 'enum District {
  $$$
  fromString($$$) {
    $$$
  }
  $$$
}'

Length of output: 84


🏁 Script executed:

#!/bin/bash
# Locate the file containing the District enum and display its content
fd -e java "District.java" --exec cat {} \;

Length of output: 1764

District String Validation Needed in Mapping Method

The District enum provides a fromString method for validating district strings. However, the mapToAllFilteringTeacherResponse method in AdminMapper.java still accepts a List<String> without converting or validating the district strings. Consider updating the mapper to invoke District.fromString for each supplied string to ensure only valid districts are used or to explicitly handle invalid input.

  • Location: src/main/java/com/yedu/backend/admin/application/mapper/AdminMapper.java
  • Suggestion: Update the implementation of mapToAllFilteringTeacherResponse to iterate over the provided strings, validate each using District.fromString, and then use the resulting District value in the response.

Comment on lines +114 to 123
private BooleanExpression districtSpecifier(List<String> districts) {
if (districts == null || districts.isEmpty()) {
return TRUE; // where() 절에서 무시됨
}

return districts.stream()
.map(teacherDistrict.district::eq)
.map(district -> teacherDistrict.district.eq(District.fromString(district)))
.reduce(BooleanExpression::or)
.orElse(TRUE);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for invalid district strings.

The current implementation might throw an exception if District.fromString() fails to parse an invalid district string. Consider adding error handling:

 private BooleanExpression districtSpecifier(List<String> districts) {
     if (districts == null || districts.isEmpty()) {
         return TRUE;
     }

     return districts.stream()
-        .map(district -> teacherDistrict.district.eq(District.fromString(district)))
+        .map(district -> {
+            try {
+                return teacherDistrict.district.eq(District.fromString(district));
+            } catch (IllegalArgumentException e) {
+                // Log the error
+                return TRUE;
+            }
+        })
         .reduce(BooleanExpression::or)
         .orElse(TRUE);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private BooleanExpression districtSpecifier(List<String> districts) {
if (districts == null || districts.isEmpty()) {
return TRUE; // where() 절에서 무시됨
}
return districts.stream()
.map(teacherDistrict.district::eq)
.map(district -> teacherDistrict.district.eq(District.fromString(district)))
.reduce(BooleanExpression::or)
.orElse(TRUE);
}
private BooleanExpression districtSpecifier(List<String> districts) {
if (districts == null || districts.isEmpty()) {
return TRUE; // where() 절에서 무시됨
}
return districts.stream()
.map(district -> {
try {
return teacherDistrict.district.eq(District.fromString(district));
} catch (IllegalArgumentException e) {
// Log the error
return TRUE;
}
})
.reduce(BooleanExpression::or)
.orElse(TRUE);
}

💡 Verification agent

⚠️ Potential issue

🧩 Analysis chain

Implement special handling for "경기도" regions.

According to the PR objectives, special handling for "경기도" regions should be implemented. Consider adding logic to handle Gyeonggi-do districts:

 private BooleanExpression districtSpecifier(List<String> districts) {
     if (districts == null || districts.isEmpty()) {
         return TRUE;
     }

     return districts.stream()
-        .map(district -> teacherDistrict.district.eq(District.fromString(district)))
+        .map(district -> {
+            if (district.contains("경기도")) {
+                // Handle Gyeonggi-do districts
+                return teacherDistrict.district.stringValue().like("경기도%");
+            }
+            return teacherDistrict.district.eq(District.fromString(district));
+        })
         .reduce(BooleanExpression::or)
         .orElse(TRUE);
 }

Let's verify if there are any existing Gyeonggi-do district handling patterns in the codebase:


🏁 Script executed:

#!/bin/bash
# Search for existing Gyeonggi-do handling patterns
rg -i "경기도" --type java

Length of output: 362

Special handling for "경기도" districts is missing.

The search output only shows hardcoded district constants (e.g., "경기도 안양", "경기도 용인", "경기도 고양") in the District.java file. There is no evidence of dedicated "경기도" handling logic in the TeacherDslRepositoryImpl. As special handling is required, you should add the conditional logic (using like("경기도%")) in the district specifier method as suggested.

  • Verify the changes in src/main/java/com/yedu/backend/domain/teacher/domain/repository/TeacherDslRepositoryImpl.java (lines 114-123).
  • Note that the only references to "경기도" are in the constants defined in src/main/java/com/yedu/backend/domain/teacher/domain/entity/constant/District.java.

@ywj9811 ywj9811 merged commit 5d0d3fa into develop Feb 5, 2025
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Feb 10, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞BugFix 버그 수정
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant