package org.ntlab.citrusserver.resources; import jakarta.ws.rs.core.Response; import org.ntlab.citrusserver.entities.Schedule; import org.ntlab.citrusserver.repositories.AccountManager; import org.ntlab.citrusserver.repositories.ScheduleManager; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.HashMap; @Path("/accounts") @Component public class ScheduleRest { private final ScheduleManager scheduleManager; private final AccountManager accountManager; @Autowired public ScheduleRest(ScheduleManager sm, AccountManager ac){ scheduleManager = sm; accountManager = ac; } // @Path("/{account_id}/schedule") // @GET//登録されたスケジュールのidを返す // @Produces(MediaType.APPLICATION_JSON) // public ArrayList<Integer> 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<Integer> 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<Integer> 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<Integer> 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}") @POST//スケジュールの新規作成 @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON) public Schedule addSchedule(@PathParam("account_id") String accountId, @PathParam("year") Integer year, @PathParam("month") Integer month, @PathParam("day") Integer day,@FormParam("title") String title, @FormParam("start_time") String startTime,@FormParam("end_time") String endTime,@FormParam("book_id") Integer bookId, @FormParam("token") String token) { if(accountManager.checkToken(accountId,token)) { return scheduleManager.addSchedule(accountId, year, month, day,title,startTime,endTime,bookId); }else { var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗"); throw new WebApplicationException(response.build()); } } @Path("/{account_id}/schedule/{year}/{month}/{day}/{schedule_id}") @GET//スケジュールの情報を返す @Produces(MediaType.APPLICATION_JSON) public Schedule getScheduleInfo(@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)) { Schedule schedule = scheduleManager.getScheduleId(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}") // @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}/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, @QueryParam("token") String token) { // 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}/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, @QueryParam("token") String token) { // 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}/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, @QueryParam("token") String token) { // 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}/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, @QueryParam("token") String token) { // 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()); // } // } }