<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 -->
<dependencyManagement>
<dependency>
<!-- FPI Framework BOM -->
<groupId>com.abavilla</groupId>
<artifactId>fpi-framework-bom</artifactId>
<version>1.1.1</version> <!-- replace with latest version -->
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencyManagement>
<dependencies>
<!-- FPI Framework Core dependency -->
<dependency>
<groupId>com.abavilla</groupId>
<artifactId>fpi-framework-core</artifactId>
</dependency>
</dependencies>
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@BsonDiscriminator
@MongoEntity(collection="students")
public class Student extends AbsMongoItem {
/** Student name */
private String name;
/** Student home address */
private String address;
/** Student gender */
private String gender;
// Getters and setters are generated by lombok
// during compile time, no need to specify them
}
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class StudentDto extends AbsDto {
/** Student name */
private String name;
/** Student gender */
private String gender;
// Getters and setters are generated by lombok
// during compile time, no need to specify them
}
@ApplicationScoped
public class StudentRepo
extends AbsMongoRepo<Student> {
// No need to specify a body as AbsMongoRepo
// extends from Panache repository, and already
// implements the basic CRUD methods
}
@Mapper(componentModel = MappingConstants.ComponentModel.CDI,
injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface StudentMapper
extends IDtoToEntityMapper<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
}
@ApplicationScoped
public class StudentSvc
// Alternatively, may extend with AbsRepoSvc if
// you need a customized repository
extends AbsSvc<StudentDto, Student> {
/** Mapstruct Mapper */
@Inject
StudentMapper mapper;
// Built in asynchronous (Mutiny) CRUD methods, all you
// have to specify are the mapping methods to convert
// a DTO to entity and vice versa
@Override
public StudentDto mapToDto(Student entity) {
return mapper.mapToDto(entity);
}
@Override
public Student mapToEntity(StudentDto dto) {
return mapper.mapToEntity(dto);
}
}
@Path("/fpi/cx")
public class StudentResource
// Alternatively, may extend from AbsBaseResource,
// or AbsReadOnlyResource for specific use case scenarios
extends AbsResource<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
// ...
}