diff --git a/src/main/java/org/ntlab/acanthus_server/entities/Animation.java b/src/main/java/org/ntlab/acanthus_server/entities/Animation.java index 46e5b11..ce9c108 100644 --- a/src/main/java/org/ntlab/acanthus_server/entities/Animation.java +++ b/src/main/java/org/ntlab/acanthus_server/entities/Animation.java @@ -1,5 +1,8 @@ package org.ntlab.acanthus_server.entities; +import org.ntlab.acanthus_server.models.Accounts; +import org.ntlab.acanthus_server.models.Gallery; + import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -30,6 +33,9 @@ this.pageMap.put(0, 0); } + private Gallery gallery = Gallery.getInstance(); + private Accounts accounts = Accounts.getInstance(); + public void setName(String name){ this.name = name; } @@ -46,12 +52,37 @@ this.ispublic = ispublic; } + public Integer getAid() { return aid; } + public Collection getAnimationInvites() { return invites; } - public Integer getAid() { - return aid; + + //----------------------------------------------------------------- + // 本当に招待されているかを確認する + public Collection searchAnimationInvites(Integer aid, String invitedUid, String invitedUserToken) { + Animation anime_info = gallery.getAnimationInformation(aid); + Account invitedAccount = accounts.getAccountByUid(Integer.parseInt(invitedUid)); + ArrayList invitedlist = null; + + for(Account account : anime_info.invites) { + if(account == invitedAccount) { + invitedlist.add(account); + return invitedlist; + } + } + return null; } + + //----------------------------------------------------------------- + //作品に招待する + public void addAccoutToAnimationInvites(Integer aid, String ownerUid, String invitedUid) { + Animation animation = gallery.getAnimationByAid(aid); + Account invitedAccount = accounts.getAccountByUid(Integer.parseInt(invitedUid)); + invites.add(invitedAccount); + } + + //----------------------------------------------------------------- } diff --git a/src/main/java/org/ntlab/acanthus_server/models/Gallery.java b/src/main/java/org/ntlab/acanthus_server/models/Gallery.java index 5222d91..2ed3d3e 100644 --- a/src/main/java/org/ntlab/acanthus_server/models/Gallery.java +++ b/src/main/java/org/ntlab/acanthus_server/models/Gallery.java @@ -4,6 +4,11 @@ import org.ntlab.acanthus_server.entities.Animation; import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Random; + /* * 作品管理シングルトン @@ -39,4 +44,7 @@ return aid; } + public Animation getAnimationByAid(Integer aid) { + return animationHashMap.get(aid); + } } \ No newline at end of file diff --git a/src/main/java/org/ntlab/acanthus_server/resources/gallery/InvitesRest.java b/src/main/java/org/ntlab/acanthus_server/resources/gallery/InvitesRest.java index 6176f0e..53461f5 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/gallery/InvitesRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/gallery/InvitesRest.java @@ -1,6 +1,8 @@ package org.ntlab.acanthus_server.resources.gallery; +import org.ntlab.acanthus_server.entities.Account; import org.ntlab.acanthus_server.entities.Animation; +import org.ntlab.acanthus_server.models.Accounts; import org.ntlab.acanthus_server.models.Gallery; import org.springframework.stereotype.Component; @@ -12,18 +14,23 @@ @Path("/gallery") public class InvitesRest { - private Gallery animation = Gallery.getInstance(); + private Gallery animations = Gallery.getInstance(); @Path("/{aid}/invites") @GET @Produces(MediaType.APPLICATION_JSON) - public Collection isGalleryInvites(@PathParam("aid")Integer aid, @QueryParam("invitedUid") String invitedUid, @QueryParam("invitedUidToken") String invitedUserToken, @QueryParam("Token") String ownerToken) { + public Collection isGalleryInvites(@PathParam("aid")Integer aid, @QueryParam("invitedUid") String invitedUid, @QueryParam("invitedUidToken") String invitedUserToken, @QueryParam("Token") String ownerToken) { + Animation animation = animations.getAnimationByAid(aid); + + //トークンの確認 + if (invitedUid == null && invitedUserToken == null) { //招待した人を確認する - return null; - }else{ + return animation.getAnimationInvites(); + } + if(ownerToken == null){ //招待されているかを確認する - + return animation.searchAnimationInvites(aid, invitedUid, invitedUserToken); } return null; } @@ -32,7 +39,11 @@ @PUT @Produces(MediaType.APPLICATION_JSON) public String addInvite(@PathParam("aid")Integer aid, @FormParam("ownerUid") String ownerUid, @FormParam("invitedUid") String invitedUid) { + Animation animation = animations.getAnimationByAid(aid); + //トークンの確認 + + animation.addAccoutToAnimationInvites(aid,ownerUid,invitedUid); return "追加しました"; } @@ -43,6 +54,6 @@ public String deleteInvite(@PathParam("aid")Integer aid, @FormParam("invitedUid") String invitedUid, @FormParam("invitedToken") String invitedToken) { - return "追加しました"; + return "削除しました"; } } \ No newline at end of file