mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-15 06:58:41 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -34,7 +34,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*
|
||||
* <p>{@link VideoResource} act as server to serve video information.
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
@@ -44,17 +43,22 @@ public class App {
|
||||
* @param args program argument.
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
var videos = Map.of(
|
||||
1, new Video(1, "Avatar", 178, "epic science fiction film",
|
||||
"James Cameron", "English"),
|
||||
2, new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|",
|
||||
"Hideaki Anno", "Japanese"),
|
||||
3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi",
|
||||
"Christopher Nolan", "English")
|
||||
);
|
||||
var videos =
|
||||
Map.of(
|
||||
1, new Video(1, "Avatar", 178, "epic science fiction film", "James Cameron", "English"),
|
||||
2,
|
||||
new Video(
|
||||
2,
|
||||
"Godzilla Resurgence",
|
||||
120,
|
||||
"Action & drama movie|",
|
||||
"Hideaki Anno",
|
||||
"Japanese"),
|
||||
3,
|
||||
new Video(
|
||||
3, "Interstellar", 169, "Adventure & Sci-Fi", "Christopher Nolan", "English"));
|
||||
var videoResource = new VideoResource(new FieldJsonMapper(), videos);
|
||||
|
||||
|
||||
LOGGER.info("Retrieving full response from server:-");
|
||||
LOGGER.info("Get all video information:");
|
||||
var videoDetails = videoResource.getDetails(1);
|
||||
|
||||
@@ -27,15 +27,13 @@ package com.iluwatar.partialresponse;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* Map a video to json.
|
||||
*/
|
||||
/** Map a video to json. */
|
||||
public class FieldJsonMapper {
|
||||
|
||||
/**
|
||||
* Gets json of required fields from video.
|
||||
*
|
||||
* @param video object containing video information
|
||||
* @param video object containing video information
|
||||
* @param fields fields information to get
|
||||
* @return json of required fields from video
|
||||
*/
|
||||
|
||||
@@ -25,11 +25,16 @@
|
||||
package com.iluwatar.partialresponse;
|
||||
|
||||
/**
|
||||
* {@link Video} is an entity to serve from server.It contains all video related information.
|
||||
* Video is a record class.
|
||||
* {@link Video} is an entity to serve from server.It contains all video related information. Video
|
||||
* is a record class.
|
||||
*/
|
||||
|
||||
public record Video(Integer id, String title, Integer length, String description, String director, String language) {
|
||||
public record Video(
|
||||
Integer id,
|
||||
String title,
|
||||
Integer length,
|
||||
String description,
|
||||
String director,
|
||||
String language) {
|
||||
/**
|
||||
* ToString.
|
||||
*
|
||||
@@ -38,12 +43,24 @@ public record Video(Integer id, String title, Integer length, String description
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{"
|
||||
+ "\"id\": " + id + ","
|
||||
+ "\"title\": \"" + title + "\","
|
||||
+ "\"length\": " + length + ","
|
||||
+ "\"description\": \"" + description + "\","
|
||||
+ "\"director\": \"" + director + "\","
|
||||
+ "\"language\": \"" + language + "\""
|
||||
+ "}";
|
||||
+ "\"id\": "
|
||||
+ id
|
||||
+ ","
|
||||
+ "\"title\": \""
|
||||
+ title
|
||||
+ "\","
|
||||
+ "\"length\": "
|
||||
+ length
|
||||
+ ","
|
||||
+ "\"description\": \""
|
||||
+ description
|
||||
+ "\","
|
||||
+ "\"director\": \""
|
||||
+ director
|
||||
+ "\","
|
||||
+ "\"language\": \""
|
||||
+ language
|
||||
+ "\""
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,18 +27,17 @@ package com.iluwatar.partialresponse;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The resource record class which serves video information. This class act as server in the demo. Which
|
||||
* has all video details.
|
||||
* The resource record class which serves video information. This class act as server in the demo.
|
||||
* Which has all video details.
|
||||
*
|
||||
* @param fieldJsonMapper map object to json.
|
||||
* @param videos initialize resource with existing videos. Act as database.
|
||||
* @param videos initialize resource with existing videos. Act as database.
|
||||
*/
|
||||
|
||||
public record VideoResource(FieldJsonMapper fieldJsonMapper, Map<Integer, Video> videos) {
|
||||
/**
|
||||
* Get Details.
|
||||
*
|
||||
* @param id video id
|
||||
* @param id video id
|
||||
* @param fields fields to get information about
|
||||
* @return full response if no fields specified else partial response for given field.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user