[add] アカウント一覧用のJsonクラスを作成. [fix] Jsonクラス追加に伴って, GET APIを修正 #63

Merged m-mifune merged 1 commit into nitta-lab-2021:master from nitta-lab-2021:feature/create_accountJson on 19 May 2021
Showing 2 changed files
View
17
src/main/java/org/ntlab/acanthus_server/entities/AccountJson.java 0 → 100644
package org.ntlab.acanthus_server.entities;
 
//-----------------------------------------------------------------
// アカウント一覧取得用のJsonクラス
public class AccountJson {
private Integer uid;
private String name;
 
//-----------------------------------------------------------------
//-----------------------------------------------------------------
public AccountJson(Integer uid, String name){
this.uid = uid;
this.name = name;
}
//-----------------------------------------------------------------
}
View
59
src/main/java/org/ntlab/acanthus_server/resources/accounts/AccountsRest.java
package org.ntlab.acanthus_server.resources.accounts;
 
import org.apache.catalina.loader.WebappClassLoader;
import org.ntlab.acanthus_server.entities.Account;
import org.ntlab.acanthus_server.entities.AccountJson;
import org.ntlab.acanthus_server.models.Accounts;
import org.springframework.stereotype.Component;
 
import javax.ws.rs.*;
 
//-----------------------------------------------------------------
// GET
//-----------------------------------------------------------------
// すべてのアカウントを返す
// すべてのアカウント情報を返す
/**
* @param name ユーザー名
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Collection<Account> getAccounts(@QueryParam("name") String name) {
public Collection<AccountJson> getAccounts(@QueryParam("name") String name) {
 
var accountJsonList = new ArrayList<AccountJson>();
 
// 名前の一致するアカウントを返す
if (name != null) return accounts.getAccountsByName(name);
 
return accounts.getAllAccounts();
if (name != null){
for(var account : accounts.getAccountsByName(name)) {
var newAccountJson = new AccountJson(account.getUid(), account.getName());
accountJsonList.add(newAccountJson);
}
}
// 全アカウントの取得
else{
for(var account : accounts.getAllAccounts()) {
var newAccountJson = new AccountJson(account.getUid(), account.getName());
accountJsonList.add(newAccountJson);
}
}
return accountJsonList;
}
 
//-----------------------------------------------------------------
// 固有の
// Uidで個人のアカウント情報を取得する
// 個人情報の開示をするので, トークンあり
/**
* @param uidStr ユーザーIDの文字列
* @param token トークン
*/
@GET
@Path("/{uid}")
@Produces(MediaType.APPLICATION_JSON)
public Account getAccountByUid(@PathParam("uid") String uidStr, @QueryParam("token") String token) {
 
return searchAccount;
}
 
 
//-----------------------------------------------------------------
// POST
//-----------------------------------------------------------------
// アカウントの新規作成
 
/**
* @param name ユーザー名
* @param email メアド
* @param password パスワード
var newAccount = accounts.registerAccount(name, email, password);
 
return newAccount.getUid();
}
 
//-----------------------------------------------------------------
 
}