-
Notifications
You must be signed in to change notification settings - Fork 4
MX-263: add admin CRUD endpoints for office services and geolocation #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
IOhacker
merged 1 commit into
openMF:develop
from
DeathGun44:MX-263-office-admin-crud-endpoints
May 28, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
227 changes: 227 additions & 0 deletions
227
src/main/java/org/apache/fineract/savings/office/api/OfficeExtensionApiResource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||
| * agreements. See the NOTICE file distributed with this work for additional information regarding | ||
| * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance with the License. You may obtain a | ||
| * copy of the License at | ||
| * | ||
| * <p>http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * <p>Unless required by applicable law or agreed to in writing, software distributed under the | ||
| * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.fineract.savings.office.api; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.ws.rs.Consumes; | ||
| import jakarta.ws.rs.DELETE; | ||
| import jakarta.ws.rs.GET; | ||
| import jakarta.ws.rs.POST; | ||
| import jakarta.ws.rs.PUT; | ||
| import jakarta.ws.rs.Path; | ||
| import jakarta.ws.rs.PathParam; | ||
| import jakarta.ws.rs.Produces; | ||
| import jakarta.ws.rs.core.MediaType; | ||
| import java.util.Collection; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; | ||
| import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer; | ||
| import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; | ||
| import org.apache.fineract.savings.office.data.OfficeGeolocationData; | ||
| import org.apache.fineract.savings.office.data.OfficeServiceData; | ||
| import org.apache.fineract.savings.office.service.OfficeExtensionReadPlatformService; | ||
| import org.apache.fineract.savings.office.service.OfficeExtensionWritePlatformService; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * JAX-RS resource exposing admin CRUD endpoints for office services and geolocation under {@code | ||
| * /v2/offices/{officeId}/services} and {@code /v2/offices/{officeId}/geolocation}. | ||
| */ | ||
| @Path("/v2/offices") | ||
| @Component | ||
| @Tag( | ||
| name = "Office Extensions", | ||
| description = | ||
| "Admin endpoints for managing office services and geolocation data. These endpoints populate" | ||
| + " the data consumed by the self-service office endpoints in the selfservice-plugin.") | ||
| @RequiredArgsConstructor | ||
| public class OfficeExtensionApiResource { | ||
|
|
||
| private static final String RESOURCE_NAME_FOR_PERMISSIONS = "OFFICE"; | ||
|
|
||
| private final PlatformSecurityContext context; | ||
| private final OfficeExtensionReadPlatformService readService; | ||
| private final OfficeExtensionWritePlatformService writeService; | ||
| private final DefaultToApiJsonSerializer<OfficeServiceData> serviceSerializer; | ||
| private final DefaultToApiJsonSerializer<OfficeGeolocationData> geolocationSerializer; | ||
|
|
||
| /** | ||
| * Lists all services associated with the given office. | ||
| * | ||
| * @param officeId the office identifier | ||
| * @return JSON array of office service data | ||
| */ | ||
| @GET | ||
| @Path("{officeId}/services") | ||
| @Produces({MediaType.APPLICATION_JSON}) | ||
| @Operation( | ||
| summary = "List Office Services", | ||
| description = "Returns all services configured for the specified office.") | ||
| @ApiResponse( | ||
| responseCode = "200", | ||
| description = "OK", | ||
| content = | ||
| @Content( | ||
| array = @ArraySchema(schema = @Schema(implementation = OfficeServiceData.class)))) | ||
| public String retrieveOfficeServices( | ||
| @PathParam("officeId") @Parameter(description = "officeId") final Long officeId) { | ||
| this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS); | ||
| final Collection<OfficeServiceData> data = readService.retrieveOfficeServices(officeId); | ||
| return serviceSerializer.serializeResult(data); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new service for the given office. | ||
| * | ||
| * @param officeId the office identifier | ||
| * @param jsonBody the JSON request body | ||
| * @return JSON with the created service id | ||
| */ | ||
| @POST | ||
| @Path("{officeId}/services") | ||
| @Consumes({MediaType.APPLICATION_JSON}) | ||
| @Produces({MediaType.APPLICATION_JSON}) | ||
| @Operation( | ||
| summary = "Create Office Service", | ||
| description = "Adds a new service to the specified office.") | ||
| @ApiResponse(responseCode = "200", description = "OK") | ||
| public String createOfficeService( | ||
| @PathParam("officeId") @Parameter(description = "officeId") final Long officeId, | ||
| @Parameter(hidden = true) final String jsonBody) { | ||
| this.context.authenticatedUser().validateHasCreatePermission(RESOURCE_NAME_FOR_PERMISSIONS); | ||
| final CommandProcessingResult result = writeService.createOfficeService(officeId, jsonBody); | ||
| return serviceSerializer.serializeResult(result); | ||
| } | ||
|
|
||
| /** | ||
| * Updates an existing office service. | ||
| * | ||
| * @param officeId the office identifier | ||
| * @param serviceId the service identifier | ||
| * @param jsonBody the JSON request body | ||
| * @return JSON with the changes applied | ||
| */ | ||
| @PUT | ||
| @Path("{officeId}/services/{serviceId}") | ||
| @Consumes({MediaType.APPLICATION_JSON}) | ||
| @Produces({MediaType.APPLICATION_JSON}) | ||
| @Operation( | ||
| summary = "Update Office Service", | ||
| description = "Updates a specific service for the office.") | ||
| @ApiResponse(responseCode = "200", description = "OK") | ||
| public String updateOfficeService( | ||
| @PathParam("officeId") @Parameter(description = "officeId") final Long officeId, | ||
| @PathParam("serviceId") @Parameter(description = "serviceId") final Long serviceId, | ||
| @Parameter(hidden = true) final String jsonBody) { | ||
| this.context.authenticatedUser().validateHasUpdatePermission(RESOURCE_NAME_FOR_PERMISSIONS); | ||
| final CommandProcessingResult result = | ||
| writeService.updateOfficeService(officeId, serviceId, jsonBody); | ||
| return serviceSerializer.serializeResult(result); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Deletes an office service. | ||
| * | ||
| * @param officeId the office identifier | ||
| * @param serviceId the service identifier | ||
| * @return JSON with the deleted service id | ||
| */ | ||
| @DELETE | ||
| @Path("{officeId}/services/{serviceId}") | ||
| @Produces({MediaType.APPLICATION_JSON}) | ||
| @Operation( | ||
| summary = "Delete Office Service", | ||
| description = "Removes a specific service from the office.") | ||
| @ApiResponse(responseCode = "200", description = "OK") | ||
| public String deleteOfficeService( | ||
| @PathParam("officeId") @Parameter(description = "officeId") final Long officeId, | ||
| @PathParam("serviceId") @Parameter(description = "serviceId") final Long serviceId) { | ||
| this.context.authenticatedUser().validateHasDeletePermission(RESOURCE_NAME_FOR_PERMISSIONS); | ||
| final CommandProcessingResult result = writeService.deleteOfficeService(officeId, serviceId); | ||
| return serviceSerializer.serializeResult(result); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves the geolocation for the given office. | ||
| * | ||
| * @param officeId the office identifier | ||
| * @return JSON representation of geolocation data | ||
| */ | ||
| @GET | ||
| @Path("{officeId}/geolocation") | ||
| @Produces({MediaType.APPLICATION_JSON}) | ||
| @Operation( | ||
| summary = "Retrieve Office Geolocation", | ||
| description = "Returns the latitude and longitude of the specified office.") | ||
| @ApiResponse( | ||
| responseCode = "200", | ||
| description = "OK", | ||
| content = @Content(schema = @Schema(implementation = OfficeGeolocationData.class))) | ||
| public String retrieveOfficeGeolocation( | ||
| @PathParam("officeId") @Parameter(description = "officeId") final Long officeId) { | ||
| this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS); | ||
| final OfficeGeolocationData data = readService.retrieveOfficeGeolocation(officeId); | ||
| return geolocationSerializer.serializeResult(data); | ||
| } | ||
|
|
||
| /** | ||
| * Creates or updates the geolocation for the given office. | ||
| * | ||
| * @param officeId the office identifier | ||
| * @param jsonBody the JSON request body containing latitude and longitude | ||
| * @return JSON with the geolocation record id | ||
| */ | ||
| @PUT | ||
| @Path("{officeId}/geolocation") | ||
| @Consumes({MediaType.APPLICATION_JSON}) | ||
| @Produces({MediaType.APPLICATION_JSON}) | ||
| @Operation( | ||
| summary = "Save Office Geolocation", | ||
| description = "Creates or updates the geolocation for the office (1:1 relationship).") | ||
| @ApiResponse(responseCode = "200", description = "OK") | ||
| public String saveOfficeGeolocation( | ||
| @PathParam("officeId") @Parameter(description = "officeId") final Long officeId, | ||
| @Parameter(hidden = true) final String jsonBody) { | ||
| this.context.authenticatedUser().validateHasUpdatePermission(RESOURCE_NAME_FOR_PERMISSIONS); | ||
| final CommandProcessingResult result = writeService.saveOfficeGeolocation(officeId, jsonBody); | ||
| return geolocationSerializer.serializeResult(result); | ||
| } | ||
|
|
||
| /** | ||
| * Deletes the geolocation for the given office. | ||
| * | ||
| * @param officeId the office identifier | ||
| * @return JSON with the deleted office id | ||
| */ | ||
| @DELETE | ||
| @Path("{officeId}/geolocation") | ||
| @Produces({MediaType.APPLICATION_JSON}) | ||
| @Operation( | ||
| summary = "Delete Office Geolocation", | ||
| description = "Removes the geolocation data for the office.") | ||
| @ApiResponse(responseCode = "200", description = "OK") | ||
| public String deleteOfficeGeolocation( | ||
| @PathParam("officeId") @Parameter(description = "officeId") final Long officeId) { | ||
| this.context.authenticatedUser().validateHasDeletePermission(RESOURCE_NAME_FOR_PERMISSIONS); | ||
| final CommandProcessingResult result = writeService.deleteOfficeGeolocation(officeId); | ||
| return geolocationSerializer.serializeResult(result); | ||
| } | ||
| } | ||
84 changes: 84 additions & 0 deletions
84
src/main/java/org/apache/fineract/savings/office/data/OfficeGeolocationData.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more contributor license | ||
| * agreements. See the NOTICE file distributed with this work for additional information regarding | ||
| * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance with the License. You may obtain a | ||
| * copy of the License at | ||
| * | ||
| * <p>http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * <p>Unless required by applicable law or agreed to in writing, software distributed under the | ||
| * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.fineract.savings.office.data; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| /** Immutable data transfer object representing an office's geographic coordinates. */ | ||
| public final class OfficeGeolocationData { | ||
|
|
||
| private final Long id; | ||
| private final Long officeId; | ||
| private final BigDecimal latitude; | ||
| private final BigDecimal longitude; | ||
|
|
||
| private OfficeGeolocationData( | ||
| final Long id, final Long officeId, final BigDecimal latitude, final BigDecimal longitude) { | ||
| this.id = id; | ||
| this.officeId = officeId; | ||
| this.latitude = latitude; | ||
| this.longitude = longitude; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new instance. | ||
| * | ||
| * @param id the geolocation record identifier | ||
| * @param officeId the parent office identifier | ||
| * @param latitude the latitude in decimal degrees (-90 to 90) | ||
| * @param longitude the longitude in decimal degrees (-180 to 180) | ||
| * @return a new {@code OfficeGeolocationData} | ||
| */ | ||
| public static OfficeGeolocationData instance( | ||
| final Long id, final Long officeId, final BigDecimal latitude, final BigDecimal longitude) { | ||
| return new OfficeGeolocationData(id, officeId, latitude, longitude); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the geolocation record identifier. | ||
| * | ||
| * @return the record id, never {@code null} | ||
| */ | ||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the associated office identifier. | ||
| * | ||
| * @return the office id, never {@code null} | ||
| */ | ||
| public Long getOfficeId() { | ||
| return officeId; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the latitude in decimal degrees. | ||
| * | ||
| * @return the latitude value (-90 to 90), never {@code null} | ||
| */ | ||
| public BigDecimal getLatitude() { | ||
| return latitude; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the longitude in decimal degrees. | ||
| * | ||
| * @return the longitude value (-180 to 180), never {@code null} | ||
| */ | ||
| public BigDecimal getLongitude() { | ||
| return longitude; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.