diff --git a/src/main/java/org/ntlab/acanthus_server/resources/gallery/EditorsRest.java b/src/main/java/org/ntlab/acanthus_server/resources/gallery/EditorsRest.java index f55f30b..2b01bee 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/gallery/EditorsRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/gallery/EditorsRest.java @@ -5,30 +5,29 @@ import org.ntlab.acanthus_server.models.Gallery; import org.springframework.stereotype.Component; -import javax.validation.constraints.Null; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import java.util.Collection; @Component @Path("/gallery") - public class EditorsRest { - //private Accounts accounts = Accounts.getInstance(); + private Accounts accounts = Accounts.getInstance(); private Gallery gallery = Gallery.getInstance(); + /* Editorに追加 */ @Path("{aid}/Editors") @GET @Produces(MediaType.APPLICATION_JSON) - public Collection getEditors(@PathParam("aid")Integer aid, @QueryParam("uid") Integer uid) { + public EditorJson getEditors(@PathParam("aid")Integer aid, @QueryParam("uid") Integer uid) { var atGallery = gallery.getAnimationInformation(aid); if(atGallery != null){ //指定作成のエディターを表示 Collection editorList = atGallery.getEditors(); - return editorList; + return new EditorJson(editorList); }else{ //aid間違っている時のレスポンス throw new WebApplicationException(401); @@ -41,14 +40,20 @@ @Path("/{aid}/Editors") @PUT @Produces(MediaType.APPLICATION_JSON) - public String addEditors(@PathParam("aid")Integer aid, @FormParam("uid")Integer uid, @FormParam("token") String token) { - /*var account = accounts.getAccountByUid(uid); + public void addEditors(@PathParam("aid")Integer aid, @FormParam("uid")Integer uid, @FormParam("token") String token) { + //招待された時のみの追加 + var account = accounts.getAccountByUid(uid); var animation = gallery.getAnimationInformation(aid); + Editor editor = new Editor(account, false); if (account != null && animation != null && account.getToken().equals(token)) { - return "ok"; - } else {*/ - //ユーザーID、トークンが間違っている時のレスポンス - throw new WebApplicationException(401); -// } + editor.setAccount(account); + animation.addEditors(editor); + if(!editor.checkOwner()){ + animation.removeAnimationInvites(account); + } + } else { + //ユーザーID、トークンが間違っている時のレスポンス + throw new WebApplicationException(401); + } } }