-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
17 deletions.
There are no files selected for viewing
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
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
49 changes: 49 additions & 0 deletions
49
.../src/main/java/community/flock/wirespec/examples/spring_boot_integration/TodoService.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package community.flock.wirespec.examples.spring_boot_integration; | ||
|
||
import community.flock.wirespec.generated.Todo; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
|
||
@Service | ||
public class TodoService { | ||
|
||
public List<Todo> store = List.of( | ||
new Todo(UUID.randomUUID().toString(), "First todo", false), | ||
new Todo(UUID.randomUUID().toString(), "Second todo", false), | ||
new Todo(UUID.randomUUID().toString(), "Third todo", false) | ||
); | ||
|
||
public CompletableFuture<Todo> create(Todo todo) { | ||
store.add(todo); | ||
return CompletableFuture.completedFuture(todo); | ||
} | ||
|
||
public CompletableFuture<Todo> update(String id, Todo todo) { | ||
store = store.stream() | ||
.map(it -> { | ||
if (it.id().equals(id)) { | ||
return todo; | ||
} else { | ||
return it; | ||
} | ||
}) | ||
.collect(toList()); | ||
return CompletableFuture.completedFuture(todo); | ||
} | ||
|
||
public CompletableFuture<Todo> delete(String id) { | ||
return store.stream() | ||
.filter(todo -> todo.id().equals(id)) | ||
.findFirst() | ||
.map(todo -> { | ||
store.remove(todo); | ||
return CompletableFuture.completedFuture(todo); | ||
}) | ||
.orElseThrow(); | ||
} | ||
} |
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