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
/
Copy pathBiddingService.java
63 lines (54 loc) · 1.94 KB
/
BiddingService.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
/*
* Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com>
*/
package com.example.auction.bidding.api;
import static com.lightbend.lagom.javadsl.api.Service.named;
import static com.lightbend.lagom.javadsl.api.Service.pathCall;
import static com.lightbend.lagom.javadsl.api.Service.topic;
import akka.NotUsed;
import com.example.auction.security.SecurityHeaderFilter;
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 org.pcollections.PSequence;
import java.util.UUID;
/**
* The bidding services.
*
* This services manages all bids and lifecycle events associated with them.
*
* An auction is created when an AuctionStarted event is received, then bids can be placed, and when the end date
* specified in AuctionStarted is reached, this service will published a BiddingFinished event with the winning
* bidder (if there was one).
*/
public interface BiddingService extends Service {
String TOPIC_ID = "bidding-BidEvent";
/**
* A place a bid.
*
* @param itemId The item to bid on.
*/
ServiceCall<PlaceBid, BidResult> placeBid(UUID itemId);
/**
* Get the bids for an item.
*
* @param itemId The item to get the bids for.
*/
ServiceCall<NotUsed, PSequence<Bid>> getBids(UUID itemId);
/**
* The bid events topic.
*/
Topic<BidEvent> bidEvents();
@Override
default Descriptor descriptor() {
return named("bidding").withCalls(
pathCall("/api/item/:id/bids", this::placeBid),
pathCall("/api/item/:id/bids", this::getBids)
).withTopics(
topic(TOPIC_ID, this::bidEvents)
).withPathParamSerializer(UUID.class, PathParamSerializers.required("UUID", UUID::fromString, UUID::toString))
.withHeaderFilter(SecurityHeaderFilter.INSTANCE);
}
}