diff --git a/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java b/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java index c21990a..9a6e657 100644 --- a/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java +++ b/src/main/java/org/ntlab/citrusserver/resources/AccountsRest.java @@ -44,9 +44,16 @@ @Path("/{account_id}") @GET @Produces(MediaType.APPLICATION_JSON) - public Account getAccountInfo(@PathParam("account_id") String accountId){ - Account ac = accountManager.getAccount(accountId); - return ac; + public Account getAccountInfo(@PathParam("account_id") String accountId) { + //404 + if (!accountManager.getAccountsID().contains(accountId)){ //account_idが存在しない時 + var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 + throw new WebApplicationException(response.build()); + } + + Account ac = accountManager.getAccount(accountId); + return ac; + } // アカウント情報を全削除する(DELETE) @@ -55,9 +62,18 @@ public void deleteAccount(@PathParam("account_id") String accountId, @QueryParam("token") String token, @QueryParam("password")String password) { - if(accountManager.checkToken(accountId, token) == true) { + if(accountManager.checkToken(accountId, token)) { accountManager.deleteAccount(accountId, token, password); } + //404 + if (!accountManager.getAccountsID().contains(accountId)){ //account_idが存在しない時 + var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 + throw new WebApplicationException(response.build()); + } + //403 + var response = Response.status(Response.Status.FORBIDDEN).entity("アカウント削除失敗");//forbiddenは403 + throw new WebApplicationException(response.build()); + } @@ -68,9 +84,16 @@ @FormParam("new_password")String newPassword, @FormParam("old_password")String oldPassword, @FormParam("token") String token){ - if(accountManager.checkToken(accountId, token)== true) { + if(accountManager.checkToken(accountId, token)) { accountManager.changePassword(accountId, newPassword, oldPassword, token); } + + //404 + if (!accountManager.getAccountsID().contains(accountId)){ //account_idが存在しない時 + var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 + throw new WebApplicationException(response.build()); + } + //403 var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗");//forbiddenは403 throw new WebApplicationException(response.build()); } @@ -90,9 +113,15 @@ public void changeIntroduction(@PathParam("account_id") String accountId, @FormParam("introduction")String introduction, @FormParam("token") String token){ - if(accountManager.checkToken(accountId, token) == true) { + if(accountManager.checkToken(accountId, token)) { accountManager.changeIntroduction(accountId, introduction, token); } + //404 + if (!accountManager.getAccountsID().contains(accountId)){ //account_idが存在しない時 + var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 + throw new WebApplicationException(response.build()); + } + //403 var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗");//forbiddenは403 throw new WebApplicationException(response.build()); } @@ -117,6 +146,11 @@ if(accountManager.checkToken(accountId, token) == true) { return accountManager.Favorites(accountId, token); } + //404 + if (accountManager.getAccountsID().contains(accountId) == false){ //account_idが存在しない時 + var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 + throw new WebApplicationException(response.build()); + } return null; } @@ -130,6 +164,13 @@ if(accountManager.checkToken(accountId, token) == true) { return accountManager.FavoritesBookId(accountId, otherAccountId, token); } + + //404 + if (accountManager.getAccountsID().contains(accountId) == false){ //account_idが存在しない時 + var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 + throw new WebApplicationException(response.build()); + } + //403 var response = Response.status(Response.Status.FORBIDDEN).entity("認証失敗");//forbiddenは403 throw new WebApplicationException(response.build()); } @@ -149,6 +190,12 @@ @Path("/{account_id}/login") @POST public String login(@PathParam("account_id") String accountId,@FormParam("password") String password) { + //404 + if (accountManager.getAccountsID().contains(accountId) == false){ //account_idが存在しない時 + var response = Response.status(Response.Status.NOT_FOUND).entity("IDが存在しません");//404 + throw new WebApplicationException(response.build()); + } return accountManager.login(accountId, password); } + }