Skip to content

Conversation

@simonhir
Copy link
Member

@simonhir simonhir commented Apr 2, 2025

Description

Matching refactor csv check. Allow excel csv and check extension.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced CSV file upload validation by enforcing stricter checks on file extension and MIME type to ensure only correctly formatted CSV files are accepted.

@simonhir simonhir self-assigned this Apr 2, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 2, 2025

Walkthrough

The changes update the file validation logic in the RestAdapter class. Two constants are introduced: one defining the expected CSV file extension and another listing acceptable CSV content types. The validation in the update method now checks both that the filename ends with the expected extension and that the file's content type matches one of the acceptable values.

Changes

File Description
matching-service/.../RestAdapter.java Added CSV_EXTENSION and CSV_CONTENT_TYPES constants; updated update method to validate the file’s extension and content type.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RestAdapter
    Client->>RestAdapter: Send file upload request
    RestAdapter->>RestAdapter: Check if filename ends with CSV_EXTENSION
    RestAdapter->>RestAdapter: Validate content type against CSV_CONTENT_TYPES
    RestAdapter-->>Client: Return success or error response
Loading

Poem

Hoppin' through the code with glee,
I add CSV checks for you and me.
Constant carrots crunch with delight,
Validating files both day and night.
Cheers from a coding bunny tonight! 🥕🐇


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 21cf364 and 29aca44.

📒 Files selected for processing (1)
  • matching-service/src/main/java/de/muenchen/oss/swim/matching/adapter/in/rest/RestAdapter.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • matching-service/src/main/java/de/muenchen/oss/swim/matching/adapter/in/rest/RestAdapter.java

Note

🎁 Summarized by CodeRabbit Free

Your organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above.

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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.

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
Contributor

@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: 1

🧹 Nitpick comments (1)
matching-service/src/main/java/de/muenchen/oss/swim/matching/adapter/in/rest/RestAdapter.java (1)

77-79: Improve error message specificity.

The error message "File needs to be a csv" could be more specific about what validation failed (extension or content type).

Suggested improvement:

-            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "File needs to be a csv");
+            final String errorDetail = file.getOriginalFilename() == null ? "Missing filename" : 
+                    !file.getOriginalFilename().endsWith(CSV_EXTENSION) ? "File extension must be .csv" : 
+                    "Invalid content type. Expected one of: " + CSV_CONTENT_TYPES;
+            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid file format: " + errorDetail);

This provides more context about which validation rule failed, helping users correct their input.

🧰 Tools
🪛 GitHub Actions: build all

[error] 77-77: Medium: Possible null pointer dereference in de.muenchen.oss.swim.matching.adapter.in.rest.RestAdapter.update(MultipartFile) due to return value of called method.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24ed839 and e9608bb.

📒 Files selected for processing (1)
  • matching-service/src/main/java/de/muenchen/oss/swim/matching/adapter/in/rest/RestAdapter.java (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: build all
matching-service/src/main/java/de/muenchen/oss/swim/matching/adapter/in/rest/RestAdapter.java

[error] 77-77: Medium: Possible null pointer dereference in de.muenchen.oss.swim.matching.adapter.in.rest.RestAdapter.update(MultipartFile) due to return value of called method.

🔇 Additional comments (1)
matching-service/src/main/java/de/muenchen/oss/swim/matching/adapter/in/rest/RestAdapter.java (1)

36-37: Good addition of constants for file validation.

Defining constants for CSV extension and content types improves code maintainability and makes the validation more explicit. Including application/vnd.ms-excel as an acceptable content type allows handling Excel-generated CSV files as required.

@simonhir simonhir marked this pull request as ready for review April 2, 2025 14:53
@simonhir simonhir requested a review from rowe42 April 2, 2025 14:53
@simonhir simonhir merged commit c6b070b into main Apr 3, 2025
8 checks passed
@simonhir simonhir deleted the bug/matching-refarctor-csv-check branch April 3, 2025 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants