Bladeren bron

Merge branch 'master' of https://git.zipcode.rocks/Cohort4.2/SpringQuickPoll

Yesoda Sanka 5 jaren geleden
bovenliggende
commit
5a6c4ee399
1 gewijzigde bestanden met toevoegingen van 12 en 9 verwijderingen
  1. 12
    9
      README.md

+ 12
- 9
README.md Bestand weergeven

@@ -140,7 +140,7 @@ public ResponseEntity<Iterable<Poll>> getAllPolls() {
140 140
 * Launch the [Postman](https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en) app and enter the URI `http://localhost:8080/polls` and hit Send.
141 141
 * Because we don’t have any polls created yet, this command should result in an empty collection.
142 142
 * If your application cannot run because something is occupying a port, use this command with the respective port number specified:
143
-	* ``kill -kill `lsof -t -i tcp:8080` ``
143
+	* ``npx kill-port 8080``
144 144
 
145 145
 
146 146
 
@@ -506,7 +506,7 @@ public ResponseEntity<?> handleResourceNotFoundException(ResourceNotFoundExcepti
506 506
 
507 507
 
508 508
 
509
-## Part 5.4 - Validating domain entities
509
+## Part 5.5 - Validating domain entities
510 510
 
511 511
 Now it's time to make sure that all objects persisted to the database actually contain valid values. Use the `org.hibernate.validator.constraints.NotEmpty` and `javax.validation.constraints.Size` and `javax.validation.Valid` annotations for validation.
512 512
 
@@ -515,7 +515,7 @@ Now it's time to make sure that all objects persisted to the database actually c
515 515
   - `question` should be `@NotEmpty`
516 516
 - To enforce these validations, add `@Valid` annotations to Poll objects in `RequestMapping`-annotated controller methods (there should be 2)
517 517
 
518
-## Part 5.5 - Customizing validation errors
518
+## Part 5.6 - Customizing validation errors
519 519
 
520 520
 In order to customize validation errors we'll need a class for error information. Create a `ValidationError` class in `io.zipcoder.tc_spring_poll_application.dto.error` with the following fields and appropriate getters and setters:
521 521
 
@@ -525,14 +525,14 @@ In order to customize validation errors we'll need a class for error information
525 525
 We also need a new field in the `ErrorDetail` class to hold errors. There may be multiple validation errors associated with a request, sometimes more than one of the same type, so this field will be a collection, specifically a `Map<String, List<ValidationError>> errors` field.
526 526
 
527 527
 
528
-## Part 5.6 - Create a validation error handler
528
+## Part 5.7 - Create a validation error handler
529 529
 
530 530
 - add below handler to `RestExceptionHandler`
531 531
 
532 532
 ```java
533 533
 @ExceptionHandler(MethodArgumentNotValidException.class)
534 534
 public ResponseEntity<?>
535
-handleValidationError(  MethodArgumentNotValidException manve,
535
+handleValidationError(MethodArgumentNotValidException manve,
536 536
 						HttpServletRequest request){...}
537 537
 ```
538 538
 
@@ -559,7 +559,10 @@ for(FieldError fe : fieldErrors) {
559 559
 }
560 560
 ```
561 561
 
562
-## Part 5.7 - Externalize strings in a messages.properties file
562
+- Use an autowired `MessageSource` object in the `RestExceptionHandler` to set the message on ValidationError objects (ie: `setMessage(messageSource.getMessage(fe,null));` )
563
+  - This object will be autowired (or injected) the same way your `CRUDRepository` instances are.
564
+
565
+## Part 5.8 - Externalize strings in a messages.properties file
563 566
 
564 567
 Commonly used strings in your Java program can be removed from the source code and placed in a separate file. This is called externalizing, and is useful for allowing changes to text displayed without impacting actual program logic. One example of where this is done is in internationalization, the practice of providing multilingual support in an application, allowing users to use an application in their native language.
565 568
 
@@ -568,8 +571,7 @@ There are two steps needed here to externalize and standardize the validation er
568 571
 - Create a `messages.properties` file in the `src/main/resources` directory with the given properties below
569 572
   - `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
570 573
   - `.properties` files are a common idiom in Java applications; they contain additional information the application uses that doesn't impact the actual source code.
571
-- Use an autowired `MessageSource` object in the `RestExceptionHandler` to set the message on ValidationError objects (ie: `setMessage(messageSource.getMessage(fe,null));` )
572
-  - This object will be autowired (or injected) the same way your `CRUDRepository` instances are.
574
+
573 575
 
574 576
 **`messages.properties` content**:
575 577
 
@@ -646,6 +648,7 @@ Size.poll.options=Options must be greater than {2} and less than {1}
646 648
 ## Part 6.2 - Spring's Built-in Pagination
647 649
 
648 650
 * Make use of Spring's built-in page number pagination support by researching `org.springframework.data.repository.PagingAndSortingRepository`.
649
-* Modify respective `Controller` methods to handle `Pageable` arguments.
651
+* Modify respective `Controller` methods to handle `Pageable` arguments and `Page<T>` return-types.
652
+* Modify respective `Repository` methods to handle `Page<T>` objects.
650 653
 * Send a `GET` request to `http://localhost:8080/polls?page=0&size=2` via Postman.
651 654
 * Ensure the response is a `JSON` object with pagination-specific information.