|
|
|
|
398
|
VoteResult voteResult = new VoteResult();
|
398
|
VoteResult voteResult = new VoteResult();
|
399
|
Iterable<Vote> allVotes = voteRepository.findVotesByPoll(pollId);
|
399
|
Iterable<Vote> allVotes = voteRepository.findVotesByPoll(pollId);
|
400
|
|
400
|
|
401
|
- // Algorithm to count votes
|
|
|
|
|
401
|
+ //TODO: Implement algorithm to count votes
|
402
|
return new ResponseEntity<VoteResult>(voteResult, HttpStatus.OK);
|
402
|
return new ResponseEntity<VoteResult>(voteResult, HttpStatus.OK);
|
403
|
}
|
403
|
}
|
404
|
```
|
404
|
```
|
|
|
|
|
525
|
There are two steps needed here to externalize and standardize the validation error messages:
|
525
|
There are two steps needed here to externalize and standardize the validation error messages:
|
526
|
|
526
|
|
527
|
- Create a `messages.properties` file in the `src/main/resources` directory with the given properties below
|
527
|
- Create a `messages.properties` file in the `src/main/resources` directory with the given properties below
|
528
|
-- Use an autowired `MessageSource` in the `RestExceptionHandler` to set the message on ValidationError objects (ie: `setMessage(messageSource.getMessage(fe,null));` )
|
|
|
|
|
528
|
+ - `messages.properties` is a key-value file stored in plain text. Your IDE may have a table-based view or show the contents as text
|
|
|
529
|
+ - `.properties` files are a common idiom in Java applications; they contain additional information the application uses that doesn't impact the actual source code.
|
|
|
530
|
+- Use an autowired `MessageSource` object in the `RestExceptionHandler` to set the message on ValidationError objects (ie: `setMessage(messageSource.getMessage(fe,null));` )
|
|
|
531
|
+ - This object will be autowired (or injected) the same way your `CRUDRepository` instances are.
|
529
|
|
532
|
|
530
|
**`messages.properties` content**:
|
533
|
**`messages.properties` content**:
|
531
|
|
534
|
|