rymghosn opened a new pull request, #6539:
URL: https://github.com/apache/fineract/pull/6539

   ## Description
   
   JIRA: https://issues.apache.org/jira/browse/FINERACT-2875
   
   `PUT /v1/templates/{templateId}` updates the template whose id is in the 
request body, not the one in the URL, and it rejects a request without a body 
id with an untranslated validation message:
   
   - `PUT /v1/templates/1` with `{"id": 2, ...}` returns `{"resourceId": 2}` 
and updates template 2; template 1 is unchanged.
   - `PUT /v1/templates/1` without `id` returns 400 with the raw key 
`{org.apache.fineract.infrastructure.template.id.not-null}` as the error 
message.
   
   `TemplatesApiResource.saveTemplate` receives the `templateId` path parameter 
but never copies it onto the `TemplateUpdateRequest` before dispatching 
`TemplateUpdateCommand`, and `TemplateDomainServiceImpl.updateTemplate` loads 
the template by `request.getId()`. `TemplateUpdateRequest.id` is `@NotNull`, so 
the body id is mandatory, and that constraint's message key is not defined in 
`ValidationMessages.properties`.
   
   This PR:
   
   - sets the payload id from the path in `saveTemplate`, as `deleteTemplate` 
already does;
   - removes the `@NotNull` on `TemplateUpdateRequest.id` (bean validation runs 
before the method body, so it would otherwise keep the body id mandatory);
   - adds the missing `org.apache.fineract.infrastructure.template.id.not-null` 
message, which `TemplateDeleteRequest` still uses.
   
   A client that already sends the matching id in the body is unaffected.
   
   ### Testing
   
   - New test in `TemplatesApiResourceTest`: `saveTemplate(34L, request)` with 
body id `99` dispatches a payload with id `34`. On `develop` it fails 
(`expected: 34L but was: 99L`); with this PR all 5 tests in the class pass.
   - Live on a local PostgreSQL instance booted with `bootRun`, with two 
freshly created templates:
     - `develop` (`213f517b88`): `PUT /v1/templates/1` with body `id: 2` 
returns 200 `{"resourceId": 2}` and renames template 2; the same request 
without `id` returns 400 with the raw message key above.
     - With this PR (templates 3 and 4): `PUT /v1/templates/3` with body `id: 
4` and without `id` both return 200 `{"resourceId": 3}` and update template 3; 
template 4 is unchanged.
   - `spotlessJavaCheck` passes.
   
   ## Checklist
   
   Please make sure these boxes are checked before submitting your pull request 
- thanks!
   
   - [x] Write the commit message as per [our 
guidelines](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#pull-requests)
   - [x] Acknowledge that we will not review PRs that are not passing the build 
_("green")_ - it is your responsibility to get a proposed PR to pass the build, 
not primarily the project's maintainers.
   - [x] Create/update [unit or integration 
tests](https://fineract.apache.org/docs/current/#_testing) for verifying the 
changes made.
   - [x] Follow our [coding 
conventions](https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions).
   - [ ] Add required Swagger annotation and update API documentation at 
fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with 
details of any API changes (not applicable: no endpoint or schema change; the 
body `id` is no longer required and is ignored)
   - [x] [This PR must not be a "code 
dump"](https://cwiki.apache.org/confluence/display/FINERACT/Pull+Request+Size+Limit).
 Large changes can be made in a branch, with assistance. Ask for help on the 
[developer mailing list](https://fineract.apache.org/#contribute).
   - [x] If merging this PR resolves a JIRA issue, I will mark that issue as 
resolved and set "Fix Version/s" appropriately.
   - [x] I followed the [AI 
Policy](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#ai-policy).
   
   Your assigned reviewer(s) will follow our [guidelines for code 
reviews](https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide).
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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