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
@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))
)
)
}

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 List<GroupInviteData> getGroupInvites(int groupId) throws DataException;
public List<GroupInviteData> getInvitesByGroupId(int groupId) 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
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)) {

Loading…
Cancel
Save