Skip to content
This repository has been archived by the owner on May 9, 2019. It is now read-only.

Commit

Permalink
UI for submit delivery details finished
Browse files Browse the repository at this point in the history
  • Loading branch information
yg-apaza committed Jun 3, 2017
1 parent b8effcb commit 66d90e8
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface TransactionService extends Service {
@Override
default Descriptor descriptor() {
return named("transaction").withCalls(
pathCall("/api/item/:id/transaction", this::submitDeliveryDetails)
pathCall("/api/transaction/:id", this::submitDeliveryDetails)
).withPathParamSerializer(UUID.class, PathParamSerializers.required("UUID", UUID::fromString, UUID::toString))
.withHeaderFilter(SecurityHeaderFilter.INSTANCE);

Expand Down
61 changes: 61 additions & 0 deletions web-gateway/app/controllers/DeliveryDetailsForm.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
package controllers;

import play.data.validation.Constraints;

public class DeliveryDetailsForm {
@Constraints.Required
private String addressLine1;
@Constraints.Required
private String addressLine2;
@Constraints.Required
private String city;
@Constraints.Required
private String state;
@Constraints.Required
private int postalCode;
@Constraints.Required
private String country;

public String getAddressLine1() {
return addressLine1;
}

public void setAddressLine1(String addressLine1) {
this.addressLine1 = addressLine1;
}

public String getAddressLine2() {
return addressLine2;
}

public void setAddressLine2(String addressLine2) {
this.addressLine2 = addressLine2;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public int getPostalCode() {
return postalCode;
}

public void setPostalCode(int postalCode) {
this.postalCode = postalCode;
}

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}
}
73 changes: 70 additions & 3 deletions web-gateway/app/controllers/TransactionController.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
package controllers;

import akka.japi.Pair;
import com.example.auction.bidding.api.BiddingService;
import com.example.auction.item.api.Item;
import com.example.auction.item.api.ItemData;
import com.example.auction.item.api.ItemService;
import com.example.auction.item.api.ItemStatus;
import com.example.auction.transaction.api.DeliveryInfo;
import com.example.auction.transaction.api.TransactionService;
import com.example.auction.user.api.UserService;
import com.lightbend.lagom.javadsl.api.transport.TransportException;
import controllers.*;
import play.Configuration;
import play.data.Form;
import play.data.FormFactory;
import play.i18n.MessagesApi;
import play.mvc.Http;
import play.mvc.Result;
import views.html.editItem;

import javax.inject.Inject;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import static com.example.auction.security.ClientSecurity.authenticate;

public class TransactionController extends AbstractController {
private final FormFactory formFactory;
private final TransactionService transactionService;
Expand All @@ -28,11 +45,61 @@ public TransactionController(Configuration config, MessagesApi messagesApi, User
showInlineInstruction = config.getBoolean("online-auction.instruction.show");
}

public CompletionStage<Result> submitDeliveryDetailsForm() {
public CompletionStage<Result> submitDeliveryDetailsForm(String id) {
return requireUser(ctx(), user ->
loadNav(user).thenApply(nav ->
ok(views.html.createItem.render(showInlineInstruction, formFactory.form(DeliveryDetailsForm.class).fill(new DeliveryDetailsForm()), nav))
loadNav(user).thenApply(nav -> {
UUID itemId = UUID.fromString(id);
// TODO: Fill with deliveryForm with data
return ok(
views.html.deliveryDetails.render(
showInlineInstruction,
itemId,
formFactory.form(DeliveryDetailsForm.class).fill(new DeliveryDetailsForm()),
Optional.empty(),
nav)
);

}
)
);
}

public CompletionStage<Result> submitDeliveryDetails(String id) {
Http.Context ctx = ctx();
return requireUser(ctx(), user -> {

Form<DeliveryDetailsForm> form = formFactory.form(DeliveryDetailsForm.class).bindFromRequest(ctx.request());
UUID itemId = UUID.fromString(id);

if (form.hasErrors()) {
return loadNav(user).thenApply(nav ->
ok(views.html.deliveryDetails.render(showInlineInstruction, itemId, form, Optional.empty(), nav))
);
} else {
return transactionService.submitDeliveryDetails(itemId)
.handleRequestHeader(authenticate(user))
.invoke(fromForm(form.get()))
.handle((done, exception) -> {
if(exception == null) {
return CompletableFuture.completedFuture(redirect(controllers.routes.TransactionController.submitDeliveryDetailsForm(id)));
} else {
String msg = ((TransportException) exception.getCause()).exceptionMessage().detail();
return loadNav(user).thenApply(nav -> ok(
views.html.deliveryDetails.render(showInlineInstruction, itemId, form, Optional.of(msg), nav)));
}
}).thenCompose((x) -> x);
}
});
}

private DeliveryInfo fromForm(DeliveryDetailsForm deliveryForm) {
return new DeliveryInfo(
deliveryForm.getAddressLine1(),
deliveryForm.getAddressLine2(),
deliveryForm.getCity(),
deliveryForm.getState(),
deliveryForm.getPostalCode(),
deliveryForm.getCountry()
);
}
}
41 changes: 38 additions & 3 deletions web-gateway/app/views/deliveryDetails.scala.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
@(showInlineInstruction: Boolean, deliveryForm: Form[DeliveryDetailsForm])(implicit nav: Nav)
@import helper._
@import java.util.Optional
@import java.util.UUID

@(showInlineInstruction: Boolean, itemId: UUID, deliveryForm: Form[DeliveryDetailsForm], errorMessage: Optional[String])(implicit nav: Nav)

@* TODO: Get transaction status to show or not read-only inputs *@
@main(message("deliveryDetails")) {

<h2>@message("deliveryDetails")</h2>

@foundationForm(deliveryForm, routes.ItemController.createItem()) {
@if(showInlineInstruction == true) {
<p>@message("instruction.deliveryDetails")</p>
}

@foundationForm(deliveryForm, routes.TransactionController.submitDeliveryDetails(itemId.toString)) {
@if(errorMessage.isPresent) {
<div class="alert callout">
<i class="fi-alert"></i> @errorMessage.get()
</div>
}

<div class="column row">
@inputText(deliveryForm("addressLine1"))
</div>
<div class="column row">
@inputText(deliveryForm("addressLine2"))
</div>
<div class="column row">
@inputText(deliveryForm("city"))
</div>
<div class="column row">
@inputText(deliveryForm("state"))
</div>
<div class="column row">
@inputText(deliveryForm("postalCode"), 'type -> "number")
</div>
<div class="column row">
@inputText(deliveryForm("country"))
</div>

<input type="submit" class="button" value="@message("submitDeliveryDetails")"/>
}
}
}
5 changes: 4 additions & 1 deletion web-gateway/conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,7 @@ instruction.auctionCancelled=The auction has been cancelled for this item.
instruction.search=Here you can search for auctioned items. You can filter your search by specifying the maximum price of items to search for and the currency to search in.
instruction.enableSearch=Search functionality can be enabled by downloading and running a local instance of elasticsearch. Steps for doing this can be found in {0}. If the lagom system is up and running, you don't need to restart the system after installing and running elasticsearch; the search service becomes functional once it starts.

deliveryDetails=Delivery Details
instruction.deliveryDetails=Here you can submit the delivery details for the transaction

deliveryDetails=Delivery Details
submitDeliveryDetails=Submit
1 change: 1 addition & 0 deletions web-gateway/conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ GET /assets/*file controllers.Assets.at(path = "/public",

# Transaction
GET /transaction/:id/delivery controllers.TransactionController.submitDeliveryDetailsForm(id)
POST /transaction/:id/delivery controllers.TransactionController.submitDeliveryDetails(id)

0 comments on commit 66d90e8

Please sign in to comment.