Search in sources :

Example 1 with AccountEmailJson

use of org.killbill.billing.jaxrs.json.AccountEmailJson in project killbill by killbill.

the class AccountResource method getEmails.

/*
     * *************************     EMAILS     *****************************
     */
@TimedResource
@GET
@Path("/{accountId:" + UUID_PATTERN + "}/" + EMAILS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve an account emails", response = AccountEmailJson.class, responseContainer = "List")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied") })
public Response getEmails(@PathParam(ID_PARAM_NAME) final String id, @javax.ws.rs.core.Context final HttpServletRequest request) {
    final UUID accountId = UUID.fromString(id);
    final List<AccountEmail> emails = accountUserApi.getEmails(accountId, context.createContext(request));
    final List<AccountEmailJson> emailsJson = new ArrayList<AccountEmailJson>();
    for (final AccountEmail email : emails) {
        emailsJson.add(new AccountEmailJson(email.getAccountId().toString(), email.getEmail()));
    }
    return Response.status(Status.OK).entity(emailsJson).build();
}
Also used : AccountEmailJson(org.killbill.billing.jaxrs.json.AccountEmailJson) AccountEmail(org.killbill.billing.account.api.AccountEmail) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with AccountEmailJson

use of org.killbill.billing.jaxrs.json.AccountEmailJson in project killbill by killbill.

the class AccountResource method removeEmail.

@TimedResource
@DELETE
@Path("/{accountId:" + UUID_PATTERN + "}/" + EMAILS + "/{email}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Delete email from account")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id supplied") })
public Response removeEmail(@PathParam(ID_PARAM_NAME) final String id, @PathParam("email") final String email, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) {
    final UUID accountId = UUID.fromString(id);
    final List<AccountEmail> emails = accountUserApi.getEmails(accountId, context.createContext(request));
    for (final AccountEmail cur : emails) {
        if (cur.getEmail().equals(email)) {
            final AccountEmailJson accountEmailJson = new AccountEmailJson(accountId.toString(), email);
            final AccountEmail accountEmail = accountEmailJson.toAccountEmail(cur.getId());
            accountUserApi.removeEmail(accountId, accountEmail, context.createContext(createdBy, reason, comment, request));
        }
    }
    return Response.status(Status.OK).build();
}
Also used : AccountEmailJson(org.killbill.billing.jaxrs.json.AccountEmailJson) AccountEmail(org.killbill.billing.account.api.AccountEmail) UUID(java.util.UUID) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 UUID (java.util.UUID)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 AccountEmail (org.killbill.billing.account.api.AccountEmail)2 AccountEmailJson (org.killbill.billing.jaxrs.json.AccountEmailJson)2 TimedResource (org.killbill.commons.metrics.TimedResource)2 ArrayList (java.util.ArrayList)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1