You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update SessionRepository methods to return Optional<Session>.
Adjust session creation and retrieval logic to handle Optional.
Refactor dependent components and tests for Optional usage.
Diagram Walkthrough
flowchart LR
A["Session.java (Model)"] --> B["SessionRepository.java (Interface)"]
B --> C["SessionSqlRepository.java (Implementation)"]
B --> D["AuthController.java"]
B --> E["CustomAuthenticationSuccessHandler.java"]
B --> F["Protector.java"]
A --> G["SessionDto.java"]
Update SessionRepository to return Optional<Session>.
Adapt session handling in controllers and services.
Enhance null-safety across session-related logic.
Diagram Walkthrough
flowchart LR
A[Old Session Model] --> B{Refactor ID to Optional};
B --> C[New Session Model];
C --> D{Update Session Repository};
D --> E{Update Auth Controllers & Services};
E --> F[Update Tests];
Migrate the Session model to use Optional for fields that can be null.
Update SessionRepository interface methods to return Optional<Session> where a session might not be found.
Implement the changes in SessionSqlRepository to handle Optional correctly during database operations (create, read).
Adjust all consuming code (e.g., AuthController, CustomAuthenticationSuccessHandler, Protector, DTOs) to correctly interact with Optional<Session> and Optional<String>.
Update relevant tests to reflect the Optional changes.
The private method updateSessionWithResultSet is defined but not called anywhere in the provided code diff. While not directly introduced by the Optional migration, it's good practice to remove unused code.
The Javadoc for the createSession method in SessionRepository describes required and optional fields for the Session object. Given that the id field is now an Optional<String> and is generated by the repository during creation, it would be beneficial to explicitly mention that the id will be populated by the repository after the method call. This clarifies the behavior for consumers of the interface.
* @note - Theprovidedobject's methods will be overridden with any returned data from the database.
* @paramsession - requiredfields:
* <ul>
* <li>userId
* <li>expiresAt
* </ul>
*/
voidcreateSession(Sessionsession);
In the createSession method, the session.getId().orElse(null) call for setting the prepared statement parameter is functionally correct. However, since the id is explicitly generated and set on the session object just before this line, session.getId().get() or session.getId().orElseThrow() would more accurately reflect the expectation that the ID is always present at this point. While orElse(null) doesn't cause an issue here, being more explicit about the expected presence of the ID could improve code clarity.
The introduction of feature flag management (FF.java and FeatureFlagManager.java) and additional @MockitoBean declarations in BaseRepositoryTest.java for scheduled tasks (SubmissionScheduler, LeetcodeAuthStealer) appear to be unrelated to the PR's stated goal of migrating session handling to use Optional. These changes introduce new functionality and dependencies that should ideally be part of a separate PR to maintain focus and simplify review.
The newly introduced FeatureFlagManager class, which is a critical component for managing application features, lacks dedicated test coverage. It's important to ensure that the feature flag logic, including exists and isEnabled methods, is thoroughly tested to prevent unexpected behavior or misconfigurations.
The @NotNullColumn annotation has been removed from the id field in the Session model, allowing it to be Optional.empty(). While the createSession method in SessionSqlRepository ensures an ID is generated before insertion, it's crucial to verify if the underlying database schema for the id column still enforces a NOT NULL constraint. If the database column is NOT NULL, the model's representation might be semantically misleading, even if the current implementation prevents null insertion.
@Builder.DefaultprivateOptional<String> id = Optional.empty();
The files FF.java and FeatureFlagManager.java introduce a new feature flag mechanism. This functionality is not mentioned in the PR description or the associated Notion task, which focuses solely on migrating session handling to use Optional. While feature flags are useful, their inclusion here might represent scope creep. It should be verified if this is an intended addition for this PR or if it should be moved to a separate PR.
The @NotNullColumn annotation was removed from the id field in the Session model. While Optional.empty() is not null, the underlying database column for id (presumably a primary key) should still be NOT NULL. Ensure that the database schema correctly enforces the NOT NULL constraint for the id column, and that the repository logic (e.g., createSession) guarantees an ID is always generated and present before insertion.
@Builder.DefaultprivateOptional<String> id = Optional.empty();
The PR description states the task is to migrate the Session and SessionRepository to use Optional. However, this PR introduces new files for feature flag functionality (FF.java and FeatureFlagManager.java). These changes appear to be unrelated to the stated task. Please confirm if these files are intentionally part of this PR or if they should be moved to a separate PR.
The Session model uses @Getter, @Setter, @Builder, @EqualsAndHashCode, and @ToString. While not strictly required for this specific model based on its current usage, the database repository best practices mention @Jacksonized is best to always add so a class can be de-serialized if it's ever converted from a JSON string into a Java object. Consider adding @Jacksonized for completeness and future-proofing, especially if Session objects might be serialized/deserialized from JSON.
publicclassSession {
@Builder.DefaultprivateOptional<String> id = Optional.empty();
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
873
Description of changes
Migrate SessionRepository to use optional
Checklist before review
Screenshots
Dev
Staging