Skip to content

Commit

Permalink
fake inmemory implementation of service
Browse files Browse the repository at this point in the history
just to manually verify our web pages
  • Loading branch information
bettini authored and LorenzoBettini committed Apr 27, 2021
1 parent 972d0ad commit 49fba8d
Showing 1 changed file with 23 additions and 8 deletions.
@@ -1,32 +1,47 @@
package com.examples.spring.demo.services;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.examples.spring.demo.model.Employee;

/**
* Temporary fake implementation of service.
* Temporary implementation just to make some manual tests.
* During the tests this will be mocked anyway.
*/
@Service
public class EmployeeService {

private static final String TEMPORARY_IMPLEMENTATION = "Temporary implementation";
private Map<Long, Employee> employees = new LinkedHashMap<>();

public EmployeeService() {
employees.put(1L, new Employee(1L, "John Doe", 1000));
employees.put(2L, new Employee(2L, "John Smith", 2000));
}

public List<Employee> getAllEmployees() {
throw new UnsupportedOperationException(TEMPORARY_IMPLEMENTATION);
return new LinkedList<>(employees.values());
}

public Employee getEmployeeById(long id) {
throw new UnsupportedOperationException(TEMPORARY_IMPLEMENTATION);
public Employee getEmployeeById(long i) {
return employees.get(i);
}

public Employee insertNewEmployee(Employee employee) {
throw new UnsupportedOperationException(TEMPORARY_IMPLEMENTATION);
// dumb way of generating an automatic ID
employee.setId(employees.size()+1L);
employees.put(employee.getId(), employee);
return employee;
}

public Employee updateEmployeeById(long id, Employee replacement) {
throw new UnsupportedOperationException(TEMPORARY_IMPLEMENTATION);
replacement.setId(id);
employees.put(replacement.getId(), replacement);
return replacement;
}
}

}

0 comments on commit 49fba8d

Please sign in to comment.