@POST @Path("/{registrationId}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response postUpdate( @Context HttpServletRequest request, @PathParam("registrationId") UUID id, String body) throws Exception { authService.guardAuthenticatedUser(request); Either<String, RegistrationsUpdate> map = ArgoUtils.parseEither(body) .right() .map(x -> x.getNode("tuple")) .right() .bind(RegistrationsRestService::registrationsUpdate); if (map.isLeft()) return Response.serverError().build(); RegistrationsUpdate ru = map.right().value(); try (Connection c = dataSource.getConnection()) { c.setAutoCommit(false); if (!registrationsSqlMapper.one(c, id).isSome()) return Response.status(Status.NOT_FOUND).build(); registrationsSqlMapper.update( c, id, ru.billingCompany, ru.badge, ru.dietaryRequirements, ru.bundle); c.commit(); } return Response.ok().build(); }
private static Either<String, RegistrationsUpdate> registrationsUpdate(JsonNode jsonNode) { Either<String, BillingCompany> billingCompany = ArgoUtils.stringValue(jsonNode, "billingCompany").right().map(BillingCompany::new); Either<String, Badge> badge = ArgoUtils.stringValue(jsonNode, "badge").right().map(Badge::new); Either<String, String> dietaryRequirements = ArgoUtils.stringValue(jsonNode, "dietaryRequirements"); Either<String, Option<String>> bundle = ArgoUtils.stringValue(jsonNode, "bundle") .right() .map(Option::fromNull) .right() .map(r -> r.filter(Strings.isNotNullOrEmpty)); return bundle .right() .apply( dietaryRequirements .right() .apply( badge .right() .apply( billingCompany .right() .apply(Either.right(Function.curry(RegistrationsUpdate::new)))))); }