Browse Source

Groups API: get invites by group ID or invitee

+ fixed API response models that were incorrectly NOT arrays
split-DB
catbref 6 years ago
parent
commit
e04f9df0dc
  1. 35
      src/main/java/org/qora/api/resource/GroupsResource.java
  2. 2
      src/main/java/org/qora/repository/GroupRepository.java
  3. 2
      src/main/java/org/qora/repository/hsqldb/HSQLDBGroupRepository.java

35
src/main/java/org/qora/api/resource/GroupsResource.java

@ -680,7 +680,7 @@ public class GroupsResource {
} }
@GET @GET
@Path("/invites/{groupid}") @Path("/invites/{address}")
@Operation( @Operation(
summary = "Pending group invites", summary = "Pending group invites",
responses = { responses = {
@ -688,15 +688,38 @@ public class GroupsResource {
description = "group invite", description = "group invite",
content = @Content( content = @Content(
mediaType = MediaType.APPLICATION_JSON, mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = GroupInviteData.class) array = @ArraySchema(schema = @Schema(implementation = GroupInviteData.class))
) )
) )
} }
) )
@ApiErrors({ApiError.REPOSITORY_ISSUE}) @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()) { 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) { } catch (DataException e) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e); throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
} }
@ -711,7 +734,7 @@ public class GroupsResource {
description = "group join requests", description = "group join requests",
content = @Content( content = @Content(
mediaType = MediaType.APPLICATION_JSON, 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", description = "group bans",
content = @Content( content = @Content(
mediaType = MediaType.APPLICATION_JSON, mediaType = MediaType.APPLICATION_JSON,
schema = @Schema(implementation = GroupJoinRequestData.class) array = @ArraySchema(schema = @Schema(implementation = GroupJoinRequestData.class))
) )
) )
} }

2
src/main/java/org/qora/repository/GroupRepository.java

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

2
src/main/java/org/qora/repository/hsqldb/HSQLDBGroupRepository.java

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

Loading…
Cancel
Save