diff --git a/build.gradle b/build.gradle index 284ac06..b4bd5ac 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,6 @@ testImplementation 'org.springframework.boot:spring-boot-starter-test' // a dependency on Jackson Databind implementation 'com.fasterxml.jackson.core:jackson-databind:2.11.4' - implementation 'io.vertx:vertx-core:3.5.3' } 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 58e3023..ef99fa0 100644 --- a/src/main/java/org/ntlab/acanthus_server/models/Gallery.java +++ b/src/main/java/org/ntlab/acanthus_server/models/Gallery.java @@ -48,11 +48,17 @@ } //作品名で作品情報を返す。 - public Animation getAnimationByAnimationName(String animationName){ - return animationHashMap.get(animationName); + public ArrayList getAnimationByAnimationName(String animationName){ + var animationList = new ArrayList(); + for(var animation : animationHashMap.values()){ + if(animation.getName().equals(animationName)) animationList.add(animation); + } + return animationList; } + + //----------------------------------------------------------------- // 作品を作る diff --git a/src/main/java/org/ntlab/acanthus_server/resources/HelloWorld.java b/src/main/java/org/ntlab/acanthus_server/resources/HelloWorld.java index f9b173d..94eb0be 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/HelloWorld.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/HelloWorld.java @@ -1,15 +1,24 @@ package org.ntlab.acanthus_server.resources; import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestMapping; import javax.ws.rs.GET; import javax.ws.rs.Path; +import java.util.Date; +@RequestMapping(produces="application/json;charset=UTF-8") @Component @Path("hello_world") public class HelloWorld { + long msec; + long responsetime; + @GET public String getHelloWorld() { - return "Hello World!!!"; + Date date = new Date(); + this.responsetime = date.getTime()-this.msec; + this.msec=date.getTime(); + return "Hello World!!!反応時間:"+this.responsetime+"time:"+this.msec; } } diff --git a/src/main/java/org/ntlab/acanthus_server/resources/gallery/GalleryRest.java b/src/main/java/org/ntlab/acanthus_server/resources/gallery/GalleryRest.java index a657327..fdeaa31 100644 --- a/src/main/java/org/ntlab/acanthus_server/resources/gallery/GalleryRest.java +++ b/src/main/java/org/ntlab/acanthus_server/resources/gallery/GalleryRest.java @@ -24,11 +24,23 @@ @Produces(MediaType.APPLICATION_JSON) //すべての作品情報を返す。 - public Collection getGallery(){ + public Collection getGallery(@QueryParam("animationName") String animationName){ //変数にAnimation型のArrayListを代入 var animationJsonList = new ArrayList(); + var searchAnimation = gallery.getAnimationByAnimationName(animationName); + var response = Response.status(Response.Status.NO_CONTENT); + + //クエリパラメータがなくても判別可能。 //拡張for文で上記のListに作品を追加。 - for (var animation : gallery.getAllAnimation()) animationJsonList.add(new AnimationJson(animation)); + if(animationName == null) { + for (var animation : gallery.getAllAnimation()) animationJsonList.add(new AnimationJson(animation)); + } + //インスタンスが生成されるとnullではなくなる。要素は0。だからsize()をつかう。 + else if(searchAnimation.size() == 0){ + response = Response.status(404).entity("この作品名に該当する作品がありません。"); + throw new WebApplicationException(response.build()); + } + else for(var animation : searchAnimation) animationJsonList.add(new AnimationJson(animation)); return animationJsonList; } //public Animation getGallery(){return ;} @@ -43,14 +55,16 @@ //Uidをとりアカウント検索 var searchAccounts = Accounts.getInstance().getAccountByUid(uid); + var response = Response.status(Response.Status.NO_CONTENT); + if(searchAccounts == null){ - var response=Response.status(404).entity("該当アカウントが存在しません"); + response=Response.status(404).entity("該当アカウントが存在しません"); throw new WebApplicationException(response.build()); } //トークン認証 これもクリアするとcreateAnimationが返され作品が作られる。 if(!searchAccounts.isCollectToken(token)){ - var response = Response.status(400).entity("トークンが違います。"); + response = Response.status(400).entity("トークンが違います。"); throw new WebApplicationException(response.build()); } else { @@ -85,20 +99,4 @@ return animationJsonList; } - //作品名で作品を検索 - public Collection getAnimationByAnimationName(@QueryParam("name") String name){ - var searchAnimation = gallery.getAnimationByAnimationName(name); - var response = Response.status(Response.Status.NO_CONTENT); - - if(searchAnimation == null){ - response = Response.status(404).entity("この作品名に該当する作品は存在しません。"); - throw new WebApplicationException(response.build()); - } - - var animationList = new ArrayList(); - animationList.add(new AnimationJson(searchAnimation)); - - return animationList; - } - } \ No newline at end of file