Groups API: get invites by group ID or invitee

+ fixed API response models that were incorrectly NOT arrays
This commit is contained in:
catbref 2019-01-16 15:22:15 +00:00
parent bc4de8f063
commit e04f9df0dc
3 changed files with 31 additions and 8 deletions

View File

@ -680,7 +680,7 @@ public class GroupsResource {
}
@GET
@Path("/invites/{groupid}")
@Path("/invites/{address}")
@Operation(
summary = "Pending group invites",
responses = {
@ -688,15 +688,38 @@ public class GroupsResource {
description = "group invite",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = GroupInviteData.class)
array = @ArraySchema(schema = @Schema(implementation = GroupInviteData.class))
)
)
}
)
@ApiErrors({ApiError.REPOSITORY_ISSUE})
public List<GroupInviteData> getInvites(@PathParam("groupid") int groupId) {
public List<GroupInviteData> getInvitesByInvitee(@PathParam("address") String invitee) {
try (final Repository repository = RepositoryManager.getRepository()) {
return repository.getGroupRepository().getGroupInvites(groupId);
return repository.getGroupRepository().getInvitesByInvitee(invitee);
} catch (DataException e) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
}
}
@GET
@Path("/invites/group/{groupid}")
@Operation(
summary = "Pending group invites",
responses = {
@ApiResponse(
description = "group invite",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
array = @ArraySchema(schema = @Schema(implementation = GroupInviteData.class))
)
)
}
)
@ApiErrors({ApiError.REPOSITORY_ISSUE})
public List<GroupInviteData> getInvitesByGroupId(@PathParam("groupid") int groupId) {
try (final Repository repository = RepositoryManager.getRepository()) {
return repository.getGroupRepository().getInvitesByGroupId(groupId);
} catch (DataException e) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
}
@ -711,7 +734,7 @@ public class GroupsResource {
description = "group join requests",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = GroupJoinRequestData.class)
array = @ArraySchema(schema = @Schema(implementation = GroupJoinRequestData.class))
)
)
}
@ -734,7 +757,7 @@ public class GroupsResource {
description = "group bans",
content = @Content(
mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = GroupJoinRequestData.class)
array = @ArraySchema(schema = @Schema(implementation = GroupJoinRequestData.class))
)
)
}

View File

@ -66,7 +66,7 @@ public interface GroupRepository {
public boolean inviteExists(int groupId, String invitee) throws DataException;
public List<GroupInviteData> getGroupInvites(int groupId) throws DataException;
public List<GroupInviteData> getInvitesByGroupId(int groupId) throws DataException;
public List<GroupInviteData> getInvitesByInvitee(String invitee) throws DataException;

View File

@ -425,7 +425,7 @@ public class HSQLDBGroupRepository implements GroupRepository {
}
@Override
public List<GroupInviteData> getGroupInvites(int groupId) throws DataException {
public List<GroupInviteData> getInvitesByGroupId(int groupId) throws DataException {
List<GroupInviteData> invites = new ArrayList<>();
try (ResultSet resultSet = this.repository.checkedExecute("SELECT inviter, invitee, expiry, reference FROM GroupInvites WHERE group_id = ?", groupId)) {