adamsaghy commented on code in PR #4222:
URL: https://github.com/apache/fineract/pull/4222#discussion_r1890778704


##########
fineract-loan/src/main/java/org/apache/fineract/portfolio/interestpauses/handler/InterestPauseCommandHandler.java:
##########
@@ -0,0 +1,57 @@
+/**
+ * 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.portfolio.interestpauses.handler;
+
+import java.time.LocalDate;
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.commands.handler.NewCommandSourceHandler;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.infrastructure.core.domain.ExternalId;
+import 
org.apache.fineract.portfolio.interestpauses.service.InterestPauseReadPlatformServiceImpl;
+import org.springframework.stereotype.Component;
+
+@Component("interestPauseCommandHandler")
+@RequiredArgsConstructor
+public class InterestPauseCommandHandler implements NewCommandSourceHandler {
+
+    private final InterestPauseReadPlatformServiceImpl interestPauseService;
+
+    @Override
+    public CommandProcessingResult processCommand(final JsonCommand command) {
+        CommandProcessingResult result;
+
+        final LocalDate startDate = 
LocalDate.parse(command.stringValueOfParameterNamed("startDate"));
+        final LocalDate endDate = 
LocalDate.parse(command.stringValueOfParameterNamed("endDate"));
+        final String dateFormat = 
command.stringValueOfParameterNamed("dateFormat");
+        final String locale = command.stringValueOfParameterNamed("locale");
+
+        if (command.getLoanId() != null) {
+            final Long loanId = command.getLoanId();
+            result = interestPauseService.createInterestPauseByLoanId(loanId, 
startDate, endDate, dateFormat, locale);
+        } else if (command.getLoanExternalId() != null) {
+            final ExternalId loanExternalId = command.getLoanExternalId();
+            result = interestPauseService.createInterestPause(loanExternalId, 
startDate, endDate, dateFormat, locale);
+        } else {
+            throw new IllegalArgumentException("Either loanId or 
loanExternalId must be provided.");

Review Comment:
   Please throw `PlatformApiDataValidationException`. IllegalArgumentExceptions 
are not covered by any Exception handler, so it will fallback to HTTP 500 - 
Internal server error which is not good.



-- 
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