TodoRest内容変更
1 parent 0172504 commit 3c1745fc4dd640177117abf4b825089816688a9e
k-iwamoto authored on 14 May
Showing 1 changed file
View
60
src/main/java/org/ntlab/citrusserver/resources/TodoRest.java
package org.ntlab.citrusserver.resources;
 
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.apache.coyote.http11.upgrade.UpgradeServletOutputStream;
import org.ntlab.citrusserver.entities.Todo;
import org.ntlab.citrusserver.repositories.AccountManager;
import org.ntlab.citrusserver.repositories.TodoManager;
@Path("/{account_id}/books/{book_id}/todos")
@GET
@Produces(MediaType.APPLICATION_JSON)
public HashMap<Integer, HashMap<Integer, HashMap<Integer, HashMap<Integer, Todo>>>> getAllTodos(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @QueryParam("token") String token) {
if(accountManager.checkToken(account_id,token)==true){
return todoManager.getAllTodos(account_id, book_id, token);
if (accountManager.checkToken(account_id, token) == true) {
return todoManager.getAllTodos(account_id, book_id);
}
return null;
}
 
@Path("/{account_id}/books/{book_id}/todos/{year}/{month}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public HashMap<Integer, HashMap<Integer, Todo>> getTodosByMonth(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @QueryParam("token") String token) {
if(accountManager.checkToken(account_id,token)==true) {
return todoManager.getTodosByMonth(account_id, book_id, year, month, token);
if (accountManager.checkToken(account_id, token) == true) {
return todoManager.getTodosByMonth(account_id, book_id, year, month);
}
return null;
}
 
@Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public HashMap<Integer, Todo> getTodosByDay(@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) {
if(accountManager.checkToken(account_id,token)==true) {
return todoManager.getTodosByDay(account_id, book_id, year, month, day, token);
if (accountManager.checkToken(account_id, token) == true) {
return todoManager.getTodosByDay(account_id, book_id, year, month, day);
}
return null;
}
 
@Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Todo getTodoById(@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) {
if(accountManager.checkToken(account_id,token)==true) {
Todo todo = todoManager.getTodoById(account_id, book_id, year, month, day, todo_id, token);
if (accountManager.checkToken(account_id, token) == true) {
Todo todo = todoManager.getTodoById(account_id, book_id, year, month, day, todo_id);
return todo;
}
return null;
}
@POST
@Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public Todo createTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @FormParam("title") String title,@FormParam("token") String token) {
if(accountManager.checkToken(account_id,token)==true) {
return todoManager.createTodo(account_id, book_id, year, month, day, title, token);
public Todo createTodo(@PathParam("account_id") String account_id, @PathParam("book_id") Integer book_id, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day, @FormParam("title") String title, @FormParam("token") String token) {
if (accountManager.checkToken(account_id, token) == true) {
return todoManager.createTodo(account_id, book_id, year, month, day, title);
}
return null;
}
 
//フォームパラメータでチェック状況
@PUT
@Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}/check")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void setCheck(@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, @FormParam("token") String token){
if(accountManager.checkToken(account_id,token)==true) {
todoManager.setCheck(account_id, book_id, year, month, day, todo_id, check, token);
public void setCheck(@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, @FormParam("token") String token) {
if (accountManager.checkToken(account_id, token) == true) {
todoManager.setCheck(account_id, book_id, year, month, day, todo_id, check);
}
}
 
 
//本のtodoを年月日とtodo_idを指定してそのtodoを削除する
//@DELETE
//@Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}")
//@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
//public void deleteTodoById(@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){
// if(accountManager.checkToken(account_id,token)==true) {
// todoManager.deleteTodoById(account_id, book_id, year, month, day, todo_id, token);
// }
//}
 
@DELETE
@Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void deleteTodoById(@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){
if(accountManager.checkToken(account_id,token)==true) {
todoManager.deleteTodoById(account_id, book_id, year, month, day, todo_id, token);
public void deleteTodoById(@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) {
if (accountManager.checkToken(account_id, token) == true) {
if (todoManager.deleteTodoById(account_id, book_id, year, month, day, todo_id) == -1) {
var response = Response.status(Response.Status.BAD_REQUEST).entity("消去失敗");
throw new WebApplicationException(response.build());
} else {
var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗」");
throw new WebApplicationException(response.build());
}
}
}
 
}
 
 
}