Skip to content

Commit

Permalink
Merge pull request #570 from NDLANO/article-api-disclaimer
Browse files Browse the repository at this point in the history
article-api: Add `disclaimer` to DTO
  • Loading branch information
jnatten authored Jan 3, 2025
2 parents 924d1e4 + 24bc7dc commit 508c905
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import no.ndla.common.implicits.*
import no.ndla.common.model.NDLADate
import no.ndla.common.model.api.{CopyrightDTO, RelatedContent, RelatedContentLinkDTO}
import no.ndla.common.model.api.{CopyrightDTO, DisclaimerDTO, RelatedContent, RelatedContentLinkDTO}
import sttp.tapir.Schema.annotations.description

@description("Information about the article")
Expand Down Expand Up @@ -64,7 +64,9 @@ case class ArticleV2DTO(
@description("The date for the next planned revision which indicates when the article might be outdated")
revisionDate: Option[NDLADate],
@description("The path to the frontpage article")
slug: Option[String]
slug: Option[String],
@description("The disclaimer of the article")
disclaimer: Option[DisclaimerDTO]
)

object ArticleV2DTO {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import no.ndla.articleapi.repository.ArticleRepository
import no.ndla.common
import no.ndla.common.{CirceUtil, Clock, model}
import no.ndla.common.model.{RelatedContentLink, api as commonApi}
import no.ndla.common.model.api.{Delete, LicenseDTO, Missing, UpdateWith}
import no.ndla.common.model.api.{Delete, DisclaimerDTO, LicenseDTO, Missing, UpdateWith}
import no.ndla.common.model.domain.{
ArticleContent,
ArticleMetaImage,
Expand Down Expand Up @@ -259,6 +259,9 @@ trait ConverterService {
.getOrElse(api.ArticleContentV2DTO("", UnknownLanguage.toString))
val metaImage = findByLanguageOrBestEffort(article.metaImage, language).map(toApiArticleMetaImage)
val copyright = toApiCopyright(article.copyright)
val disclaimer = article.disclaimer
.flatMap(d => findByLanguageOrBestEffort(d, language))
.map(d => DisclaimerDTO(d.disclaimer, d.language))

Success(
api.ArticleV2DTO(
Expand All @@ -285,7 +288,8 @@ trait ConverterService {
availability = article.availability.toString,
article.relatedContent.map(toApiRelatedContent),
article.revisionDate,
article.slug
article.slug,
disclaimer
)
)
} else {
Expand Down
9 changes: 6 additions & 3 deletions article-api/src/test/scala/no/ndla/articleapi/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ trait TestData {
availability = Availability.everyone.toString,
relatedContent = Seq.empty,
revisionDate = None,
slug = None
slug = None,
disclaimer = None
)

val apiArticleV2: api.ArticleV2DTO = api.ArticleV2DTO(
Expand Down Expand Up @@ -122,7 +123,8 @@ trait TestData {
availability = Availability.everyone.toString,
relatedContent = Seq.empty,
revisionDate = None,
slug = None
slug = None,
disclaimer = None
)

val sampleArticleWithPublicDomain: Article = Article(
Expand Down Expand Up @@ -278,7 +280,8 @@ trait TestData {
availability = Availability.everyone.toString,
relatedContent = Seq.empty,
revisionDate = None,
slug = None
slug = None,
disclaimer = None
)

val (nodeId, nodeId2) = ("1234", "4321")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*
* Part of NDLA draft-api
* Copyright (C) 2024 NDLA
* Part of NDLA common
* Copyright (C) 2025 NDLA
*
* See LICENSE
*
*/

package no.ndla.draftapi.model.api
package no.ndla.common.model.api

import io.circe.{Decoder, Encoder}
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import sttp.tapir.Schema.annotations.description

case class DisclaimerDTO(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ package no.ndla.draftapi.model.api

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import no.ndla.common.implicits._
import no.ndla.common.implicits.*
import no.ndla.common.model.NDLADate
import no.ndla.common.model.api.draft.CommentDTO
import no.ndla.common.model.api.{DraftCopyrightDTO, RelatedContent, RelatedContentLinkDTO}
import no.ndla.common.model.api.{DisclaimerDTO, DraftCopyrightDTO, RelatedContent, RelatedContentLinkDTO}
import sttp.tapir.Schema.annotations.description

// format: off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.typesafe.scalalogging.StrictLogging
import no.ndla.common.configuration.Constants.EmbedTagName
import no.ndla.common.errors.{ValidationException, ValidationMessage}
import no.ndla.common.implicits.TryQuestionMark
import no.ndla.common.model.api.{Delete, DraftCopyrightDTO, Missing, UpdateWith, draft}
import no.ndla.common.model.api.{Delete, DisclaimerDTO, DraftCopyrightDTO, Missing, UpdateWith, draft}
import no.ndla.common.model.domain.{ArticleContent, Priority, Responsible}
import no.ndla.common.model.domain.draft.DraftStatus.{IMPORTED, PLANNED}
import no.ndla.common.model.domain.draft.{Comment, Draft, DraftStatus}
Expand Down Expand Up @@ -259,7 +259,7 @@ trait ConverterService {
private def toDomainTitle(articleTitle: api.ArticleTitleDTO): common.Title =
common.Title(articleTitle.title, articleTitle.language)

private def toDomainDisclaimer(articleDisclaimer: api.DisclaimerDTO): common.Disclaimer =
private def toDomainDisclaimer(articleDisclaimer: DisclaimerDTO): common.Disclaimer =
common.Disclaimer(articleDisclaimer.disclaimer, articleDisclaimer.language)

private def toDomainContent(articleContent: api.ArticleContentDTO): common.ArticleContent = {
Expand Down Expand Up @@ -461,11 +461,8 @@ trait ConverterService {
def toApiArticleTitle(title: common.Title): api.ArticleTitleDTO =
api.ArticleTitleDTO(Jsoup.parseBodyFragment(title.title).body().text(), title.title, title.language)

private def toApiArticleDisclaimer(disclaimer: common.Disclaimer): api.DisclaimerDTO =
api.DisclaimerDTO(
disclaimer.disclaimer,
disclaimer.language
)
private def toApiArticleDisclaimer(disclaimer: common.Disclaimer): DisclaimerDTO =
DisclaimerDTO(disclaimer.disclaimer, disclaimer.language)

private def toApiArticleContent(content: common.ArticleContent): api.ArticleContentDTO =
api.ArticleContentDTO(content.content, content.language)
Expand Down Expand Up @@ -802,7 +799,7 @@ trait ConverterService {
case Some(newDisclaimer) =>
val updated = mergeLanguageFields(
toMergeInto.disclaimer.getOrElse(Seq.empty),
maybeLang.map(lang => toDomainDisclaimer(api.DisclaimerDTO(newDisclaimer, lang))).toSeq
maybeLang.map(lang => toDomainDisclaimer(DisclaimerDTO(newDisclaimer, lang))).toSeq
)
Option.when(updated.nonEmpty)(updated)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class SearchableDraftTest extends UnitSuite with TestEnvironment {
supportedLanguages = List("en", "nb", "nn"),
notes = List("Note1", "note2"),
contexts = searchableTaxonomyContexts,
contextids = searchableTaxonomyContexts.map(_.contextId),
contextids = searchableTaxonomyContexts.map(_.contextId),
users = List("ndalId54321", "ndalId12345"),
previousVersionsNotes = List("OldNote"),
grepContexts =
Expand Down

0 comments on commit 508c905

Please sign in to comment.