This repository has been archived by the owner on May 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
ItemService.java
97 lines (82 loc) · 3 KB
/
ItemService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com>
*/
package com.example.auction.item.api;
import akka.Done;
import akka.NotUsed;
import com.example.auction.security.SecurityHeaderFilter;
import com.example.auction.pagination.PaginatedSequence;
import com.lightbend.lagom.javadsl.api.Descriptor;
import com.lightbend.lagom.javadsl.api.Service;
import com.lightbend.lagom.javadsl.api.ServiceCall;
import com.lightbend.lagom.javadsl.api.broker.Topic;
import com.lightbend.lagom.javadsl.api.deser.PathParamSerializers;
import com.lightbend.lagom.javadsl.api.transport.Method;
import java.util.Optional;
import java.util.UUID;
import static com.lightbend.lagom.javadsl.api.Service.*;
/**
* The item service.
* Manages the lifecycle of items, as well properties on them.
*/
public interface ItemService extends Service {
String TOPIC_ID = "item-ItemEvent";
/**
* Create an item.
*
* @return The created item with its ID populated.
*/
ServiceCall<ItemData, Item> createItem();
/**
* Update an item.
*
* @param id The ID of the item to update.
* @return Done.
*/
ServiceCall<ItemData, Item> updateItem(UUID id);
/**
* Start an auction for an item.
*
* @param id The id of the item to start the auction for.
* @return Done if the auction was started.
*/
ServiceCall<NotUsed, Done> startAuction(UUID id);
/**
* Get an item with the given ID.
*
* @param id The ID of the item to get.
* @return The item.
*/
ServiceCall<NotUsed, Item> getItem(UUID id);
/**
* Get a list of items for the given user.
*
* @param id The ID of the user.
* @param status The status of items to return.
* @param pageNo The page number, starting from zero.
* @param pageSize The number of items to return per page.
* @return The sequence of items.
*/
ServiceCall<NotUsed, PaginatedSequence<ItemSummary>> getItemsForUser(
UUID id, ItemStatus status, Optional<Integer> pageNo, Optional<Integer> pageSize);
/**
* The item events stream.
*/
Topic<ItemEvent> itemEvents();
@Override
default Descriptor descriptor() {
return named("item").withCalls(
pathCall("/api/item", this::createItem),
restCall(Method.POST, "/api/item/:id/start", this::startAuction),
pathCall("/api/item/:id", this::getItem),
restCall(Method.PUT, "/api/item/:id", this::updateItem),
pathCall("/api/item?userId&status&pageNo&pageSize", this::getItemsForUser)
).withTopics(
topic(TOPIC_ID, this::itemEvents)
).withPathParamSerializer(
UUID.class, PathParamSerializers.required("UUID", UUID::fromString, UUID::toString)
).withPathParamSerializer(
ItemStatus.class, PathParamSerializers.required("ItemStatus", ItemStatus::valueOf, ItemStatus::toString)
).withHeaderFilter(SecurityHeaderFilter.INSTANCE);
}
}