diff --git a/src/main/java/org/ntlab/tampoposerver/resources/NotificationsResource.java b/src/main/java/org/ntlab/tampoposerver/resources/NotificationsResource.java index e0d2311..ed3d776 100644 --- a/src/main/java/org/ntlab/tampoposerver/resources/NotificationsResource.java +++ b/src/main/java/org/ntlab/tampoposerver/resources/NotificationsResource.java @@ -19,7 +19,7 @@ public class NotificationsResource { private final UserRepository userRepository; private final NotificationRepository notificationRepository; - //finalによりインスタンス作成後に再代入不可,不変オブジェクト + //finalによりインスタンス作成後に再代入不可,不変オブジェクト(後から再代入しないため) @Autowired public NotificationsResource(UserRepository userRepository, NotificationRepository notificationRepository) { @@ -44,7 +44,8 @@ var response = Response.status(Response.Status.UNAUTHORIZED).entity("認証トークンがありません"); //401 throw new WebApplicationException(response.build()); } - if (!token.equals(user.getToken())) { //リクエストに含まれるトークンが、ユーザーに登録されているトークンと一致していない場合 + //リクエストに含まれるトークンが、ユーザーに登録されているトークンと一致していない場合 + if (!token.equals(user.getToken())) { var response = Response.status(Response.Status.FORBIDDEN).entity("トークンが不正です"); //403 throw new WebApplicationException(response.build()); } @@ -53,6 +54,8 @@ return Response.ok(notifications).build(); } + + //テスト用 @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response addNotification(@PathParam("user-id") String userID, @FormParam("from") String from, @FormParam("text") String text, @FormParam("time") String time) { @@ -60,6 +63,7 @@ var response = Response.status(Response.Status.BAD_REQUEST).entity("404"); throw new WebApplicationException(response.build()); } + Notification notification = notificationRepository.addNotification(userID, from, text, time); return Response.ok(notification).build(); } @@ -87,11 +91,13 @@ var response = Response.status(Response.Status.FORBIDDEN).entity("トークンが不正です"); //403 throw new WebApplicationException(response.build()); } - Notification notification = notificationRepository.getNotification(userID, notificationID); //通知詳細を取得 + + Notification notification = notificationRepository.getNotification(userID, notificationID); //詳細取得 if (notification == null) { var response = Response.status(Response.Status.NOT_FOUND).entity("通知が存在しません"); //404 throw new WebApplicationException(response.build()); } + return Response.ok(notification).build(); } @@ -124,11 +130,15 @@ throw new WebApplicationException(response.build()); } - Map response = new HashMap<>(); //HashMapクラスのインスタンスを生成 - response.put("text", notification.getText()); //Mapにキーと値のペアを追加 + //HashMapクラスのインスタンスを生成(キーの順序を保持しない) + Map response = new HashMap<>(); + response.put("text", notification.getText()); + //Mapにキーと値のペアを追加 + //テキストをキーでMapに格納し、レスポンスに使用 return Response.ok(response).build(); } + //通知日時だけを返す @Path("/{notification-id}/time") @GET @@ -162,6 +172,7 @@ return Response.ok(response).build(); } + //通知送信者だけを返す @Path("/{notification-id}/from") @GET