Added isAdmin field to output of API call GET /groups/member/{address}

This commit is contained in:
catbref 2020-04-22 16:32:55 +01:00
parent 33010f82d8
commit 5011a2be22
2 changed files with 23 additions and 3 deletions

View File

@ -35,6 +35,9 @@ public class GroupData {
) )
private int creationGroupId; private int creationGroupId;
// We abuse this class for API purposes by adding this unrelated field. Not always present.
private Boolean isAdmin;
// Constructors // Constructors
// necessary for JAX-RS serialization // necessary for JAX-RS serialization
@ -140,4 +143,14 @@ public class GroupData {
return this.creationGroupId; return this.creationGroupId;
} }
// This is for API call GET /groups/member/{address}
public Boolean isAdmin() {
return this.isAdmin;
}
public void setIsAdmin(boolean isAdmin) {
this.isAdmin = isAdmin;
}
} }

View File

@ -206,8 +206,10 @@ public class HSQLDBGroupRepository implements GroupRepository {
public List<GroupData> getGroupsWithMember(String member, Integer limit, Integer offset, Boolean reverse) throws DataException { public List<GroupData> getGroupsWithMember(String member, Integer limit, Integer offset, Boolean reverse) throws DataException {
StringBuilder sql = new StringBuilder(512); StringBuilder sql = new StringBuilder(512);
sql.append("SELECT group_id, owner, group_name, description, created, updated, reference, is_open, " sql.append("SELECT group_id, owner, group_name, description, created, updated, reference, is_open, "
+ "approval_threshold, min_block_delay, max_block_delay, creation_group_id FROM Groups " + "approval_threshold, min_block_delay, max_block_delay, creation_group_id, admin FROM Groups "
+ "JOIN GroupMembers USING (group_id) WHERE address = ? ORDER BY group_name"); + "JOIN GroupMembers USING (group_id) "
+ "LEFT OUTER JOIN GroupAdmins ON GroupAdmins.group_id = GroupMembers.group_id AND GroupAdmins.admin = GroupMembers.address "
+ "WHERE address = ? ORDER BY group_name");
if (reverse != null && reverse) if (reverse != null && reverse)
sql.append(" DESC"); sql.append(" DESC");
@ -239,8 +241,13 @@ public class HSQLDBGroupRepository implements GroupRepository {
int maxBlockDelay = resultSet.getInt(11); int maxBlockDelay = resultSet.getInt(11);
int creationGroupId = resultSet.getInt(12); int creationGroupId = resultSet.getInt(12);
resultSet.getString(13);
boolean isAdmin = !resultSet.wasNull();
groups.add(new GroupData(groupId, owner, groupName, description, created, updated, isOpen, approvalThreshold, minBlockDelay, maxBlockDelay, reference, creationGroupId)); GroupData groupData = new GroupData(groupId, owner, groupName, description, created, updated, isOpen, approvalThreshold, minBlockDelay, maxBlockDelay, reference, creationGroupId);
groupData.setIsAdmin(isAdmin);
groups.add(groupData);
} while (resultSet.next()); } while (resultSet.next());
return groups; return groups;