Skip to content

876: Added optional to all of the nullable function returns in POTDRe…#861

Merged
Arshadul-Monir merged 2 commits intomainfrom
876
Mar 18, 2026
Merged

876: Added optional to all of the nullable function returns in POTDRe…#861
Arshadul-Monir merged 2 commits intomainfrom
876

Conversation

@Arshadul-Monir
Copy link
Collaborator

@Arshadul-Monir Arshadul-Monir commented Mar 17, 2026

876

…pository

Description of changes

Replaced returns and return types of any function that can return a null value with an Optional return type for POTDRepository. Also edited anywhere that used those functions to match the return type.

Checklist before review

  • I have done a thorough self-review of the PR
  • Copilot has reviewed my latest changes, and all comments have been fixed and/or closed.
  • If I have made database changes, I have made sure I followed all the db repo rules listed in the wiki here. (check if no db changes)
  • All tests have passed
  • I have successfully deployed this PR to staging
  • I have done manual QA in both dev (and staging if possible) and attached screenshots below.

Screenshots

Dev

Staging

@github-actions
Copy link
Contributor

Available PR Commands

  • /ai - Triggers all AI review commands at once
  • /review - AI review of the PR changes
  • /describe - AI-powered description of the PR
  • /improve - AI-powered suggestions
  • /deploy - Deploy to staging

See: https://github.com/tahminator/codebloom/wiki/CI-Commands

@github-actions
Copy link
Contributor

Title

876: Added optional to all of the nullable function returns in POTDRe…


PR Type

Enhancement


Description

  • POTDRepository read methods now return Optional<POTD>.

  • Updated SubmissionController to handle Optional returns.

  • SubmissionsHandler and PotdSetter adapted for Optional.

  • Unit tests adjusted to reflect Optional return types.


Diagram Walkthrough

flowchart LR
  A["POTDRepository Interface"] -- "Update return types" --> B["POTDSqlRepository Implementation"]
  B -- "Return Optional.of/empty" --> C["SubmissionController"]
  C -- "Handle Optional" --> D["SubmissionsHandler"]
  D -- "Handle Optional" --> E["PotdSetter"]
  E -- "Handle Optional" --> F["Unit Tests"]
  F -- "Adjust mocks and assertions" --> G["Codebase Stability"]
Loading

File Walkthrough

Relevant files
Enhancement
3 files
SubmissionController.java
Update `getCurrentPotd` to handle `Optional` returns
+9/-4     
SubmissionsHandler.java
Adapt `handleSubmissions` to use `Optional` from repository
+5/-5     
PotdSetter.java
Modify `setPotd` logic to correctly handle `Optional`
+4/-2     
Interface change
1 files
POTDRepository.java
Change `getPOTDById` and `getCurrentPOTD` to return `Optional`
+3/-2     
Implementation change
1 files
POTDSqlRepository.java
Implement Optional return types for getPOTDById and getCurrentPOTD
+7/-6     
Tests
4 files
SubmissionControllerTest.java
Update `SubmissionController` tests for `Optional` mocks
+2/-2     
POTDRepositoryTest.java
Adjust `POTDRepository` tests to assert `Optional` returns
+7/-6     
SubmissionsHandlerTest.java
Update `SubmissionsHandler` tests for `Optional` mocks
+2/-2     
PotdSetterTest.java
Modify `PotdSetter` tests to handle `Optional` mocks
+5/-4     

@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Error Logging

The catch (SQLException e) blocks in POTDSqlRepository.java throw a RuntimeException directly. While this is consistent with the existing code in this file, the general error handling guidelines suggest using @Slf4j and log.error("...", e) for structured logging. Consider if these exceptions should be logged before being re-thrown, or if the calling layers are expected to handle the logging.

} catch (SQLException e) {
    throw new RuntimeException("Failed to create POTD", e);

@github-actions
Copy link
Contributor

Title

876: Added optional to all of the nullable function returns in POTDRe…


PR Type

Enhancement


Description

  • Migrate POTDRepository methods to Optional.

  • Update SubmissionController for Optional handling.

  • Refactor SubmissionsHandler to use Optional.

  • Adapt PotdSetter for Optional POTD checks.


Diagram Walkthrough

flowchart LR
    A[POTDRepository Interface] --> B[POTDSqlRepository]
    A --> C[SubmissionController]
    A --> D[SubmissionsHandler]
    A --> E[PotdSetter]
    A --> F[Tests]

    B -- "Implement Optional returns" --> A
    C -- "Consume Optional<POTD>" --> A
    D -- "Consume Optional<POTD>" --> A
    E -- "Consume Optional<POTD>" --> A
    F -- "Update mocks/assertions" --> A
Loading

File Walkthrough

Relevant files
Enhancement
5 files
SubmissionController.java
Refactor POTD retrieval to use `Optional` for null safety
+9/-4     
POTDRepository.java
Update `POTDRepository` interface for `Optional` return types
+3/-2     
POTDSqlRepository.java
Implement `Optional` return types for `POTD` SQL queries 
+7/-6     
SubmissionsHandler.java
Adapt `SubmissionsHandler` to consume `Optional`     
+5/-5     
PotdSetter.java
Refactor `PotdSetter` to handle `Optional` returns 
+4/-2     
Tests
4 files
SubmissionControllerTest.java
Update `SubmissionController` tests for `Optional` mocks
+4/-4     
POTDRepositoryTest.java
Adjust `POTDRepository` tests for `Optional` return type assertions
+11/-9   
SubmissionsHandlerTest.java
Update `SubmissionsHandler` tests to mock `Optional`
+2/-2     
PotdSetterTest.java
Refactor `PotdSetter` tests for `Optional` mocks and assertions
+17/-16 

@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Test Logic Error

The ArgumentCaptor for createPOTD in testPotdSetterSetPotdWherePotdIsFoundButNoCurrentPotdYet and testPotdSetterSetPotdWherePotdIsFoundAndDoesntMatchOldPotd is incorrectly defined as Optional<POTD>. The createPOTD method in POTDRepository expects a POTD object directly, not an Optional<POTD>. This could lead to a runtime error or incorrect test validation. The captor should be for POTD directly, and then potdCaptor.getValue() should be used.

ArgumentCaptor<Optional<org.patinanetwork.codebloom.common.db.models.potd.POTD>> potdCaptor =
        ArgumentCaptor.captor();
verify(potdRepository, times(1)).getCurrentPOTD();
verify(potdRepository, times(1)).createPOTD(potdCaptor.capture().get());

@github-actions
Copy link
Contributor

Title

876: Added optional to all of the nullable function returns in POTDRe…


PR Type

Enhancement


Description

  • Migrated POTDRepository methods to return Optional<POTD>.

  • Updated POTDSqlRepository to implement Optional returns.

  • Refactored SubmissionController and SubmissionsHandler to use Optional.

  • Adjusted PotdSetter and all related tests for Optional handling.


Diagram Walkthrough

flowchart LR
  A["POTDRepository Interface"] -- "Update method signatures" --> B["Optional<POTD> Returns"];
  C["POTDSqlRepository Implementation"] -- "Implement Optional returns" --> B;
  D["SubmissionController"] -- "Consume Optional<POTD>" --> B;
  E["SubmissionsHandler"] -- "Consume Optional<POTD>" --> B;
  F["PotdSetter"] -- "Consume Optional<POTD>" --> B;
  G["Related Tests"] -- "Update mocks & assertions" --> B;
Loading

File Walkthrough

Relevant files
Enhancement
5 files
SubmissionController.java
Adapted controller to handle `Optional` from repository.
+9/-4     
POTDRepository.java
Updated `getPOTDById` and `getCurrentPOTD` to return `Optional`.
+3/-2     
POTDSqlRepository.java
Implemented Optional returns for getPOTDById and getCurrentPOTD.
+7/-6     
SubmissionsHandler.java
Refactored `handleSubmissions` to process `Optional` correctly.
+5/-5     
PotdSetter.java
Modified `setPotd` to handle `Optional` when checking current POTD.
+4/-2     
Tests
4 files
SubmissionControllerTest.java
Adjusted mocks for `getCurrentPOTD` to return `Optional` values.
+4/-4     
POTDRepositoryTest.java
Updated tests for getPOTDById and getCurrentPOTD to assert Optional
presence.
+11/-9   
SubmissionsHandlerTest.java
Updated mocks for `getCurrentPOTD` to return `Optional` values.
+4/-4     
PotdSetterTest.java
Modified mocks and assertions to handle `Optional` returns.
+7/-6     

@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Error Handling

The catch (SQLException e) blocks in getPOTDById and getCurrentPOTD methods throw a RuntimeException directly without logging the exception using @Slf4j. The style guide recommends using @Slf4j and log.error("Exception thrown in ABClass.xyZFunction", e) for proper error handling and structured logging.

} catch (SQLException e) {
    throw new RuntimeException("Failed to get POTD by id", e);
}

@github-actions
Copy link
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@Arshadul-Monir
Copy link
Collaborator Author

/deploy

@github-actions
Copy link
Contributor

Title

876: Added optional to all of the nullable function returns in POTDRe…


PR Type

Enhancement, Tests


Description

  • Migrated POTDRepository methods to return Optional<POTD>.

  • Updated SubmissionController to handle Optional returns.

  • Refactored SubmissionsHandler and PotdSetter for Optional usage.

  • Updated unit tests to reflect Optional return types.


Diagram Walkthrough

flowchart LR
    A[POTDRepository Interface] -- "Return Optional<POTD>" --> B[POTDSqlRepository Implementation]
    B -- "Used by" --> C[API Controllers & Handlers]
    B -- "Used by" --> D[Scheduled Tasks]
    E[Unit Tests] -- "Updated for Optional" --> A
    E -- "Updated for Optional" --> B
    E -- "Updated for Optional" --> C
    E -- "Updated for Optional" --> D
Loading

File Walkthrough

Relevant files
Enhancement
5 files
SubmissionController.java
Updated POTD retrieval to use Optional type                           
+12/-7   
POTDRepository.java
Changed POTD repository read methods to return Optional   
+3/-2     
POTDSqlRepository.java
Implemented Optional return types for POTD SQL repository
+7/-6     
SubmissionsHandler.java
Adapted submission handling to use Optional POTD returns 
+5/-5     
PotdSetter.java
Adjusted POTD setter logic for Optional POTD objects         
+4/-2     
Tests
4 files
SubmissionControllerTest.java
Updated submission controller tests for Optional POTD mocks
+4/-4     
POTDRepositoryTest.java
Modified POTD repository tests to verify Optional returns
+11/-9   
SubmissionsHandlerTest.java
Updated submission handler tests for Optional POTD mocks 
+4/-4     
PotdSetterTest.java
Adjusted POTD setter tests for Optional POTD mocks             
+7/-6     

@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@Arshadul-Monir
Copy link
Collaborator Author

/deploy

@github-actions
Copy link
Contributor

Title

876: Added optional to all of the nullable function returns in POTDRe…


PR Type

Enhancement


Description

  • Refactor POTDRepository methods to return Optional<POTD>.

  • Update SubmissionController to use Optional for POTD retrieval.

  • Adjust SubmissionsHandler and PotdSetter for Optional<POTD> handling.

  • Modify unit tests to align with new Optional return types.


Diagram Walkthrough

flowchart LR
  POTDRepository_Interface["POTDRepository (Interface)"] --> POTDSqlRepository_Impl["POTDSqlRepository (Implementation)"]
  POTDSqlRepository_Impl -- returns Optional<POTD> --> SubmissionController["SubmissionController"]
  POTDSqlRepository_Impl -- returns Optional<POTD> --> SubmissionsHandler["SubmissionsHandler"]
  POTDSqlRepository_Impl -- returns Optional<POTD> --> PotdSetter["PotdSetter"]
  SubmissionController -- handles Optional, throws exception --> ResponseStatusException["ResponseStatusException (Error)"]
  SubmissionsHandler -- handles Optional --> Logic["Business Logic"]
  PotdSetter -- handles Optional --> Logic
Loading

File Walkthrough

Relevant files
Enhancement
1 files
SubmissionController.java
Update POTD retrieval to use Optional and functional error handling
+8/-12   
Interface change
1 files
POTDRepository.java
Change `getPOTDById` and `getCurrentPOTD` return types to `Optional`
+3/-2     
Implementation change
1 files
POTDSqlRepository.java
Implement Optional return types for getPOTDById and getCurrentPOTD
+7/-6     
Code refactoring
2 files
SubmissionsHandler.java
Refactor POTD handling to correctly process `Optional`
+5/-5     
PotdSetter.java
Update POTD existence check to use `Optional` methods       
+4/-2     
Tests
4 files
SubmissionControllerTest.java
Adjust mocks for `POTDRepository` to return `Optional`
+4/-4     
POTDRepositoryTest.java
Update assertions to validate `Optional` return values
+11/-9   
SubmissionsHandlerTest.java
Modify `POTDRepository` mocks to return `Optional` 
+4/-4     
PotdSetterTest.java
Update mocks and assertions for `Optional` handling
+7/-6     

@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Error Message Consistency

The orElseThrow method in getCurrentPotd and getCurrentPotdEmbed uses a hardcoded user-facing error message. While functional, consider if such messages should be externalized or follow a more standardized error response format for consistency across the API.

POTD potd = potdRepository
        .getCurrentPOTD()
        .filter(p -> isSameDay(p.getCreatedAt()))
        .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Sorry, no problem of the day today!"));
Documentation

The getPOTDById and getCurrentPOTD methods now return Optional<POTD>. Adding Javadoc to these interface methods to explicitly state that Optional.empty() is returned when no POTD is found would enhance clarity and align with the documentation guidelines for non-controller classes.

Optional<POTD> getPOTDById(String id);

Optional<POTD> getCurrentPOTD();

@github-actions
Copy link
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@github-actions
Copy link
Contributor

Title

876: Added optional to all of the nullable function returns in POTDRe…


PR Type

Enhancement, Refactoring, Tests


Description

  • Refactor POTDRepository methods to return Optional<POTD>.

  • Update SubmissionController to use Optional and throw ResponseStatusException.

  • Adapt SubmissionsHandler and PotdSetter to handle Optional<POTD>.

  • Update unit tests for Optional returns and exception handling.


Diagram Walkthrough

flowchart LR
  POTDRepo["POTDRepository"] --> OptionalReturn{"Return Optional<POTD>"};
  OptionalReturn --> SubController["SubmissionController"];
  OptionalReturn --> SubHandler["SubmissionsHandler"];
  OptionalReturn --> PotdSetter["PotdSetter"];
  SubController -- "Uses Optional, throws ResponseStatusException" --> APIError["API Error Handling"];
  SubHandler -- "Adapts to Optional" --> SubHandler;
  PotdSetter -- "Adapts to Optional" --> PotdSetter;
  OptionalReturn -- "Reflected in" --> Tests["Updated Unit Tests"];
  APIError -- "Reflected in" --> Tests;
Loading

File Walkthrough

Relevant files
Error handling
1 files
SubmissionController.java
Updated POTD retrieval to use Optional and ResponseStatusException.
+10/-12 
Refactoring
4 files
POTDRepository.java
Changed `getPOTDById` and `getCurrentPOTD` to return `Optional`.
+3/-2     
POTDSqlRepository.java
Implemented `Optional` return types for POTD retrieval methods.
+7/-6     
SubmissionsHandler.java
Adapted POTD retrieval logic to handle `Optional` type.
+5/-5     
PotdSetter.java
Updated POTD existence check using `Optional.map` for clarity.
+4/-2     
Tests
4 files
SubmissionControllerTest.java
Updated mocks and assertions for Optional returns and
ResponseStatusException.
+10/-10 
POTDRepositoryTest.java
Modified assertions to validate `Optional` return types.
+11/-9   
SubmissionsHandlerTest.java
Updated POTD repository mocks to return `Optional`.
+4/-4     
PotdSetterTest.java
Adjusted POTD repository mocks to return `Optional`.
+7/-6     

@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

API Error Handling

The getCurrentPotd and getCurrentPotdEmbed methods now throw ResponseStatusException when the POTD is not found. This changes the API's error response structure from the ApiResponder.failure pattern previously used, which might affect consistency with other API endpoints and how the frontend handles these specific error responses. The ApiResponder type is intended to provide a consistent response structure, including for failures.

POTD potd = potdRepository
        .getCurrentPOTD()
        .filter(p -> isSameDay(p.getCreatedAt()))
        .orElseThrow(
                () -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Sorry, no problem of the day today!"));

@Arshadul-Monir
Copy link
Collaborator Author

/deploy

@github-actions
Copy link
Contributor

Title

876: Added optional to all of the nullable function returns in POTDRe…


PR Type

Enhancement


Description

  • Migrated POTDRepository methods to return Optional<POTD>.

  • Updated SubmissionController to use Optional for POTD retrieval.

  • Refactored SubmissionsHandler and PotdSetter for Optional handling.

  • Enhanced unit tests to reflect Optional return types and error handling.


Diagram Walkthrough

flowchart LR
  A[POTDRepository] -- "Return Optional<POTD>" --> B{Consumers};
  B -- "Handle Optional" --> C[SubmissionController];
  B -- "Handle Optional" --> D[SubmissionsHandler];
  B -- "Handle Optional" --> E[PotdSetter];
  C -- "Throw ResponseStatusException" --> F[Error Handling];
Loading

File Walkthrough

Relevant files
Enhancement
1 files
SubmissionController.java
Refactored POTD retrieval to use `Optional` and `orElseThrow`
+10/-12 
Interface change
1 files
POTDRepository.java
Updated `POTDRepository` interface methods to return `Optional`
+3/-2     
Implementation
1 files
POTDSqlRepository.java
Implemented `Optional` return types for POTD database queries
+7/-6     
Logic update
2 files
SubmissionsHandler.java
Adapted submission handling logic to process `Optional`
+10/-6   
PotdSetter.java
Modified POTD setter to correctly handle `Optional` for current POTD
+4/-2     
Tests
4 files
SubmissionControllerTest.java
Updated tests for SubmissionController to reflect Optional and
exception handling
+10/-10 
POTDRepositoryTest.java
Adjusted `POTDRepository` tests to validate `Optional` return types
+11/-9   
SubmissionsHandlerTest.java
Updated `SubmissionsHandler` tests to mock `Optional` returns
+4/-4     
PotdSetterTest.java
Modified PotdSetter tests to handle Optional mock responses and
assertions
+7/-6     

@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@Arshadul-Monir
Copy link
Collaborator Author

/deploy

@Arshadul-Monir
Copy link
Collaborator Author

/deploy

@github-actions
Copy link
Contributor

Title

876: Added optional to all of the nullable function returns in POTDRe…


PR Type

Enhancement, Error handling, Tests


Description

  • Migrates POTDRepository methods to return Optional<POTD>.

  • Updates SubmissionController to handle Optional and throw ResponseStatusException.

  • Refactors SubmissionsHandler and PotdSetter to safely process Optional<POTD>.

  • Enhances unit tests to reflect Optional return types and exception handling.


Diagram Walkthrough

flowchart LR
  POTDRepoInterface["POTDRepository Interface"] -- "Return Optional<POTD>" --> POTDSqlRepo["POTDSqlRepository Implementation"]
  POTDSqlRepo -- "Used by" --> SubmissionCtrl["SubmissionController"]
  POTDSqlRepo -- "Used by" --> SubmissionsHndlr["SubmissionsHandler"]
  POTDSqlRepo -- "Used by" --> PotdSetter["PotdSetter Scheduled Task"]
  SubmissionCtrl -- "Adapt logic & throw ResponseStatusException" --> UnitTests["Updated Unit Tests"]
  SubmissionsHndlr -- "Adapt logic" --> UnitTests
  PotdSetter -- "Adapt logic" --> UnitTests
Loading

File Walkthrough

Relevant files
Error handling
1 files
SubmissionController.java
Updates POTD retrieval to use Optional and ResponseStatusException
+10/-12 
Abstraction / code structure
2 files
POTDRepository.java
Updates POTDRepository interface to return Optional for nullable
methods
+3/-2     
POTDSqlRepository.java
Implements Optional return types for `POTD` SQL repository methods
+7/-6     
Enhancement
2 files
SubmissionsHandler.java
Adapts submission handling logic to `Optional` return type
+10/-6   
PotdSetter.java
Modifies POTD setter to handle `Optional` for current POTD
+4/-2     
Tests
4 files
SubmissionControllerTest.java
Updates SubmissionController tests for Optional returns and
ResponseStatusException
+10/-10 
POTDRepositoryTest.java
Adjusts `POTDRepository` tests to validate Optional return types
+11/-9   
SubmissionsHandlerTest.java
Updates `SubmissionsHandler` tests to mock `Optional`
+4/-4     
PotdSetterTest.java
Modifies `PotdSetter` tests to handle `Optional` mocks
+7/-6     

@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

API Error Handling

The error handling in getCurrentPotd and getCurrentPotdEmbed has been changed from returning ResponseEntity.status(HttpStatus.NOT_FOUND).body(ApiResponder.failure(...)) to throwing a ResponseStatusException. While ResponseStatusException is a valid Spring approach, it alters the API response structure for a "not found" scenario. Previously, the API would return a custom ApiResponder failure object, but now it will likely return a standard Spring error response. This change should be verified to ensure it aligns with the expected API error response format for the frontend and other consumers, especially given the mention of ApiResponder in the frontend guidelines.

POTD potd = potdRepository
        .getCurrentPOTD()
        .filter(p -> isSameDay(p.getCreatedAt()))
        .orElseThrow(
                () -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Sorry, no problem of the day today!"));

…pository

876: reduced multiple Optional.get() operations down into one

876: Condensed multiplier logic
@github-actions
Copy link
Contributor

Title

876: Added optional to all of the nullable function returns in POTDRe…


PR Type

Enhancement


Description

  • Migrate POTDRepository methods to return Optional<POTD>.

  • Refactor SubmissionController to use Optional and ResponseStatusException.

  • Update SubmissionsHandler and PotdSetter for Optional handling.

  • Adjust unit tests to reflect Optional return types and error handling.


Diagram Walkthrough

flowchart LR
  A[SubmissionController] --> B{POTDRepository};
  B -- "Optional<POTD>" --> C[SubmissionsHandler];
  B -- "Optional<POTD>" --> D[PotdSetter];
  B --> E[POTDSqlRepository];
  A -- "ResponseStatusException" --> F[API Client];
Loading

File Walkthrough

Relevant files
Enhancement
5 files
SubmissionController.java
Update POTD retrieval to use Optional and ResponseStatusException
+10/-12 
POTDRepository.java
Change `getPOTDById` and `getCurrentPOTD` to return `Optional`
+3/-2     
POTDSqlRepository.java
Implement `Optional` return types for POTD retrieval methods
+7/-6     
SubmissionsHandler.java
Refactor POTD multiplier logic using Optional methods       
+5/-9     
PotdSetter.java
Update POTD existence check to use Optional methods           
+4/-2     
Tests
4 files
SubmissionControllerTest.java
Update tests for SubmissionController to reflect Optional and
exception handling
+10/-10 
POTDRepositoryTest.java
Adjust `POTDRepository` tests for `Optional` return types
+11/-9   
SubmissionsHandlerTest.java
Update `SubmissionsHandler` tests for `Optional` POTD handling
+4/-4     
PotdSetterTest.java
Modify PotdSetter tests to use Optional.empty() for null scenarios
+7/-6     

@github-actions
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

API Error Consistency

The controller now throws ResponseStatusException when a POTD is not found. While this is an idiomatic Spring approach, it's important to verify that the global exception handling mechanism correctly intercepts this exception and transforms it into the standard ApiResponder.failure format, ensuring consistent API error responses for clients.

POTD potd = potdRepository
        .getCurrentPOTD()
        .filter(p -> isSameDay(p.getCreatedAt()))
        .orElseThrow(
                () -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Sorry, no problem of the day today!"));
Test Coverage

The tests for getPOTDById and getCurrentPOTD verify the Optional.isPresent() case. Consider adding explicit test cases to ensure that Optional.empty() is returned when a POTD is not found (e.g., by a non-existent ID or when no current POTD exists), to fully validate the Optional implementation.

    Optional<POTD> fetched = potdRepository.getPOTDById(testPOTD.getId());
    assertTrue(fetched.isPresent());
    assertTrue(Optional.of(testPOTD).equals(fetched));
}

@Test
@Order(3)
void testGetCurrentPOTD() {
    Optional<POTD> current = potdRepository.getCurrentPOTD();
    assertTrue(current.isPresent());
    assertTrue(Optional.of(testPOTD).equals(current));
}

@github-actions
Copy link
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@Arshadul-Monir
Copy link
Collaborator Author

/improve

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

PR Code Suggestions ✨

No code suggestions found for the PR.

@Arshadul-Monir Arshadul-Monir enabled auto-merge (rebase) March 18, 2026 05:24
@Arshadul-Monir
Copy link
Collaborator Author

/deploy

@angelayu0530 angelayu0530 self-requested a review March 18, 2026 18:07
@Arshadul-Monir Arshadul-Monir dismissed tahminator’s stale review March 18, 2026 18:11

Changes already made

@Arshadul-Monir Arshadul-Monir merged commit 76c807e into main Mar 18, 2026
35 checks passed
@Arshadul-Monir Arshadul-Monir deleted the 876 branch March 18, 2026 18:11
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.

3 participants