This file contains 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
@Repository | |
public interface PostRepository extends ReactiveCrudRepository<Post, Long>, SoftDeleteRepository<Post, Long> { | |
Flux<PostWithDeleteStamp> findByDeletedDateIsNotNull(); | |
@Query("select * FROM posts") | |
Flux<PostWithDeleteStamp> findAllEntries(); | |
// delete (hard-delete) all posts from the database | |
@Query("delete from posts") | |
Mono<Void> flush(); |
This file contains 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
@Configuration | |
@EnableR2dbcRepositories( | |
basePackages = "io.github.jelilio.feed.repository", | |
repositoryBaseClass = SoftDeleteRepositoryImpl.class | |
) | |
public class DatabaseConfig { | |
} |
This file contains 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
@Repository | |
public interface PostRepository extends SoftDeleteRepository<Post, Long>, ReactiveCrudRepository<Post, Long> { | |
@NonNull | |
default Mono<Post> findById(@NonNull Long id) { | |
return findById(id, Post.class); | |
} | |
@NonNull | |
default Flux<Post> findAll() { | |
return findAll(Post.class); |
This file contains 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
public interface SoftDeleteRepository<T, ID> { | |
@NonNull | |
Mono<Long> count(Class<T> entityClass); | |
@NonNull | |
Mono<Boolean> existsById(@NonNull ID id, Class<T> entityClass); | |
@NonNull | |
Mono<T> findById(@NonNull ID id, Class<T> entityClass); |
This file contains 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
public class SoftDeleteRepositoryImpl<T extends AbstractSoftDeletableEntity, ID> implements SoftDeleteRepository<T, ID> { | |
private final R2dbcEntityOperations entityOperations; | |
private final R2dbcConverter converter; | |
public SoftDeleteRepositoryImpl(R2dbcEntityOperations entityOperations, R2dbcConverter converter) { | |
this.entityOperations = entityOperations; | |
this.converter = converter; | |
} | |
@NonNull |
This file contains 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
@Table("posts") | |
public class Post extends AbstractSoftDeletableEntity { | |
@Id | |
private Long id; | |
@Column("title") | |
public String title; | |
@Column("body") | |
public String body; |
This file contains 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
public abstract class AbstractSoftDeletableEntity extends AbstractAuditingEntity { | |
@JsonIgnore | |
@Column("deleted_date") | |
public Instant deletedDate; | |
} |
This file contains 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
private boolean isValidEmailAddress(String email) { | |
String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$"; | |
Pattern p = Pattern.compile(ePattern); | |
Matcher m = p.matcher(email); | |
return m.matches(); | |
} |