FPI Reactive API backend Framework, built on top of Quarkus
JavaApache-2.0
Importing the POM (choose 1 option)
As Parent POM
<parent>
<!-- FPI Framework Parent POM -->
<groupId>com.abavilla</groupId>
<artifactId>fpi-framework-pom</artifactId>
<version>1.1.1</version> <!-- replace with latest version -->
</parent>
<!-- As dependencies are defined in parent POM no need to add FPI Framework Core as a dependency -->
@Data@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor@BsonDiscriminator@MongoEntity(collection="students")
publicclassStudentextendsAbsMongoItem {
/** Student name */privateStringname;
/** Student home address */privateStringaddress;
/** Student gender */privateStringgender;
// Getters and setters are generated by lombok// during compile time, no need to specify them
}
DTO (Data Transfer Object)
@Data@EqualsAndHashCode(callSuper = true)
@NoArgsConstructorpublicclassStudentDtoextendsAbsDto {
/** Student name */privateStringname;
/** Student gender */privateStringgender;
// Getters and setters are generated by lombok// during compile time, no need to specify them
}
Repository
@ApplicationScopedpublicclassStudentRepoextendsAbsMongoRepo<Student> {
// No need to specify a body as AbsMongoRepo// extends from Panache repository, and already// implements the basic CRUD methods
}
DTO to Entity Mapstruct Mapper
@Mapper(componentModel = MappingConstants.ComponentModel.CDI,
injectionStrategy = InjectionStrategy.CONSTRUCTOR)
publicinterfaceStudentMapperextendsIDtoToEntityMapper<StudentDto, Student> {
// Mapstruct will generate the mappings during compile time,// and mo need to specify a body as IDtoToEntityMapper specifies// the commonly used mapping methods
}
Service Layer
@ApplicationScopedpublicclassStudentSvc// Alternatively, may extend with AbsRepoSvc if// you need a customized repositoryextendsAbsSvc<StudentDto, Student> {
/** Mapstruct Mapper */@InjectStudentMappermapper;
// Built in asynchronous (Mutiny) CRUD methods, all you // have to specify are the mapping methods to convert// a DTO to entity and vice versa@OverridepublicStudentDtomapToDto(Studententity) {
returnmapper.mapToDto(entity);
}
@OverridepublicStudentmapToEntity(StudentDtodto) {
returnmapper.mapToEntity(dto);
}
}
REST Controller
@Path("/fpi/cx")
publicclassStudentResource// Alternatively, may extend from AbsBaseResource,// or AbsReadOnlyResource for specific use case scenarios extendsAbsResource<StudentDto, Student, StudentSvc> {
// ...// Built in asynchronous (Mutiny) CRUD methods for GET, POST,// PATCH, DELETE are implemented by default, you may customize// or add your own methods for specific requirements// ...
}