Package resources.article

Source Code of resources.article.SlugResource

package resources.article;

import static utils.ResourceHelper.notFoundIfNull;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response.Status;

import models.Article;
import models.User;
import views.ArticleView;

import com.yammer.dropwizard.auth.Auth;

import daos.ArticleDao;

@Path("/article/{slug}")
public class SlugResource {

    private ArticleDao dao;

    public SlugResource(ArticleDao dao) {
        this.dao = dao;
    }

    @DELETE
    public void deleteArticle(@Auth User user, @PathParam("slug") String slug) {
        if (!dao.deleteBySlug(slug)) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }

        throw new WebApplicationException(Status.NO_CONTENT);
    }

    @GET
    public ArticleView getArticle(@PathParam("slug") String slug) {
        Article article = dao.findBySlug(slug);
        notFoundIfNull(article);

        return new ArticleView(article);
    }

}
TOP

Related Classes of resources.article.SlugResource

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.