diff --git a/src/main/java/org/ntlab/acanthus_server/entities/FollowerUidJson.java b/src/main/java/org/ntlab/acanthus_server/entities/FollowerUidJson.java new file mode 100644 index 0000000..4fcc657 --- /dev/null +++ b/src/main/java/org/ntlab/acanthus_server/entities/FollowerUidJson.java @@ -0,0 +1,26 @@ +package org.ntlab.acanthus_server.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.ArrayList; +import java.util.Collection; + +public class FollowerUidJson { + @JsonProperty("followersUid") + private Collection uidList = new ArrayList<>(); + + //Json型でフォロワーのユーザーIDを表示する処理 + public FollowerUidJson(Collection followUidList){ + for (var followerUid : followUidList){ + uidList.add(followerUid); + } + } + + public Collection getUidList() { + return uidList; + } + + public void setUidList(Collection uidList) { + this.uidList = uidList; + } +} diff --git a/src/main/java/org/ntlab/acanthus_server/resources/accounts/FollowersRest.java b/src/main/java/org/ntlab/acanthus_server/resources/accounts/FollowersRest.java new file mode 100644 index 0000000..3cbe5f8 --- /dev/null +++ b/src/main/java/org/ntlab/acanthus_server/resources/accounts/FollowersRest.java @@ -0,0 +1,35 @@ +package org.ntlab.acanthus_server.resources.accounts; + +import org.ntlab.acanthus_server.entities.FollowerUidJson; +import org.ntlab.acanthus_server.models.Accounts; +import org.springframework.stereotype.Component; + +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.Collection; + +@Component +@Path("/accounts") +public class FollowersRest { + private Accounts accounts = Accounts.getInstance(); + + //アカウント別のフォロワー情報を取得するメソッド + + @Path("/{uid}/followers") + @GET + @Produces(MediaType.APPLICATION_JSON) + public FollowerUidJson getFollowers(@PathParam("uid") Integer uid){ + var account = accounts.getAccountByUid(uid);//ユーザー情報の取得 + + if (account != null){ + Collection followersUidList = account.getFollowersHashMap().keySet(); + + return new FollowerUidJson(followersUidList); + }else { + var response = Response.status(401).entity("ユーザーIDが間違っています"); + throw new WebApplicationException(response.build()); + } + } + +}