use of com.webank.wedatasphere.qualitis.response.DepartmentResponse in project Qualitis by WeBankFinTech.
the class DepartmentServiceImpl method addDepartment.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<DepartmentResponse> addDepartment(DepartmentAddRequest request) throws UnExpectedRequestException {
Department departmentInDb = departmentDao.findByName(request.getDepartmentName());
if (departmentInDb != null) {
LOGGER.error("Department already exist.");
throw new UnExpectedRequestException("Department {&ALREADY_EXIST}");
}
Department department = new Department();
department.setName(request.getDepartmentName());
Department savedDepartment = departmentDao.saveDepartment(department);
LOGGER.info("Succeed to create department, saved department info is : {}", savedDepartment.toString());
return new GeneralResponse<>("200", "{&ADD_DEPARTMENT_SUCCESSFULLY}", new DepartmentResponse(savedDepartment));
}
use of com.webank.wedatasphere.qualitis.response.DepartmentResponse in project Qualitis by WeBankFinTech.
the class DepartmentServiceImpl method findAllDepartment.
@Override
public GeneralResponse<GetAllResponse<DepartmentResponse>> findAllDepartment(PageRequest request) throws UnExpectedRequestException {
PageRequest.checkRequest(request);
int page = request.getPage();
int size = request.getSize();
long total = departmentDao.countDepartment();
List<Department> departmentList = departmentDao.findAllDepartment(page, size);
List<DepartmentResponse> departmentResponses = new ArrayList<>(departmentList.size());
for (Department department : departmentList) {
departmentResponses.add(new DepartmentResponse(department));
}
GetAllResponse<DepartmentResponse> responses = new GetAllResponse<>();
responses.setData(departmentResponses);
responses.setTotal(total);
LOGGER.info("Succeed to find all departments, page: {}, size: {}, departments: {}", page, size, responses);
return new GeneralResponse("200", "{&GET_DEPARTMENT_SUCCESSFULLY}", responses);
}
Aggregations