-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajustes criticos no projeto com a adição de classe abstrata
- Loading branch information
1 parent
b6368a2
commit 7d755cd
Showing
13 changed files
with
138 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
[ | ||
{ | ||
"id": "tt0468569", | ||
"myRating": 10 | ||
"title": "The Boys", | ||
"rating": 9 | ||
}, | ||
{ | ||
"id": "tt0068646", | ||
"myRating": 5 | ||
"title": "Better Call Saul", | ||
"rating": 10 | ||
}, | ||
{ | ||
"title": "Stranger Things", | ||
"rating": 9 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package com.alura.model; | ||
|
||
public record ContentSticker(String title, String urlImage, Double rating, Double myRating) { | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ContentSticker(String title, String urlImage, String rating, String myRating) { | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
src/main/java/com/alura/model/marvel/PaginateCharacters.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.alura.service; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import com.alura.exception.StickerApiException; | ||
import com.alura.model.ContentSticker; | ||
import com.alura.model.RatingContent; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@SuppressWarnings("squid:S106") | ||
public abstract class AbstractDataApi implements StickerApi { | ||
|
||
private List<ContentSticker> data; | ||
|
||
@Override | ||
public void limitData(int max) { | ||
this.data = this.data.subList(0, max); | ||
} | ||
|
||
public void printDataField(String format, String field) { | ||
System.out.println(format + field + "\033[0m"); | ||
} | ||
|
||
@Override | ||
public void printData() { | ||
for (ContentSticker content : this.data) { | ||
printDataField("\033[1;37m", "\nTitulo: " + content.title()); | ||
printDataField("\033[1;37m", "Image: " + content.urlImage()); | ||
if (Optional.ofNullable(content.rating()).isPresent() && !content.rating().isBlank()) { | ||
printDataField("\033[0;105m", "Classificacao: " + content.rating()); | ||
printDataField("\033[1;33m", "\u2605 ".repeat((int) Math.round(Double.valueOf(content.rating())))); | ||
} else { | ||
printDataField("\033[0;105m", "Sem classificacao"); | ||
} | ||
Optional.ofNullable(content.myRating()).ifPresent( | ||
rating -> printDataField("\033[1;31m", "Minha nota: " + rating)); | ||
} | ||
} | ||
|
||
@Override | ||
public void updateDataWithInput(InputStream inputRating) throws StickerApiException { | ||
try { | ||
List<RatingContent> jsonRating = new ObjectMapper().readValue(inputRating, | ||
new TypeReference<List<RatingContent>>() { | ||
}); | ||
if (!jsonRating.isEmpty()) { | ||
setData(getData().stream() | ||
.map(content -> { | ||
Optional<RatingContent> personalRating = jsonRating.stream() | ||
.filter(rating -> rating.title().equals(content.title())) | ||
.findFirst(); | ||
return personalRating.isPresent() ? new ContentSticker(content.title(), content.urlImage(), | ||
content.rating(), personalRating.get().rating().toString()) : content; | ||
}) | ||
.collect(Collectors.toList())); | ||
} | ||
} catch (IOException e) { | ||
throw new StickerApiException("Erro ao inserir as notas personalizadas.", e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.