kapil-panchal commented on code in PR #4814:
URL: https://github.com/apache/fineract/pull/4814#discussion_r2176793041


##########
fineract-core/src/main/java/org/apache/fineract/organisation/monetary/api/CurrenciesApiResource.java:
##########
@@ -0,0 +1,80 @@
+/**
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.organisation.monetary.api;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.PUT;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
+import java.util.UUID;
+import java.util.function.Supplier;
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.command.core.CommandPipeline;
+import org.apache.fineract.infrastructure.core.service.DateUtils;
+import org.apache.fineract.organisation.monetary.command.CurrencyUpdateCommand;
+import 
org.apache.fineract.organisation.monetary.data.CurrencyConfigurationData;
+import org.apache.fineract.organisation.monetary.data.CurrencyUpdateRequest;
+import org.apache.fineract.organisation.monetary.data.CurrencyUpdateResponse;
+import 
org.apache.fineract.organisation.monetary.service.OrganisationCurrencyReadPlatformService;
+import org.springframework.stereotype.Component;
+
+@Path("/v1/currencies")
+@Component
+@Tag(name = "Currency", description = "Application related configuration 
around viewing/updating the currencies permitted for use within the MFI.")
+@RequiredArgsConstructor
+public class CurrenciesApiResource {
+
+    private final OrganisationCurrencyReadPlatformService readPlatformService;
+    private final CommandPipeline commandPipeline;
+
+    @GET
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Operation(summary = "Retrieve Currency Configuration", description = """
+            Returns the list of currencies permitted for use AND the list of 
currencies not selected (but available for selection).
+
+            Example Requests:
+
+            currencies
+            currencies?fields=selectedCurrencyOptions
+            """)
+    public CurrencyConfigurationData retrieveCurrencies() {
+        return readPlatformService.retrieveCurrencyConfiguration();
+    }
+
+    @PUT
+    @Consumes({ MediaType.APPLICATION_JSON })
+    @Produces({ MediaType.APPLICATION_JSON })
+    @Operation(summary = "Update Currency Configuration", description = 
"Updates the list of currencies permitted for use.")
+    public CurrencyUpdateResponse updateCurrencies(CurrencyUpdateRequest 
request) {
+        final var command = new CurrencyUpdateCommand();
+
+        command.setId(UUID.randomUUID());

Review Comment:
   Q) I have a question on idempotency?
   
   A) Every request generates a new UUID. Even if the payload is the same, it 
will produce a distinct command (with a different UUID). Therefore, multiple 
executions will reprocess the same request, which violates idempotency.
   
   So, if the payload is the same the database (and not the controller) will 
now handle the updation of records. This also means that if the user clicks 
repeatedly many number of times update currency, it will flood the database 
with that many requests.
   
   Rather if we,
   UUID commandId = 
UUID.nameUUIDFromBytes(request.toString().getBytes(StandardCharsets.UTF_8));
   command.setId(commandId); (here based on payload the UUID will stay 
constant) - I will be implementing similar logic in my POST method which will 
insert a new currency?
   
   This way we can make an if check and return response if the user has pressed 
twice the update button?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to