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

Feat 191 #192

Merged
merged 3 commits into from
Dec 6, 2024
Merged

Feat 191 #192

merged 3 commits into from
Dec 6, 2024

Conversation

capDoYeonLee
Copy link
Contributor

@capDoYeonLee capDoYeonLee commented Dec 6, 2024

  • 한 학기 일정 조회 기능 개발

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new endpoint to retrieve semester schedules via /api/calendar/semester.
    • Added a response structure for semester schedules, including event name and dates.
  • Bug Fixes

    • Corrected a typographical error in the method signature for fetching specific schedules.
  • Improvements

    • Enhanced functionality to fetch public schedules based on semester dates.
    • Updated methods to convert schedule entities into the new response format.

Copy link

coderabbitai bot commented Dec 6, 2024

Walkthrough

The pull request introduces several modifications across multiple classes in the com.example.demo package. Key changes include the removal of a MemberEntity field from the FilterEntity class, the addition of a new SemesterScheduleResponse class, and the implementation of a method in ScheduleService to retrieve semester schedules. Additionally, new methods are added to ScheduleResponseConverter and ScheduleJpaRepository to facilitate the conversion and retrieval of schedule data, respectively. A new endpoint in ScheduleController allows clients to access semester schedules.

Changes

File Change Summary
BE/error/src/main/java/com/example/demo/filter/persistence/FilterEntity.java - Removed field: private MemberEntity member
- Retained field: private Long memberId (non-nullable)
BE/error/src/main/java/com/example/demo/schedule/application/dto/SemesterScheduleResponse.java - Added class: SemesterScheduleResponse
- Added fields: private String eventName, private String eventStartDate, private String eventEndDate
BE/error/src/main/java/com/example/demo/schedule/application/service/ScheduleService.java - Added method: public List<SemesterScheduleResponse> getSemesterSchedule()
- Corrected method name: SpecificScheduleResopnse to SpecificScheduleResponse
BE/error/src/main/java/com/example/demo/schedule/domain/model/converter/ScheduleResponseConverter.java - Added method: public List<SemesterScheduleResponse> toSemesterScheduleResponse(List<ScheduleEntity> entities)
- Added method: private SemesterScheduleResponse buildSemesterResponse(ScheduleEntity entity)
BE/error/src/main/java/com/example/demo/schedule/infrastructure/persistence/ScheduleJpaRepository.java - Added method: public List<ScheduleEntity> findOneSemesterPublicSchedule(LocalDateTime requestDate)
BE/error/src/main/java/com/example/demo/schedule/presentation/ScheduleController.java - Added method: public ApiResponse<SuccessBody<List<SemesterScheduleResponse>>> getSemesterSchedule()

Possibly related PRs

  • feat: slack 자동화 메세지 기능 개발  #190: The changes in ScheduleService.java related to the findWeekendSchedule method may have implications for how schedules are retrieved, which could indirectly relate to the modifications in FilterEntity.java if schedules are filtered based on member relationships.

🐇 In the meadow where schedules bloom,
A new response class dispels the gloom.
With events to share, from start to end,
Our semester's tale, we now can send.
Hopping along, with data in tow,
The rabbit's delight in the updates we show! 🌼


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 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: 4

🧹 Outside diff range and nitpick comments (4)
BE/error/src/main/java/com/example/demo/schedule/application/dto/SemesterScheduleResponse.java (1)

14-18: Add validation annotations and documentation

The class would benefit from:

  1. Documentation explaining its purpose and field formats
  2. Validation annotations to ensure data integrity

Add documentation and validation:

+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * Response DTO for semester schedule information.
+ */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SemesterScheduleResponse {
+   @NotBlank(message = "Event name cannot be blank")
    private String eventName;
+   @NotNull(message = "Start date cannot be null")
    private LocalDateTime eventStartDate;
+   @NotNull(message = "End date cannot be null")
    private LocalDateTime eventEndDate;
}
BE/error/src/main/java/com/example/demo/schedule/application/service/ScheduleService.java (1)

Line range hint 65-69: Fix typo in method return type

The return type contains a typo: SpecificScheduleResopnse should be SpecificScheduleResponse

Apply this fix:

-   public SpecificScheduleResopnse getSpecificSchedule(final Long eventId) {
+   public SpecificScheduleResponse getSpecificSchedule(final Long eventId) {
        ScheduleModel model = domainService.findSchedule(eventId);
        String filterColor = scheduleJpaRepository.findFilterColor(model.getFilterId());
        return responseConverter.from(model, filterColor);
    }
BE/error/src/main/java/com/example/demo/schedule/presentation/ScheduleController.java (1)

Line range hint 82-91: Review scheduled task implementation

The sendSlackMessage method:

  1. Is both a scheduled task and an HTTP endpoint
  2. Lacks error handling for Slack API calls

Consider separating the scheduled task from the HTTP endpoint and adding proper error handling.

BE/error/src/main/java/com/example/demo/schedule/domain/model/converter/ScheduleResponseConverter.java (1)

74-80: Consider adding null checks and consistent date formatting.

The date conversion might need additional safety measures:

  1. Add null checks for entity and its fields
  2. Use the existing FORMATTER field for consistent date formatting across the class

Consider this implementation:

 private SemesterScheduleResponse buildSemesterResponse(ScheduleEntity entity) {
+    if (entity == null) {
+        return null;
+    }
     return SemesterScheduleResponse.builder()
-            .eventName(entity.getEventName())
-            .eventStartDate(entity.getEventStartDate().toString())
-            .eventEndDate(entity.getEventEndDate().toString())
+            .eventName(entity.getEventName())
+            .eventStartDate(entity.getEventStartDate() != null ? 
+                entity.getEventStartDate().format(FORMATTER) : null)
+            .eventEndDate(entity.getEventEndDate() != null ? 
+                entity.getEventEndDate().format(FORMATTER) : null)
             .build();
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 292d0e6 and d5b09cf.

📒 Files selected for processing (6)
  • BE/error/src/main/java/com/example/demo/filter/persistence/FilterEntity.java (0 hunks)
  • BE/error/src/main/java/com/example/demo/schedule/application/dto/SemesterScheduleResponse.java (1 hunks)
  • BE/error/src/main/java/com/example/demo/schedule/application/service/ScheduleService.java (1 hunks)
  • BE/error/src/main/java/com/example/demo/schedule/domain/model/converter/ScheduleResponseConverter.java (2 hunks)
  • BE/error/src/main/java/com/example/demo/schedule/infrastructure/persistence/ScheduleJpaRepository.java (2 hunks)
  • BE/error/src/main/java/com/example/demo/schedule/presentation/ScheduleController.java (1 hunks)
💤 Files with no reviewable changes (1)
  • BE/error/src/main/java/com/example/demo/filter/persistence/FilterEntity.java
🔇 Additional comments (2)
BE/error/src/main/java/com/example/demo/schedule/domain/model/converter/ScheduleResponseConverter.java (1)

68-72: LGTM! Clean implementation of the converter method.

The stream operation is implemented correctly with good separation of concerns.

BE/error/src/main/java/com/example/demo/schedule/infrastructure/persistence/ScheduleJpaRepository.java (1)

36-65: Verify the impact of pagination on the frontend.

The addition of pagination might require changes in the frontend to handle partial data loading.

Let's check for any frontend components that might be affected:

Comment on lines +15 to +17
private String eventName;
private String eventStartDate;
private String eventEndDate;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using proper date types instead of Strings for date fields

Using String for date fields (eventStartDate and eventEndDate) can lead to:

  • Inconsistent date formats
  • Difficulty in date comparisons and calculations
  • Potential parsing errors

Consider using LocalDateTime or LocalDate:

public class SemesterScheduleResponse {
    private String eventName;
-   private String eventStartDate;
-   private String eventEndDate;
+   private LocalDateTime eventStartDate;
+   private LocalDateTime eventEndDate;
}
📝 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 String eventName;
private String eventStartDate;
private String eventEndDate;
private String eventName;
private LocalDateTime eventStartDate;
private LocalDateTime eventEndDate;

Comment on lines +76 to +80
public List<SemesterScheduleResponse> getSemesterSchedule() {
LocalDateTime requestNow = LocalDateTime.now();
List<ScheduleEntity> semesterScheduleResponses = scheduleJpaRepository.findOneSemesterPublicSchedule(requestNow);
return responseConverter.toSemesterScheduleResponse(semesterScheduleResponses);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling and documentation for getSemesterSchedule

The method lacks:

  1. Error handling for empty results
  2. Documentation explaining the business logic
  3. Separation of concerns (entity to DTO conversion should be in converter)

Consider this improvement:

+   /**
+    * Retrieves public schedules for the current semester.
+    * @return List of semester schedules, empty list if none found
+    */
    public List<SemesterScheduleResponse> getSemesterSchedule() {
        LocalDateTime requestNow = LocalDateTime.now();
        List<ScheduleEntity> semesterScheduleResponses = scheduleJpaRepository.findOneSemesterPublicSchedule(requestNow);
+       if (semesterScheduleResponses.isEmpty()) {
+           // Consider if this should throw a custom exception or return empty list
+           return Collections.emptyList();
+       }
        return responseConverter.toSemesterScheduleResponse(semesterScheduleResponses);
    }
📝 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
public List<SemesterScheduleResponse> getSemesterSchedule() {
LocalDateTime requestNow = LocalDateTime.now();
List<ScheduleEntity> semesterScheduleResponses = scheduleJpaRepository.findOneSemesterPublicSchedule(requestNow);
return responseConverter.toSemesterScheduleResponse(semesterScheduleResponses);
}
/**
* Retrieves public schedules for the current semester.
* @return List of semester schedules, empty list if none found
*/
public List<SemesterScheduleResponse> getSemesterSchedule() {
LocalDateTime requestNow = LocalDateTime.now();
List<ScheduleEntity> semesterScheduleResponses = scheduleJpaRepository.findOneSemesterPublicSchedule(requestNow);
if (semesterScheduleResponses.isEmpty()) {
// Consider if this should throw a custom exception or return empty list
return Collections.emptyList();
}
return responseConverter.toSemesterScheduleResponse(semesterScheduleResponses);
}

Comment on lines +77 to +81
@GetMapping("semester")
public ApiResponse<SuccessBody<List<SemesterScheduleResponse>>> getSemesterSchedule() {
List<SemesterScheduleResponse> response = scheduleService.getSemesterSchedule();
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GET);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add API documentation and consider pagination

The endpoint would benefit from:

  1. Swagger/OpenAPI documentation
  2. Pagination support for large result sets

Consider these improvements:

+   /**
+    * Retrieves public schedules for the current semester.
+    * @return List of semester schedules wrapped in ApiResponse
+    */
+   @Operation(summary = "Get semester schedule", description = "Retrieves all public schedules for the current semester")
+   @ApiResponse(responseCode = "200", description = "Successfully retrieved semester schedule")
    @GetMapping("semester")
-   public ApiResponse<SuccessBody<List<SemesterScheduleResponse>>> getSemesterSchedule() {
+   public ApiResponse<SuccessBody<Page<SemesterScheduleResponse>>> getSemesterSchedule(
+       @RequestParam(defaultValue = "0") int page,
+       @RequestParam(defaultValue = "20") int size) {
-       List<SemesterScheduleResponse> response = scheduleService.getSemesterSchedule();
+       Page<SemesterScheduleResponse> response = scheduleService.getSemesterSchedule(PageRequest.of(page, size));
        return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GET);
    }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +36 to +65
public List<ScheduleEntity> findOneSemesterPublicSchedule(LocalDateTime requestDate) {
int month = requestDate.getMonthValue();
int year = requestDate.getYear();

LocalDateTime startDate;
LocalDateTime endDate;

if (month >= 2 && month <= 7) {
// 2월 ~ 7월
startDate = LocalDateTime.of(year, 2, 1, 0, 0);
endDate = LocalDateTime.of(year, 7, 31, 23, 59, 59);
} else if (month >= 8 && month <= 12) {
// 8월 ~ 다음해 1월
startDate = LocalDateTime.of(year, 8, 1, 0, 0);
endDate = LocalDateTime.of(year + 1, 1, 31, 23, 59, 59);
} else { // month == 1
// 전년도 8월 ~ 해당 연도 1월
startDate = LocalDateTime.of(year - 1, 8, 1, 0, 0);
endDate = LocalDateTime.of(year, 1, 31, 23, 59, 59);
}

String jpql = "SELECT s FROM ScheduleEntity s " +
"WHERE s.eventStartDate BETWEEN :startDate AND :endDate";

TypedQuery<ScheduleEntity> query = em.createQuery(jpql, ScheduleEntity.class);
query.setParameter("startDate", startDate);
query.setParameter("endDate", endDate);

return query.getResultList();
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Several improvements needed for robustness and performance.

The implementation has the following concerns:

  1. Missing filter for public schedules
  2. No pagination for potentially large result sets
  3. Hardcoded date ranges could be constants
  4. No sorting specified

Consider this improved implementation:

+ private static final int FIRST_SEMESTER_START_MONTH = 2;
+ private static final int FIRST_SEMESTER_END_MONTH = 7;
+ private static final int SECOND_SEMESTER_START_MONTH = 8;

 public List<ScheduleEntity> findOneSemesterPublicSchedule(LocalDateTime requestDate) {
     int month = requestDate.getMonthValue();
     int year = requestDate.getYear();

     LocalDateTime startDate;
     LocalDateTime endDate;

-    if (month >= 2 && month <= 7) {
+    if (month >= FIRST_SEMESTER_START_MONTH && month <= FIRST_SEMESTER_END_MONTH) {
         // 2월 ~ 7월
-        startDate = LocalDateTime.of(year, 2, 1, 0, 0);
-        endDate = LocalDateTime.of(year, 7, 31, 23, 59, 59);
+        startDate = LocalDateTime.of(year, FIRST_SEMESTER_START_MONTH, 1, 0, 0);
+        endDate = LocalDateTime.of(year, FIRST_SEMESTER_END_MONTH, 31, 23, 59, 59);
-    } else if (month >= 8 && month <= 12) {
+    } else if (month >= SECOND_SEMESTER_START_MONTH && month <= 12) {
         // 8월 ~ 다음해 1월
-        startDate = LocalDateTime.of(year, 8, 1, 0, 0);
+        startDate = LocalDateTime.of(year, SECOND_SEMESTER_START_MONTH, 1, 0, 0);
         endDate = LocalDateTime.of(year + 1, 1, 31, 23, 59, 59);
     } else { // month == 1
         // 전년도 8월 ~ 해당 연도 1월
-        startDate = LocalDateTime.of(year - 1, 8, 1, 0, 0);
+        startDate = LocalDateTime.of(year - 1, SECOND_SEMESTER_START_MONTH, 1, 0, 0);
         endDate = LocalDateTime.of(year, 1, 31, 23, 59, 59);
     }

     String jpql = "SELECT s FROM ScheduleEntity s " +
-            "WHERE s.eventStartDate BETWEEN :startDate AND :endDate";
+            "WHERE s.scheduleType = :scheduleType " +
+            "AND s.eventStartDate BETWEEN :startDate AND :endDate " +
+            "ORDER BY s.eventStartDate ASC";

     TypedQuery<ScheduleEntity> query = em.createQuery(jpql, ScheduleEntity.class);
+    query.setParameter("scheduleType", "PUBLIC");
     query.setParameter("startDate", startDate);
     query.setParameter("endDate", endDate);
+    query.setMaxResults(1000); // Add pagination to prevent memory issues

     return query.getResultList();
 }
📝 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
public List<ScheduleEntity> findOneSemesterPublicSchedule(LocalDateTime requestDate) {
int month = requestDate.getMonthValue();
int year = requestDate.getYear();
LocalDateTime startDate;
LocalDateTime endDate;
if (month >= 2 && month <= 7) {
// 2월 ~ 7월
startDate = LocalDateTime.of(year, 2, 1, 0, 0);
endDate = LocalDateTime.of(year, 7, 31, 23, 59, 59);
} else if (month >= 8 && month <= 12) {
// 8월 ~ 다음해 1월
startDate = LocalDateTime.of(year, 8, 1, 0, 0);
endDate = LocalDateTime.of(year + 1, 1, 31, 23, 59, 59);
} else { // month == 1
// 전년도 8월 ~ 해당 연도 1월
startDate = LocalDateTime.of(year - 1, 8, 1, 0, 0);
endDate = LocalDateTime.of(year, 1, 31, 23, 59, 59);
}
String jpql = "SELECT s FROM ScheduleEntity s " +
"WHERE s.eventStartDate BETWEEN :startDate AND :endDate";
TypedQuery<ScheduleEntity> query = em.createQuery(jpql, ScheduleEntity.class);
query.setParameter("startDate", startDate);
query.setParameter("endDate", endDate);
return query.getResultList();
}
private static final int FIRST_SEMESTER_START_MONTH = 2;
private static final int FIRST_SEMESTER_END_MONTH = 7;
private static final int SECOND_SEMESTER_START_MONTH = 8;
public List<ScheduleEntity> findOneSemesterPublicSchedule(LocalDateTime requestDate) {
int month = requestDate.getMonthValue();
int year = requestDate.getYear();
LocalDateTime startDate;
LocalDateTime endDate;
if (month >= FIRST_SEMESTER_START_MONTH && month <= FIRST_SEMESTER_END_MONTH) {
// 2월 ~ 7월
startDate = LocalDateTime.of(year, FIRST_SEMESTER_START_MONTH, 1, 0, 0);
endDate = LocalDateTime.of(year, FIRST_SEMESTER_END_MONTH, 31, 23, 59, 59);
} else if (month >= SECOND_SEMESTER_START_MONTH && month <= 12) {
// 8월 ~ 다음해 1월
startDate = LocalDateTime.of(year, SECOND_SEMESTER_START_MONTH, 1, 0, 0);
endDate = LocalDateTime.of(year + 1, 1, 31, 23, 59, 59);
} else { // month == 1
// 전년도 8월 ~ 해당 연도 1월
startDate = LocalDateTime.of(year - 1, SECOND_SEMESTER_START_MONTH, 1, 0, 0);
endDate = LocalDateTime.of(year, 1, 31, 23, 59, 59);
}
String jpql = "SELECT s FROM ScheduleEntity s " +
"WHERE s.scheduleType = :scheduleType " +
"AND s.eventStartDate BETWEEN :startDate AND :endDate " +
"ORDER BY s.eventStartDate ASC";
TypedQuery<ScheduleEntity> query = em.createQuery(jpql, ScheduleEntity.class);
query.setParameter("scheduleType", "PUBLIC");
query.setParameter("startDate", startDate);
query.setParameter("endDate", endDate);
query.setMaxResults(1000); // Add pagination to prevent memory issues
return query.getResultList();
}

@capDoYeonLee capDoYeonLee merged commit 855b809 into main Dec 6, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant