Skip to content

Instantly share code, notes, and snippets.

@evrentan
Created April 1, 2021 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evrentan/00366b5d43cc8919e076b42095fe68c0 to your computer and use it in GitHub Desktop.
Save evrentan/00366b5d43cc8919e076b42095fe68c0 to your computer and use it in GitHub Desktop.
EnterpriseService with MapStruct Methods
package com.tan.example.service;
import com.tan.example.dto.Enterprise;
import com.tan.example.entity.EnterpriseEntity;
import com.tan.example.mapper.EnterpriseMapper;
import org.bson.types.ObjectId;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import javax.validation.Valid;
import java.util.List;
@ApplicationScoped
@Transactional(Transactional.TxType.REQUIRED)
public class EnterpriseService implements EnterpriseInterface {
@Inject
EnterpriseMapper enterpriseMapper;
public List<Enterprise> findAllEnterprises() {
return this.enterpriseMapper.toDtoList(EnterpriseEntity.listAll());
}
public Enterprise findEnterpriseById(String id) {
final ObjectId enterpriseId = new ObjectId(id);
return this.enterpriseMapper.toDto(EnterpriseEntity.findById(enterpriseId));
}
public Enterprise createEnterprise(@Valid Enterprise enterprise) {
EnterpriseEntity enterpriseEntity = this.enterpriseMapper.toEntity(enterprise);
EnterpriseEntity.persist(enterpriseEntity);
return this.enterpriseMapper.toDto(enterpriseEntity);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment