package controllers;

import helper.JsonLinker;

import java.util.List;
import java.util.Optional;

import models.Entry;
import play.mvc.Controller;
import play.mvc.Result;

public class Entries extends Controller {

    public static Result list() {
    	final List<Entry> entries = Entry.find.all();
        return ok(JsonLinker.from(entries).to());
    }
    
    public static Result create() {
        return ok("Your new application is ready.");
    }
    
    public static Result show(Integer id) {
    	return Optional
    			.ofNullable(Entry.find.byId(id))
    			.map(entry -> ok(JsonLinker.from(entry).to()))
    			.orElse(notFound());
    }
    
    public static Result update(Integer id) {
        return ok("update id: " + id);
    }
    
    public static Result delete(Integer id) {
        return ok("delete id: " + id);
    }

}

@@ -65,16 +65,42 @@
 l.List;%0A
+import java.util.Objects;%0A
 import j
@@ -830,40 +830,241 @@
     
-    return ok(%22delete id: %22 + id
+%09return Optional%0A    %09%09%09.ofNullable(Entry.find.byId(id))%0A    %09%09%09.map(Entries::deleteNoContent)%0A    %09%09%09.orElse(notFound());%0A    %7D%0A    %0A    private static Status deleteNoContent(Entry entry)%7B%0A    %09entry.delete();%0A    %09return noContent(
 );%0A 

DELETE Request for single entry