/*
 * Copyright (c) 2016 BreizhCamp
 * [http://breizhcamp.org]
 *
 * This file is part of CFP.io.
 *
 * CFP.io is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package io.cfp.controller;

import io.cfp.domain.exception.CospeakerNotFoundException;
import io.cfp.dto.TalkAdmin;
import io.cfp.entity.Role;
import io.cfp.entity.Talk;
import io.cfp.service.TalkAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@Secured(Role.ADMIN)
@RequestMapping(value = { "/v0/admin", "/api/admin" }, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class AdminSessionController {

    @Autowired
    private TalkAdminService talkService;

    /**
     * Get all sessions
     */
    @RequestMapping(value="/sessions", method= RequestMethod.GET)
    @ResponseBody
    public List<TalkAdmin> getAllSessions() {
        return talkService.findAll(Talk.State.CONFIRMED, Talk.State.ACCEPTED, Talk.State.REFUSED);
    }

    /**
     * Get all drafts
     */
    @RequestMapping(value="/drafts", method= RequestMethod.GET)
    @ResponseBody
    public List<TalkAdmin> getAllDrafts() {
        return talkService.findAll(Talk.State.DRAFT);
    }

    /**
     * Get a specific session
     */
    @RequestMapping(value= "/sessions/{talkId}", method= RequestMethod.GET)
    @ResponseBody
    public TalkAdmin getTalk(@PathVariable int talkId) {
        return talkService.getOne(talkId);
    }

    /**
     * Edit a specific session
     */
    @RequestMapping(value= "/sessions/{talkId}", method= RequestMethod.PUT)
    @ResponseBody
    public TalkAdmin editTalk(@PathVariable int talkId, @RequestBody TalkAdmin talkAdmin) throws CospeakerNotFoundException{
        talkAdmin.setId(talkId);
        return talkService.edit(talkAdmin);
    }

    /**
     * Delete a session
     */
    @RequestMapping(value="/sessions/{talkId}", method= RequestMethod.DELETE)
    @ResponseBody
    public TalkAdmin deleteGoogleSpreadsheet(@PathVariable int talkId) {
        return talkService.delete(talkId);
    }
}

@@ -1434,16 +1434,77 @@
 Method;%0A
+import org.springframework.web.bind.annotation.RequestParam;%0A
 import o
@@ -1982,28 +1982,66 @@
 essions(
+@RequestParam(%22status%22) String status
 ) %7B%0A
+%0A
         
 return t
@@ -2036,96 +2036,303 @@
     
-return talkService.findAll(Talk.State.CONFIRMED, Talk.State.ACCEPTED, Talk.State.REFUSED
+Talk.State%5B%5D accept;%0A        if (status == null) %7B%0A            accept = new Talk.State%5B%5D %7B Talk.State.CONFIRMED, Talk.State.ACCEPTED, Talk.State.REFUSED %7D;%0A        %7D else %7B%0A            accept = new Talk.State%5B%5D %7B Talk.State.valueOf(status) %7D;%0A        %7D%0A%0A        return talkService.findAll(accept
 );%0A 

add status query filter to /api/admin/sessions can help for #83