1
1
package controllers ;
2
2
3
- import com .example .auction .item .api .ItemStatus ;
4
3
import com .example .auction .pagination .PaginatedSequence ;
5
4
import com .example .auction .transaction .api .*;
6
5
import com .example .auction .user .api .User ;
7
6
import com .example .auction .user .api .UserService ;
8
- import com .lightbend .lagom .javadsl .api .transport .TransportException ;
9
7
import com .typesafe .config .Config ;
10
8
import play .data .Form ;
11
9
import play .data .FormFactory ;
@@ -96,7 +94,7 @@ public CompletionStage<Result> getTransaction(String id) {
96
94
Currency currency = Currency .valueOf (transaction .getItemData ().getCurrencyId ());
97
95
return ok (views .html .transaction .render (showInlineInstruction , Optional .of (transaction ), seller , winner , Optional .of (currency ), Optional .empty (), nav ));
98
96
} else {
99
- String msg = (( TransportException ) exception .getCause ()). exceptionMessage (). detail ();
97
+ String msg = exception .getCause (). getMessage ();
100
98
return ok (views .html .transaction .render (showInlineInstruction , Optional .empty (), Optional .empty (), Optional .empty (), Optional .empty (), Optional .of (msg ), nav ));
101
99
}
102
100
});
@@ -132,7 +130,7 @@ public CompletionStage<Result> submitDeliveryDetailsForm(String id) {
132
130
nav )
133
131
);
134
132
} else {
135
- String msg = (( TransportException ) exception .getCause ()). exceptionMessage (). detail ();
133
+ String msg = exception .getCause (). getMessage ();
136
134
return ok (views .html .deliveryDetails .render (showInlineInstruction , false , itemId , formFactory .form (DeliveryDetailsForm .class ), TransactionInfoStatus .NEGOTIATING_DELIVERY , Optional .of (msg ), nav ));
137
135
}
138
136
});
@@ -162,7 +160,7 @@ public CompletionStage<Result> submitDeliveryDetails(String id, String transacti
162
160
if (exception == null ) {
163
161
return CompletableFuture .completedFuture (redirect (routes .TransactionController .getTransaction (id )));
164
162
} else {
165
- String msg = (( TransportException ) exception .getCause ()). exceptionMessage (). detail ();
163
+ String msg = exception .getCause (). getMessage ();
166
164
return loadNav (user ).thenApplyAsync (nav ->
167
165
ok (views .html .deliveryDetails .render (showInlineInstruction , isBuyer , itemId , form , status , Optional .of (msg ), nav )),
168
166
ec .current ());
@@ -182,4 +180,66 @@ private DeliveryInfo fromForm(DeliveryDetailsForm deliveryForm) {
182
180
deliveryForm .getCountry ()
183
181
);
184
182
}
183
+
184
+ public CompletionStage <Result > setDeliveryPriceForm (String id ) {
185
+ return requireUser (ctx (), user ->
186
+ loadNav (user ).thenComposeAsync (nav -> {
187
+ UUID itemId = UUID .fromString (id );
188
+ CompletionStage <TransactionInfo > transactionFuture = transactionService .getTransaction (itemId ).handleRequestHeader (authenticate (user )).invoke ();
189
+ return transactionFuture .handle ((transaction , exception ) -> {
190
+ if (exception == null ) {
191
+ DeliveryPriceForm form = new DeliveryPriceForm ();
192
+ Optional <Integer > maybeDeliveryPrice = transaction .getDeliveryPrice ();
193
+ if (maybeDeliveryPrice .isPresent ())
194
+ form .setDeliveryPrice (maybeDeliveryPrice .get ());
195
+ return ok (
196
+ views .html .deliveryPrice .render (
197
+ showInlineInstruction ,
198
+ transaction .getCreator ().equals (user ),
199
+ itemId ,
200
+ formFactory .form (DeliveryPriceForm .class ).fill (form ),
201
+ transaction .getStatus (),
202
+ Optional .empty (),
203
+ nav )
204
+ );
205
+ } else {
206
+ String msg = exception .getCause ().getMessage ();
207
+ return ok (views .html .deliveryPrice .render (showInlineInstruction , false , itemId , formFactory .form (DeliveryPriceForm .class ), TransactionInfoStatus .NEGOTIATING_DELIVERY , Optional .of (msg ), nav ));
208
+ }
209
+ });
210
+ },
211
+ ec .current ())
212
+ );
213
+ }
214
+
215
+ public CompletionStage <Result > setDeliveryPrice (String id , String transactionStatus , boolean isSeller ) {
216
+ Http .Context ctx = ctx ();
217
+ return requireUser (ctx (), user -> {
218
+
219
+ Form <DeliveryPriceForm > form = formFactory .form (DeliveryPriceForm .class ).bindFromRequest (ctx .request ());
220
+ UUID itemId = UUID .fromString (id );
221
+ TransactionInfoStatus status = TransactionInfoStatus .valueOf (transactionStatus );
222
+
223
+ if (form .hasErrors ()) {
224
+ return loadNav (user ).thenApplyAsync (nav ->
225
+ ok (views .html .deliveryPrice .render (showInlineInstruction , isSeller , itemId , form , status , Optional .empty (), nav )),
226
+ ec .current ()
227
+ );
228
+ } else {
229
+ return transactionService .setDeliveryPrice (itemId )
230
+ .handleRequestHeader (authenticate (user ))
231
+ .invoke (form .get ().getDeliveryPrice ())
232
+ .handle ((done , exception ) -> {
233
+ if (exception == null ) {
234
+ return CompletableFuture .completedFuture (redirect (routes .TransactionController .getTransaction (id )));
235
+ } else {
236
+ String msg = exception .getCause ().getMessage ();
237
+ return loadNav (user ).thenApplyAsync (nav ->
238
+ ok (views .html .deliveryPrice .render (showInlineInstruction , isSeller , itemId , form , status , Optional .of (msg ), nav )),
239
+ ec .current ());
240
+ }
241
+ }).thenComposeAsync (x -> x , ec .current ());
242
+ }
243
+ });
244
+ }
185
245
}
0 commit comments