Java Code Examples for io.vertx.reactivex.ext.web.RoutingContext#pathParam()
The following examples show how to use
io.vertx.reactivex.ext.web.RoutingContext#pathParam() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserProfileApiVerticle.java From vertx-in-action with MIT License | 6 votes |
private void fetchUser(RoutingContext ctx) { String username = ctx.pathParam("username"); JsonObject query = new JsonObject() .put("username", username); JsonObject fields = new JsonObject() .put("_id", 0) .put("username", 1) .put("email", 1) .put("deviceId", 1) .put("city", 1) .put("makePublic", 1); mongoClient .rxFindOne("user", query, fields) .toSingle() .subscribe( json -> completeFetchRequest(ctx, json), err -> handleFetchError(ctx, err)); }
Example 2
Source File: UserProfileApiVerticle.java From vertx-in-action with MIT License | 6 votes |
private void whoOwns(RoutingContext ctx) { String deviceId = ctx.pathParam("deviceId"); JsonObject query = new JsonObject() .put("deviceId", deviceId); JsonObject fields = new JsonObject() .put("_id", 0) .put("username", 1) .put("deviceId", 1); mongoClient .rxFindOne("user", query, fields) .toSingle() .subscribe( json -> completeFetchRequest(ctx, json), err -> handleFetchError(ctx, err)); }
Example 3
Source File: ActivityApiVerticle.java From vertx-in-action with MIT License | 6 votes |
private void stepsOnMonth(RoutingContext ctx) { try { String deviceId = ctx.pathParam("deviceId"); LocalDateTime dateTime = LocalDateTime.of( Integer.parseInt(ctx.pathParam("year")), Integer.parseInt(ctx.pathParam("month")), 1, 0, 0); Tuple params = Tuple.of(deviceId, dateTime); pgPool .preparedQuery(SqlQueries.monthlyStepsCount()) .rxExecute(params) .map(rs -> rs.iterator().next()) .subscribe( row -> sendCount(ctx, row), err -> handleError(ctx, err)); } catch (DateTimeException | NumberFormatException e) { sendBadRequest(ctx); } }
Example 4
Source File: ActivityApiVerticle.java From vertx-in-action with MIT License | 6 votes |
private void stepsOnDay(RoutingContext ctx) { try { String deviceId = ctx.pathParam("deviceId"); LocalDateTime dateTime = LocalDateTime.of( Integer.parseInt(ctx.pathParam("year")), Integer.parseInt(ctx.pathParam("month")), Integer.parseInt(ctx.pathParam("day")), 0, 0); Tuple params = Tuple.of(deviceId, dateTime); pgPool .preparedQuery(SqlQueries.dailyStepsCount()) .rxExecute(params) .map(rs -> rs.iterator().next()) .subscribe( row -> sendCount(ctx, row), err -> handleError(ctx, err)); } catch (DateTimeException | NumberFormatException e) { sendBadRequest(ctx); } }
Example 5
Source File: UserProfileApiVerticle.java From vertx-in-action with MIT License | 5 votes |
private void updateUser(RoutingContext ctx) { String username = ctx.pathParam("username"); JsonObject body = jsonBody(ctx); JsonObject query = new JsonObject().put("username", username); JsonObject updates = new JsonObject(); if (body.containsKey("city")) { updates.put("city", body.getString("city")); } if (body.containsKey("email")) { updates.put("email", body.getString("email")); } if (body.containsKey("makePublic")) { updates.put("makePublic", body.getBoolean("makePublic")); } if (updates.isEmpty()) { ctx.response() .setStatusCode(200) .end(); return; } updates = new JsonObject() .put("$set", updates); mongoClient .rxFindOneAndUpdate("user", query, updates) .ignoreElement() .subscribe( () -> completeEmptySuccess(ctx), err -> handleUpdateError(ctx, err)); }
Example 6
Source File: ActivityApiVerticle.java From vertx-in-action with MIT License | 5 votes |
private void totalSteps(RoutingContext ctx) { String deviceId = ctx.pathParam("deviceId"); Tuple params = Tuple.of(deviceId); pgPool .preparedQuery(SqlQueries.totalStepsCount()) .rxExecute(params) .map(rs -> rs.iterator().next()) .subscribe( row -> sendCount(ctx, row), err -> handleError(ctx, err)); }
Example 7
Source File: PublicApiVerticle.java From vertx-in-action with MIT License | 5 votes |
private void monthlySteps(RoutingContext ctx) { String deviceId = ctx.user().principal().getString("deviceId"); String year = ctx.pathParam("year"); String month = ctx.pathParam("month"); webClient .get(3001, "localhost", "/" + deviceId + "/" + year + "/" + month) .as(BodyCodec.jsonObject()) .rxSend() .subscribe( resp -> forwardJsonOrStatusCode(ctx, resp), err -> sendBadGateway(ctx, err)); }
Example 8
Source File: PublicApiVerticle.java From vertx-in-action with MIT License | 5 votes |
private void dailySteps(RoutingContext ctx) { String deviceId = ctx.user().principal().getString("deviceId"); String year = ctx.pathParam("year"); String month = ctx.pathParam("month"); String day = ctx.pathParam("day"); webClient .get(3001, "localhost", "/" + deviceId + "/" + year + "/" + month + "/" + day) .as(BodyCodec.jsonObject()) .rxSend() .subscribe( resp -> forwardJsonOrStatusCode(ctx, resp), err -> sendBadGateway(ctx, err)); }
Example 9
Source File: FakeUserService.java From vertx-in-action with MIT License | 5 votes |
private void owns(RoutingContext ctx) { logger.info("Device ownership request {}", ctx.request().path()); deviceId = ctx.pathParam("deviceId"); JsonObject notAllData = new JsonObject() .put("username", "Foo") .put("deviceId", deviceId); ctx.response() .putHeader("Content-Type", "application/json") .end(notAllData.encode()); }
Example 10
Source File: SuperHeroesService.java From rxjava2-lab with Apache License 2.0 | 5 votes |
private void getById(RoutingContext rc, Map<Integer, Character> map) { String id = rc.pathParam("id"); try { Integer value = Integer.valueOf(id); Character character = map.get(value); if (character == null) { rc.response().setStatusCode(404).end("Unknown hero " + id); } else { rc.response().end(character.toJson().encodePrettily()); } } catch (NumberFormatException e) { rc.response().setStatusCode(404).end("Unknown hero " + id); } }
Example 11
Source File: MyFirstVerticle.java From introduction-to-eclipse-vertx with Apache License 2.0 | 4 votes |
private void deleteOne(RoutingContext rc) { String id = rc.pathParam("id"); connect() .flatMapCompletable(connection -> delete(connection, id)) .subscribe(noContent(rc), onError(rc)); }
Example 12
Source File: MyFirstVerticle.java From introduction-to-eclipse-vertx with Apache License 2.0 | 4 votes |
private void getOne(RoutingContext rc) { String id = rc.pathParam("id"); connect() .flatMap(connection -> queryOne(connection, id)) .subscribe(ok(rc)); }