package org.apache.saltedpeanuts.handler;


import com.bardframework.bard.basic.marker.Doc;
import com.bardframework.bard.basic.marker.EscapeHTML;
import com.bardframework.bard.basic.marker.Required;
import com.bardframework.bard.core.Handler;
import com.bardframework.bard.util.db.marker.DBSession;
import com.bardframework.bard.util.user.marker.LoginUser;
import org.apache.saltedpeanuts.model.Article;
import org.apache.saltedpeanuts.model.User;
import org.hibernate.Session;

import javax.ws.rs.*;


@Path("/article")
public class ArticleHandler extends Handler {
    @DBSession public Session dbSession;
    @LoginUser @Required("Auth token error") public String userId;

    @PUT
    @Path("/")
    @Doc("Create an article")
    public Article createArticle(
        @FormParam("title") @Required String title,
        @FormParam("content") @EscapeHTML @Required String content
    ) {
        Article article = new Article();
        article.author = new User(userId);
        article.title = title;
        article.content = content;
        dbSession.save(article);
        return article;
    }

    @GET
    @Path("/{id}")
    @Doc("Get an article by id")
    public Article getArticle(@PathParam("id") @Required String articleId) {
        Article article = new Article();
        dbSession.load(article, articleId);
        return article;
    }
}

@@ -84,119 +84,9 @@
 ker.
-Doc;%0Aimport com.bardframework.bard.basic.marker.EscapeHTML;%0Aimport com.bardframework.bard.basic.marker.Required
+*
 ;%0Aim
@@ -328,24 +328,70 @@
 model.User;%0A
+import org.hibernate.ObjectNotFoundException;%0A
 import org.h
@@ -1035,16 +1035,186 @@
 %0A    %7D%0A%0A
+    @HandleErrors(%7B%0A        @ErrorCase(code = 20010, exception = ObjectNotFoundException.class,%0A            description = %22article not found%22, logLevel = %22DEBUG%22)%0A    %7D)%0A
     @GET

fix if no article found