package fr.alecharp.picshare.resource;

import fr.alecharp.picshare.domain.Event;
import fr.alecharp.picshare.service.EventService;
import net.codestory.http.annotations.Get;
import net.codestory.http.templating.Model;
import net.codestory.http.templating.ModelAndView;

import javax.inject.Inject;
import java.util.Optional;

/**
 * @author Adrien Lecharpentier
 */
public class EventResource {
    private final EventService eventService;

    @Inject
    public EventResource(EventService eventService) {
        this.eventService = eventService;
    }

    @Get("/event/:id")
    public ModelAndView dashboard(String id) {
        Optional<Event> event = eventService.get(id);
        return event.isPresent() ?
                ModelAndView.of("event/display.html", "event", event.get()) :
                ModelAndView.of("404.html");
    }
}

@@ -136,42 +136,176 @@
 ort 
-net.codestory.http.annotations.Get
+fr.alecharp.picshare.service.PictureService;%0Aimport net.codestory.http.Response;%0Aimport net.codestory.http.annotations.Get;%0Aimport net.codestory.http.annotations.Prefix
 ;%0Aim
@@ -426,16 +426,72 @@
 Inject;%0A
+import java.io.IOException;%0Aimport java.nio.file.Files;%0A
 import j
@@ -550,16 +550,34 @@
 ier%0A */%0A
+@Prefix(%22/event%22)%0A
 public c
@@ -641,16 +641,65 @@
 Service;
+%0A    private final PictureService pictureService;
 %0A%0A    @I
@@ -754,16 +754,47 @@
 tService
+, PictureService pictureService
 ) %7B%0A    
@@ -827,24 +827,70 @@
 entService;%0A
+        this.pictureService = pictureService;%0A
     %7D%0A%0A    @
@@ -895,22 +895,16 @@
  @Get(%22/
-event/
 :id%22)%0A  
@@ -1165,11 +1165,281 @@
 );%0A    %7D
+%0A%0A    @Get(%22/:id/:picture%22)%0A    public void download(String id, String picture, Response resp) throws IOException %7B%0A        resp.setHeader(%22Content-Type%22, %22application/octet-stream%22);%0A        Files.copy(pictureService.getPicture(id, picture), resp.outputStream());%0A    %7D
 %0A%7D%0A

Create HTTP API to download the file