Merge pull request #253 from nitta-lab-2024/putTodo
TodoManagerとTodoRestにPutTodoの処理を追加しました
commit 2214433a64ff232f1eb53b2dbb9051eac7723c4b
2 parents 0721f45 + 77bc058
山本大翔 authored on 26 Sep
Showing 2 changed files
View
27
src/main/java/org/ntlab/citrusserver/repositories/TodoManager.java
todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setCheck(check);
return 1;
}
 
public int setTodo(String accountId, int bookId, int year, int month, int day, int todoId, String title){
if(!todos.containsKey(accountId)){
return -1;
}
if(!todos.get(accountId).containsKey(bookId)){
return -1;
}
if(!todos.get(accountId).get(bookId).containsKey(year)){
return -1;
}
if(!todos.get(accountId).get(bookId).get(year).containsKey(month)){
return -1;
}
if(!todos.get(accountId).get(bookId).get(year).get(month).containsKey(day)){
return -1;
}
if(!todos.get(accountId).get(bookId).get(year).get(month).get(day).containsKey(todoId)){
return -1;
}
todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setTitle(title);
todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setBookId(bookId);
todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setYear(year);
todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setMonth(month);
todos.get(accountId).get(bookId).get(year).get(month).get(day).get(todoId).setDay(day);
return 1;
}
 
/**
*todo_idを指定してtodoの達成状態を変更
*
* @param accountId アカウントのid
View
19
src/main/java/org/ntlab/citrusserver/resources/TodoRest.java
import org.ntlab.citrusserver.repositories.AccountManager;
import org.ntlab.citrusserver.repositories.BookManager;
import org.ntlab.citrusserver.repositories.TodoManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.stereotype.Component;
 
import java.util.HashMap;
 
throw new WebApplicationException(response.build());
}
}
 
@PUT
@Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public void setTodo(@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("title") String title,
@FormParam("new_year") Integer new_year,@FormParam("new_month") Integer new_month,@FormParam("new_day") Integer new_day, @FormParam("token") String token){
if (accountManager.checkToken(account_id, token)) {
if (todoManager.setTodo(account_id, book_id, new_year, new_month, new_day, todo_id, title) == -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());
}
}
 
 
/* //本のtodoを年月日とtodo_idを指定してそのtodoを削除する
@DELETE
@Path("/{account_id}/books/{book_id}/todos/{year}/{month}/{day}/{todo_id}")