Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fake inmemory implementation of service
just to manually verify our web pages
- Loading branch information
1 parent
972d0ad
commit 49fba8d
Showing
1 changed file
with
23 additions
and
8 deletions.
There are no files selected for viewing
31 changes: 23 additions & 8 deletions
31
src/main/java/com/examples/spring/demo/services/EmployeeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|
||
} |