Skip to content

Commit

Permalink
Task 40 : Adding Java Doc for TimestampAfterStoreCreation and Timesta…
Browse files Browse the repository at this point in the history
…mpAfterStoreCreationValidator
  • Loading branch information
Rapter1990 committed Sep 29, 2024
1 parent 2d3a4d4 commit 2067621
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

import java.lang.annotation.*;

/**
* Annotation to validate that a timestamp is after the store creation time.
* This can be used on fields or parameters to enforce timestamp constraints.
*/
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = TimestampAfterStoreCreationValidator.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,35 @@
import java.time.LocalDateTime;
import java.util.Optional;

/**
* Validator for the {@link TimestampAfterStoreCreation} annotation that checks
* if a given timestamp is after the creation time of the nearest store.
*
* @see #isValid(LogCourierLocationRequest, ConstraintValidatorContext)
* @see #initialize(TimestampAfterStoreCreation)
*/
@RequiredArgsConstructor
@Slf4j
public class TimestampAfterStoreCreationValidator implements ConstraintValidator<TimestampAfterStoreCreation, LogCourierLocationRequest> {

private final StoreRepository storeRepository;

/**
* Initializes the validator with the specified {@link TimestampAfterStoreCreation} constraint annotation.
**/
@Override
public void initialize(TimestampAfterStoreCreation constraintAnnotation) {
}

/**
* Validates the given {@link LogCourierLocationRequest} to ensure that the
* timestamp is after the creation time of the nearest store within a 100-meter radius.
*
* @param request the {@link LogCourierLocationRequest} object containing the timestamp, latitude, and longitude
* @param context the {@link ConstraintValidatorContext} used for building error messages
* @return true if the timestamp is valid (i.e., after the nearest store's creation time or no nearby store found),
* false if the request is null or if any required field is missing
*/
@Override
public boolean isValid(LogCourierLocationRequest request, ConstraintValidatorContext context) {
// Check if the request is null or any required field is null
Expand Down

0 comments on commit 2067621

Please sign in to comment.