diff --git a/src/main/java/org/ntlab/citrusserver/resources/ScheduleRest.java b/src/main/java/org/ntlab/citrusserver/resources/ScheduleRest.java index f1bf33a..d65ee15 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/ScheduleRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/ScheduleRest.java @@ -25,51 +25,55 @@ accountManager = ac; } -// @Path("/{account_id}/schedule") -// @GET//登録されたスケジュールのidを返す -// @Produces(MediaType.APPLICATION_JSON) -// public ArrayList getScheduleAll(@PathParam("account_id") String accountId, @QueryParam("token") String token){ -// if(accountManager.checkToken(accountId,token)) { -// return scheduleManager.getScheduleAll(accountId); -// } -// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); -// throw new WebApplicationException(response.build()); -// } + @Path("/{account_id}/schedule") + @GET//登録されたスケジュールのidを返す + @Produces(MediaType.APPLICATION_JSON) + public HashMap>>> getScheduleAll(@PathParam("account_id") String accountId, + @QueryParam("token") String token){ + if(accountManager.checkToken(accountId,token)) { + return scheduleManager.getScheduleAll(accountId); + } + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } -// @Path("/{account_id}/schedule/{year}") -// @GET//登録されたスケジュールのidを年単位で返す -// @Produces(MediaType.APPLICATION_JSON) -// public ArrayList getScheduleYear(@PathParam("account_id") String accountId, @PathParam("year") Integer year,@QueryParam("token") String token){ -// if(accountManager.checkToken(accountId,token)) { -// return scheduleManager.getScheduleYear(accountId,year); -// } -// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); -// throw new WebApplicationException(response.build()); -// } + @Path("/{account_id}/schedule/{year}") + @GET//登録されたスケジュールのidを年単位で返す + @Produces(MediaType.APPLICATION_JSON) + public HashMap>> getScheduleYear(@PathParam("account_id") String accountId, + @PathParam("year") Integer year,@QueryParam("token") String token){ + if(accountManager.checkToken(accountId,token)) { + return scheduleManager.getScheduleYear(accountId,year); + } + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } -// @Path("/{account_id}/schedule/{year}/{month}") -// @GET//登録されたスケジュールのidを月単位で返す -// @Produces(MediaType.APPLICATION_JSON) -// public ArrayList getScheduleMonth(@PathParam("account_id") String accountId, @PathParam("year") Integer year,@PathParam("month") Integer month, -// @QueryParam("token") String token){ -// if(accountManager.checkToken(accountId,token)) { -// return scheduleManager.getScheduleMonth(accountId,year,month); -// } -// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); -// throw new WebApplicationException(response.build()); -// } + @Path("/{account_id}/schedule/{year}/{month}") + @GET//登録されたスケジュールのidを月単位で返す + @Produces(MediaType.APPLICATION_JSON) + public HashMap> getScheduleMonth(@PathParam("account_id") String accountId, + @PathParam("year") Integer year,@PathParam("month") Integer month, + @QueryParam("token") String token){ + if(accountManager.checkToken(accountId,token)) { + return scheduleManager.getScheduleMonth(accountId,year,month); + } + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } -// @Path("/{account_id}/schedule/{year}/{month}/{day}") -// @GET//登録されたスケジュールのidを日ごとで返す -// @Produces(MediaType.APPLICATION_JSON) -// public ArrayList getScheduleDay(@PathParam("account_id") String accountId, @PathParam("year") Integer year,@PathParam("month") Integer month, -// @PathParam("day") Integer day,@QueryParam("token") String token){ -// if(accountManager.checkToken(accountId,token)) { -// return scheduleManager.getScheduleYear(accountId,year,month,day); -// } -// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); -// throw new WebApplicationException(response.build()); -// } + @Path("/{account_id}/schedule/{year}/{month}/{day}") + @GET//登録されたスケジュールのidを日ごとで返す + @Produces(MediaType.APPLICATION_JSON) + public HashMap getScheduleDay(@PathParam("account_id") String accountId, @PathParam("year") Integer year, + @PathParam("month") Integer month, @PathParam("day") Integer day, + @QueryParam("token") String token){ + if(accountManager.checkToken(accountId,token)) { + return scheduleManager.getScheduleDay(accountId,year,month,day); + } + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } @Path("/{account_id}/schedule/{year}/{month}/{day}") @POST//スケジュールの新規作成 @@ -104,83 +108,83 @@ } } -// @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}") -// @DELETE//特定のスケジュールを削除する -// @Produces(MediaType.TEXT_PLAIN) -// @Consumes(MediaType.APPLICATION_FORM_URLENCODED) -// public Schedule deleteSchedule(@PathParam("account_id") String accountId, @PathParam("year") Integer year, -// @PathParam("month") Integer month, @PathParam("day") Integer day, -// @PathParam("schedule_id") Integer scheduleId, @QueryParam("token") String token) { -// if(accountManager.checkToken(accountId,token)) { -// scheduleManager.deleteSchedule(accountId, year, month, day, scheduleId); -// return "success"; -// }else { -// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); -// throw new WebApplicationException(response.build()); -// } -// } + @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}") + @DELETE//特定のスケジュールを削除する + @Produces(MediaType.TEXT_PLAIN) + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public String deleteSchedule(@PathParam("account_id") String accountId, @PathParam("year") Integer year, + @PathParam("month") Integer month, @PathParam("day") Integer day, + @PathParam("schedule_id") Integer scheduleId, @QueryParam("token") String token) { + if(accountManager.checkToken(accountId,token)) { + scheduleManager.deleteSchedule(accountId, year, month, day, scheduleId); + return "success"; + }else { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } + } -// @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}/start_time") -// @PUT//スケジュールの開始時刻の新規作成・変更 -// @Produces(MediaType.TEXT_PLAIN) -// @Consumes(MediaType.APPLICATION_FORM_URLENCODED) -// public Schedule setScheduleStartTime(@PathParam("account_id") String accountId, @PathParam("year") Integer year, -// @PathParam("month") Integer month, @PathParam("day") Integer day, -// @PathParam("schedule_id") Integer scheduleId, @FormParam("token") String token, @FormParam("start_time") String startTime) { -// if(accountManager.checkToken(accountId,token)) { -// scheduleManager.setScheduleStartTime(accountId, year, month, day, scheduleId); -// return "success"; -// }else { -// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); -// throw new WebApplicationException(response.build()); -// } -// } + @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}/start_time") + @PUT//スケジュールの開始時刻の新規作成・変更 + @Produces(MediaType.TEXT_PLAIN) + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public String setScheduleStartTime(@PathParam("account_id") String accountId, @PathParam("year") Integer year, + @PathParam("month") Integer month, @PathParam("day") Integer day, + @PathParam("schedule_id") Integer scheduleId, @FormParam("token") String token, @FormParam("start_time") String startTime) { + if(accountManager.checkToken(accountId,token)) { + scheduleManager.setScheduleStartTime(accountId, year, month, day, scheduleId,startTime); + return "success"; + }else { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } + } -// @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}/end_time") -// @PUT//スケジュールの終了時刻の新規作成・変更 -// @Produces(MediaType.TEXT_PLAIN) -// @Consumes(MediaType.APPLICATION_FORM_URLENCODED) -// public Schedule setScheduleEndTime(@PathParam("account_id") String accountId, @PathParam("year") Integer year, -// @PathParam("month") Integer month, @PathParam("day") Integer day, -// @PathParam("schedule_id") Integer scheduleId, @FormParam("token") String token, @FormParam("end_time") String endTime) { -// if(accountManager.checkToken(accountId,token)) { -// scheduleManager.setScheduleEndTime(accountId, year, month, day, scheduleId); -// return "success"; -// }else { -// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); -// throw new WebApplicationException(response.build()); -// } -// } + @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}/end_time") + @PUT//スケジュールの終了時刻の新規作成・変更 + @Produces(MediaType.TEXT_PLAIN) + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public String setScheduleEndTime(@PathParam("account_id") String accountId, @PathParam("year") Integer year, + @PathParam("month") Integer month, @PathParam("day") Integer day, + @PathParam("schedule_id") Integer scheduleId, @FormParam("token") String token, @FormParam("end_time") String endTime) { + if(accountManager.checkToken(accountId,token)) { + scheduleManager.setScheduleEndTime(accountId, year, month, day, scheduleId, endTime); + return "success"; + }else { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } + } -// @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}/title") -// @PUT//スケジュールのタイトルの変更 -// @Produces(MediaType.TEXT_PLAIN) -// @Consumes(MediaType.APPLICATION_FORM_URLENCODED) -// public Schedule setScheduleTitle(@PathParam("account_id") String accountId, @PathParam("year") Integer year, -// @PathParam("month") Integer month, @PathParam("day") Integer day, -// @PathParam("schedule_id") Integer scheduleId, @FormParam("token") String token, @FormParam("title") String title) { -// if(accountManager.checkToken(accountId,token)) { -// scheduleManager.setScheduleTitle(accountId, year, month, day, scheduleId); -// return schedule; -// }else { -// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); -// throw new WebApplicationException(response.build()); -// } -// } + @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}/title") + @PUT//スケジュールのタイトルの変更 + @Produces(MediaType.TEXT_PLAIN) + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public String setScheduleTitle(@PathParam("account_id") String accountId, @PathParam("year") Integer year, + @PathParam("month") Integer month, @PathParam("day") Integer day, + @PathParam("schedule_id") Integer scheduleId, @FormParam("token") String token, @FormParam("title") String title) { + if(accountManager.checkToken(accountId,token)) { + scheduleManager.changeScheduleTitle(accountId, year, month, day, scheduleId, title); + return "success"; + }else { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } + } -// @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}/book_id") -// @PUT//スケジュールの所属している本の新規設定・変更 -// @Produces(MediaType.TEXT_PLAIN) -// @Consumes(MediaType.APPLICATION_FORM_URLENCODED) -// public Schedule setSchedulesBook(@PathParam("account_id") String accountId, @PathParam("year") Integer year, -// @PathParam("month") Integer month, @PathParam("day") Integer day, -// @PathParam("schedule_id") Integer scheduleId, @FormParam("token") String token, @FormParam("book_id") String bookId) { -// if(accountManager.checkToken(accountId,token)) { -// scheduleManager.setSchedulesBook(accountId, year, month, day, scheduleId);//token後でつける -// return "success"; -// }else { -// var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); -// throw new WebApplicationException(response.build()); -// } -// } + @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}/book_id") + @PUT//スケジュールの所属している本の新規設定・変更 + @Produces(MediaType.TEXT_PLAIN) + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public String setSchedulesBook(@PathParam("account_id") String accountId, @PathParam("year") Integer year, + @PathParam("month") Integer month, @PathParam("day") Integer day, + @PathParam("schedule_id") Integer scheduleId, @FormParam("token") String token, @FormParam("book_id") Integer bookId) { + if(accountManager.checkToken(accountId,token)) { + scheduleManager.setSchedulesBookId(accountId, year, month, day, scheduleId, bookId); + return "success"; + }else { + var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); + throw new WebApplicationException(response.build()); + } + } }