Package com.wesabe.grendel.resources

Source Code of com.wesabe.grendel.resources.DocumentsResource

package com.wesabe.grendel.resources;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;

import com.google.inject.Inject;
import com.wesabe.grendel.auth.Credentials;
import com.wesabe.grendel.auth.Session;
import com.wesabe.grendel.entities.Document;
import com.wesabe.grendel.entities.dao.UserDAO;
import com.wesabe.grendel.representations.DocumentListRepresentation;

/**
* A class which exposes a list of {@link Document}s as a resource.
*
* @author coda
*/
@Path("/users/{id}/documents")
@Produces(MediaType.APPLICATION_JSON)
public class DocumentsResource {
  final UserDAO userDAO;
 
  @Inject
  public DocumentsResource(UserDAO userDAO) {
    this.userDAO = userDAO;
  }
 
  @GET
  public DocumentListRepresentation listDocuments(@Context UriInfo uriInfo,
    @Context Credentials credentials, @PathParam("id") String id) {
   
    final Session session = credentials.buildSession(userDAO, id);
   
    return new DocumentListRepresentation(uriInfo, session.getUser().getDocuments());
  }
}
TOP

Related Classes of com.wesabe.grendel.resources.DocumentsResource

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.