feat: add adult content flag to manga model and related services #47

Merged
rov merged 1 commits from feat/adult into main 2026-04-09 17:56:56 -03:00
13 changed files with 43 additions and 16 deletions
Showing only changes of commit 86f4adc101 - Show all commits

View File

@ -57,7 +57,8 @@ public interface AniListClient {
List<String> genres,
FuzzyDate startDate,
FuzzyDate endDate,
StaffConnection staff) {
StaffConnection staff,
Boolean isAdult) {
public record Title(
String romaji, String english, @JsonProperty("native") String nativeTitle) {}

View File

@ -47,7 +47,8 @@ public interface JikanClient {
Integer chapters,
PublishData published,
List<AuthorData> authors,
List<GenreData> genres) {
List<GenreData> genres,
List<ExplicitGenreData> explicit_genres) {
public record ImageData(ImageUrls jpg) {
public record ImageUrls(String large_image_url) {}
}
@ -57,6 +58,8 @@ public interface JikanClient {
public record AuthorData(Long mal_id, String name) {}
public record GenreData(Long mal_id, String name) {}
public record ExplicitGenreData(Long mal_id, String name) {}
}
}
}

View File

@ -28,7 +28,8 @@ public record MangaDTO(
@NotNull List<MangaProviderDTO> providers,
@NotNull Integer chapterCount,
@NotNull Boolean favorite,
@NotNull Boolean following) {
@NotNull Boolean following,
@NotNull Boolean adult) {
public static MangaDTO from(Manga manga, Boolean favorite, Boolean following) {
return new MangaDTO(
manga.getId(),
@ -48,7 +49,8 @@ public record MangaDTO(
manga.getMangaContentProviders().stream().map(MangaProviderDTO::from).toList(),
manga.getChapterCount(),
favorite,
following);
following,
manga.getAdult());
}
public record MangaProviderDTO(

View File

@ -14,6 +14,7 @@ public record MangaDataDTO(
OffsetDateTime publishedFrom,
OffsetDateTime publishedTo,
Integer chapterCount,
Boolean adult,
List<String> authors,
List<String> genres,
List<String> alternativeTitles,

View File

@ -20,7 +20,8 @@ public record MangaListDTO(
@NotNull List<String> genres,
@NotNull List<String> authors,
@NotNull Double score,
@NotNull Boolean favorite) {
@NotNull Boolean favorite,
@NotNull Boolean adult) {
public static MangaListDTO from(Manga manga, boolean favorite) {
return new MangaListDTO(
manga.getId(),
@ -35,6 +36,7 @@ public record MangaListDTO(
.map(mangaAuthor -> mangaAuthor.getAuthor().getName())
.toList(),
manga.getScore(),
favorite);
favorite,
manga.getAdult());
}
}

View File

@ -7,4 +7,5 @@ public record MangaListFilterDTO(
List<Long> genreIds,
List<String> statuses,
Boolean userFavorites,
Double score) {}
Double score,
Boolean adult) {}

View File

@ -53,6 +53,8 @@ public class Manga {
@Builder.Default private Integer chapterCount = 0;
@Builder.Default private Boolean adult = false;
@Builder.Default private Boolean follow = false;
@Enumerated(EnumType.STRING)
@ -71,8 +73,6 @@ public class Manga {
@Builder.Default
private List<MangaGenre> mangaGenres = new ArrayList<>();
;
@OneToMany(mappedBy = "manga", cascade = CascadeType.ALL, orphanRemoval = true)
@Builder.Default
private List<MangaAlternativeTitle> alternativeTitles = new ArrayList<>();

View File

@ -90,6 +90,7 @@ public class AniListService {
? media.coverImage().extraLarge()
: media.coverImage().large())
.status(mapStatus(media.status()))
.adult(nonNull(media.isAdult()) ? media.isAdult() : false)
.build();
}
@ -111,6 +112,7 @@ public class AniListService {
chapters
coverImage { large, extraLarge }
genres
isAdult
staff {
edges {
role

View File

@ -130,6 +130,7 @@ public class MangaUpdateService {
manga.setPublishedFrom(mangaData.publishedFrom());
manga.setPublishedTo(mangaData.publishedTo());
manga.setChapterCount(mangaData.chapterCount());
manga.setAdult(mangaData.adult());
manga.setState(MangaState.AVAILABLE);
manga.updateAlternativeTitles(alternativeTitles);
manga.updateGenres(genres);

View File

@ -73,6 +73,7 @@ public class MyAnimeListService {
.alternativeTitles(alternativeTitles)
.coverImageUrl(responseData.images().jpg().large_image_url())
.status(mapStatus(responseData.status()))
.adult(nonNull(responseData.explicit_genres()) && !responseData.explicit_genres().isEmpty())
.build();
}

View File

@ -1,6 +1,5 @@
package com.magamochi.common.config;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.boot.info.GitProperties;
@ -9,16 +8,23 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
@RequiredArgsConstructor
public class GitInfoLogger {
private final GitProperties gitProperties;
public GitInfoLogger(GitProperties gitProperties) {
this.gitProperties = gitProperties;
}
@EventListener(ApplicationStartedEvent.class)
public void logGitInfo() {
log.info(
"Git Info :: commit {} ({}) :: built at {}",
gitProperties.getShortCommitId(),
gitProperties.getBranch(),
gitProperties.getCommitTime());
if (gitProperties != null) {
log.info(
"Git Info :: commit {} ({}) :: built at {}",
gitProperties.getShortCommitId(),
gitProperties.getBranch(),
gitProperties.getCommitTime());
} else {
log.info("Git Info :: not available");
}
}
}

View File

@ -1,5 +1,6 @@
package com.magamochi.model.specification;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import com.magamochi.catalog.model.dto.MangaListFilterDTO;
@ -63,6 +64,10 @@ public class MangaSpecification {
predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("score"), filterDTO.score()));
}
if (isNull(filterDTO.adult()) || !filterDTO.adult()) {
predicates.add(criteriaBuilder.equal(root.get("adult"), false));
}
query.distinct(true);
return criteriaBuilder.and(predicates.toArray(Predicate[]::new));

View File

@ -0,0 +1,2 @@
ALTER TABLE mangas
ADD COLUMN adult BOOLEAN NOT NULL DEFAULT FALSE;