Class AbstractCreateService<CreateForm extends AbstractCreateForm,Entity extends AbstractEntity,Model,CreateRepository extends org.springframework.data.repository.CrudRepository<Entity,Long>>

java.lang.Object
fr.tiogars.architecture.create.services.AbstractCreateService<CreateForm,Entity,Model,CreateRepository>
Type Parameters:
CreateForm - the type of the form used to create an entity
Entity - the type of the entity being created
Model - the type of the model used in the service
CreateRepository - the type of the repository used for CRUD operations

public abstract class AbstractCreateService<CreateForm extends AbstractCreateForm,Entity extends AbstractEntity,Model,CreateRepository extends org.springframework.data.repository.CrudRepository<Entity,Long>> extends Object
Abstract class for create services. This class can be extended to implement specific create operations for different entities.
  • Field Details

    • crudRepository

      public org.springframework.data.repository.CrudRepository<Entity extends AbstractEntity,Long> crudRepository
      The CrudRepository used for database operations. This repository should be injected in the constructor and is used to perform CRUD operations on the entity type.
  • Constructor Details

    • AbstractCreateService

      public AbstractCreateService()
      Default constructor for the AbstractCreateService. This constructor is provided for cases where dependency injection is not used.
    • AbstractCreateService

      public AbstractCreateService(CreateRepository crudRepository)
      Constructor for the AbstractCreateService. Initializes the CrudRepository used for database operations.
      Parameters:
      crudRepository - the CrudRepository for the entity
  • Method Details

    • toEntity

      public abstract Entity toEntity(Model model)
      Converts a CreateForm to an Entity. This method should be implemented by subclasses to define how the conversion is done.
      Parameters:
      model - the model containing data to create the entity
      Returns:
      the entity created from the model
    • toModel

      public abstract Model toModel(Entity entity)
      Converts an UpdateRequest to an Entity. This method should be implemented by subclasses to define how the conversion is done.
      Parameters:
      entity - the entity
      Returns:
      the model
    • toModel

      public abstract Model toModel(CreateForm createForm)
      Converts a CreateForm to a Model. This method should be implemented by subclasses to define how the conversion is done.
      Parameters:
      createForm - the form containing data to create the model
      Returns:
      the model created from the form
    • validate

      public abstract void validate(Model model)
      Validates the provided model. This method should be implemented by subclasses to define how the validation is done.
      Parameters:
      model - the model to validate
    • create

      public Model create(CreateForm createForm)
      Creates a new entity based on the provided CreateForm.
      Parameters:
      createForm - the form containing data to create the entity
      Returns:
      a response containing the ID of the created entity