package org.ntlab.citrusserver.resources;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import org.apache.coyote.http11.upgrade.UpgradeServletOutputStream;
import org.ntlab.citrusserver.entities.Todo;
import org.ntlab.citrusserver.repositories.TodoManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Path("/accounts")
@Component
public class TodoRest {
private final TodoManager todoManager;
@Autowired
public TodoRest(TodoManager tm, TodoManager todoManager) {
this.todoManager = todoManager;
todoManager = tm;
}
@Path("/TodoTest")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String testHello() {
return "hello";
}
//指定された本のtodoをすべて返す
//変更↓
@Path("/{account_id}/books/{book_id}/todos")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Todo getName(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") Integer token) {
Todo todo = todoManager.getAllTodos(account_id, book_id, token);
return todo;//account部分のリスト名要変更
//ドット部分以降打合せ(相手の関数名に合わせる)
}
//指定された本の指定された年と月のtodoをすべて返す
//yearとmonthはintなのか!!!
@Path("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Todo getTodoMonth(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @QueryParam("token") String token) {
Todo todo = todoManager.getTodosByMonth(account_id, book_id, year, month,token);
return todo;
}
//指定された本の指定された年と月と日のtodoをすべて返す
@Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Todo getTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @QueryParam("token") String token) {
Todo todo = todoManager.getTodosByDay(account_id, book_id, year, month, day, token);
return todo;
}
//本のtodoを年月日とtodo_idを指定してtodoを一つ返す
@Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Todo getTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @PathParam("todo_id") Integer todo_id, @QueryParam("token") String token) {
Todo todo = todoManager.getTodoById(account_id, book_id, year, month, day, todo_id, token);
return todo;
}
//指定した本と年月日にtodoを新しく追加する
@POST
@Path("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}/{day}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Todo putTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @QueryParam("token") String token) {
Todo todo = todoManager.createTodo(account_id, book_id, year, month, day, token);
return todo;
}
//todoを選んで達成状態を変更する
//フォームパラメータでチェック状況
@PUT
@Path("/accounts/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}/check")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Todo putTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day,@PathParam("todo_id") Integer todo_id, @FormParam("check") boolean check){
Todo todo = todoManager.setCheck(account_id, book_id, year, month, day, todo_id,check);
return todo;
}
}