diff --git a/src/main/java/org/ntlab/tampoposerver/resources/NotificationsResource.java b/src/main/java/org/ntlab/tampoposerver/resources/NotificationsResource.java index 1f5b609..537a354 100644 --- a/src/main/java/org/ntlab/tampoposerver/resources/NotificationsResource.java +++ b/src/main/java/org/ntlab/tampoposerver/resources/NotificationsResource.java @@ -9,16 +9,17 @@ import org.ntlab.tampoposerver.repositories.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; - import java.util.HashMap; import java.util.List; import java.util.Map; + @Path("/users/{user-id}/notifications") @Component public class NotificationsResource { private final UserRepository userRepository; - private final NotificationRepository notificationRepository; //finalによりインスタンス作成後に再代入不可,不変オブジェクト + private final NotificationRepository notificationRepository; + //finalによりインスタンス作成後に再代入不可,不変オブジェクト @Autowired public NotificationsResource(UserRepository userRepository, NotificationRepository notificationRepository) { @@ -36,7 +37,7 @@ throw new WebApplicationException(response.build()); } if (user == null) { - var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 + var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません"); //404 throw new WebApplicationException(response.build()); } if (token == null || token.isEmpty()) { @@ -44,7 +45,7 @@ throw new WebApplicationException(response.build()); } if (!token.equals(user.getToken())) { //リクエストに含まれるトークンが、ユーザーに登録されているトークンと一致していない場合 - var response = Response.status(Response.Status.FORBIDDEN).entity("トークンが不正です");//403 + var response = Response.status(Response.Status.FORBIDDEN).entity("トークンが不正です"); //403 throw new WebApplicationException(response.build()); } @@ -52,6 +53,7 @@ return Response.ok(notifications).build(); } + //通知詳細を取得 @Path("/{notification-id}") @GET @Produces(MediaType.APPLICATION_JSON) @@ -62,7 +64,7 @@ throw new WebApplicationException(response.build()); } if (user == null) { - var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 + var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません"); //404 throw new WebApplicationException(response.build()); } if (token == null || token.isEmpty()) { @@ -70,18 +72,19 @@ throw new WebApplicationException(response.build()); } if (!token.equals(user.getToken())) { - var response = Response.status(Response.Status.FORBIDDEN).entity("トークンが不正です");//403 + var response = Response.status(Response.Status.FORBIDDEN).entity("トークンが不正です"); //403 throw new WebApplicationException(response.build()); } Notification notification = notificationRepository.getNotification(userID, notificationID); //通知詳細を取得 if (notification == null) { - var response = Response.status(Response.Status.NOT_FOUND).entity("通知が存在しません");//404 + var response = Response.status(Response.Status.NOT_FOUND).entity("通知が存在しません"); //404 throw new WebApplicationException(response.build()); } return Response.ok(notification).build(); } - @Path("/{notification-id}/text") //通知本文だけを返す + //通知本文だけを返す + @Path("/{notification-id}/text") @GET @Produces(MediaType.APPLICATION_JSON) public Response getNotificationText(@PathParam("user-id") String userID, @PathParam("notification-id") String notificationID, @QueryParam("token") String token) { @@ -91,7 +94,7 @@ throw new WebApplicationException(response.build()); } if (user == null) { - var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 + var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません"); //404 throw new WebApplicationException(response.build()); } if (token == null || token.isEmpty()) { @@ -99,12 +102,12 @@ throw new WebApplicationException(response.build()); } if (!token.equals(user.getToken())) { - var response = Response.status(Response.Status.FORBIDDEN).entity("トークンが不正です");//403 + var response = Response.status(Response.Status.FORBIDDEN).entity("トークンが不正です"); //403 throw new WebApplicationException(response.build()); } Notification notification = notificationRepository.getNotification(userID, notificationID); if (notification == null) { - var response = Response.status(Response.Status.NOT_FOUND).entity("通知が存在しません");//404 + var response = Response.status(Response.Status.NOT_FOUND).entity("通知が存在しません"); //404 throw new WebApplicationException(response.build()); } @@ -113,7 +116,8 @@ return Response.ok(response).build(); } - @Path("/{notification-id}/time") //通知日時だけを返す + //通知日時だけを返す + @Path("/{notification-id}/time") @GET @Produces(MediaType.APPLICATION_JSON) public Response getNotificationTime(@PathParam("user-id") String userID, @PathParam("notification-id") String notificationID, @QueryParam("token") String token) { @@ -123,7 +127,7 @@ throw new WebApplicationException(response.build()); } if (user == null) { - var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 + var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません"); //404 throw new WebApplicationException(response.build()); } if (token == null || token.isEmpty()) { @@ -131,12 +135,12 @@ throw new WebApplicationException(response.build()); } if (!token.equals(user.getToken())) { - var response = Response.status(Response.Status.FORBIDDEN).entity("トークンが不正です");//403 + var response = Response.status(Response.Status.FORBIDDEN).entity("トークンが不正です"); //403 throw new WebApplicationException(response.build()); } Notification notification = notificationRepository.getNotification(userID, notificationID); if (notification == null) { - var response = Response.status(Response.Status.NOT_FOUND).entity("通知が存在しません");//404 + var response = Response.status(Response.Status.NOT_FOUND).entity("通知が存在しません"); //404 throw new WebApplicationException(response.build()); } @@ -145,7 +149,8 @@ return Response.ok(response).build(); } - @Path("/{notification-id}/from") //通知送信者だけを返す + //通知送信者だけを返す + @Path("/{notification-id}/from") @GET @Produces(MediaType.APPLICATION_JSON) public Response getNotificationFrom(@PathParam("user-id") String userID, @PathParam("notification-id") String notificationID, @QueryParam("token") String token) { @@ -155,7 +160,7 @@ throw new WebApplicationException(response.build()); } if (user == null) { - var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 + var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません"); //404 throw new WebApplicationException(response.build()); } if (token == null || token.isEmpty()) { @@ -163,12 +168,12 @@ throw new WebApplicationException(response.build()); } if (!token.equals(user.getToken())) { - var response = Response.status(Response.Status.FORBIDDEN).entity("トークンが不正です");//403 + var response = Response.status(Response.Status.FORBIDDEN).entity("トークンが不正です"); //403 throw new WebApplicationException(response.build()); } Notification notification = notificationRepository.getNotification(userID, notificationID); if (notification == null) { - var response = Response.status(Response.Status.NOT_FOUND).entity("通知が存在しません");//404 + var response = Response.status(Response.Status.NOT_FOUND).entity("通知が存在しません"); //404 throw new WebApplicationException(response.build()); }