Skip to content

Commit

Permalink
Add DTO suffix to all DTO types
Browse files Browse the repository at this point in the history
  • Loading branch information
jnatten committed Dec 10, 2024
1 parent fcab9ea commit a25b03e
Show file tree
Hide file tree
Showing 441 changed files with 4,859 additions and 5,017 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ trait ArticleControllerV2 {

private case class SummaryWithHeader(
@jsonbody
body: SearchResultV2,
body: SearchResultV2DTO,
@header("search-context")
searchContext: Option[String]
)
Expand All @@ -106,8 +106,8 @@ trait ArticleControllerV2 {
* A Try with scroll result, or the return of the orFunction (Usually a try with a search result).
*/
private def scrollSearchOr(scrollId: Option[String], language: String)(
orFunction: => Try[(SearchResultV2, DynamicHeaders)]
): Try[(SearchResultV2, DynamicHeaders)] =
orFunction: => Try[(SearchResultV2DTO, DynamicHeaders)]
): Try[(SearchResultV2DTO, DynamicHeaders)] =
scrollId match {
case Some(scroll) if !InitialScrollContextKeywords.contains(scroll) =>
articleSearchService.scroll(scroll, language) match {
Expand All @@ -129,7 +129,7 @@ trait ArticleControllerV2 {
.in(pageSize)
.in(pageNo)
.in(language)
.out(jsonBody[TagsSearchResult])
.out(jsonBody[TagsSearchResultDTO])
.errorOut(errorOutputsFor())
.serverLogicPure { case (query, pageSize, pageNo, language) =>
val queryOrEmpty = query.getOrElse("")
Expand Down Expand Up @@ -165,7 +165,7 @@ trait ArticleControllerV2 {
grepCodes: Seq[String],
shouldScroll: Boolean,
feideToken: Option[String]
): Try[(SearchResultV2, DynamicHeaders)] = {
): Try[(SearchResultV2DTO, DynamicHeaders)] = {
val result = readService.search(
query,
sort,
Expand Down Expand Up @@ -207,7 +207,7 @@ trait ArticleControllerV2 {
.in(fallback)
.in(scrollId)
.in(grepCodes)
.out(jsonBody[SearchResultV2])
.out(jsonBody[SearchResultV2DTO])
.out(EndpointOutput.derived[DynamicHeaders])
.errorOut(errorOutputsFor())
.serverLogicPure {
Expand Down Expand Up @@ -260,7 +260,7 @@ trait ArticleControllerV2 {
.in(pageSize)
.in(pageNo)
.errorOut(errorOutputsFor())
.out(jsonBody[Seq[ArticleV2]])
.out(jsonBody[Seq[ArticleV2DTO]])
.serverLogicPure { case (feideToken, ids, fallback, language, mbPageSize, mbPageNo) =>
val pageSize = mbPageSize.getOrElse(props.DefaultPageSize) match {

Expand Down Expand Up @@ -288,9 +288,9 @@ trait ArticleControllerV2 {
.summary("Find published articles.")
.description("Search all articles.")
.in(feideHeader)
.in(jsonBody[ArticleSearchParams])
.in(jsonBody[ArticleSearchParamsDTO])
.errorOut(errorOutputsFor())
.out(jsonBody[SearchResultV2])
.out(jsonBody[SearchResultV2DTO])
.out(EndpointOutput.derived[DynamicHeaders])
.serverLogicPure { case (feideToken, searchParams) =>
val language = searchParams.language.getOrElse(AllLanguages)
Expand Down Expand Up @@ -331,7 +331,7 @@ trait ArticleControllerV2 {
.in(language)
.in(fallback)
.errorOut(errorOutputsFor(410))
.out(jsonBody[ArticleV2])
.out(jsonBody[ArticleV2DTO])
.out(EndpointOutput.derived[DynamicHeaders])
.serverLogicPure { params =>
val (articleId, revisionQuery, feideToken, language, fallback) = params
Expand Down Expand Up @@ -361,7 +361,7 @@ trait ArticleControllerV2 {
.in("external_id")
.in(deprecatedNodeId)
.errorOut(errorOutputsFor(404, 500))
.out(jsonBody[ArticleIdV2])
.out(jsonBody[ArticleIdV2DTO])
.serverLogicPure(externalId => {
readService.getInternalIdByExternalId(externalId) match {
case Some(id) => Right(id)
Expand All @@ -377,7 +377,7 @@ trait ArticleControllerV2 {
.in("external_ids")
.in(deprecatedNodeId)
.errorOut(errorOutputsFor(404, 500))
.out(jsonBody[api.ArticleIds])
.out(jsonBody[api.ArticleIdsDTO])
.serverLogicPure(externalId => {
readService.getArticleIdsByExternalId(externalId) match {
case Some(idObject) => Right(idObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ trait InternController {
.in(query[Int]("page-size").default(250))
.in(query[String]("language").default(Language.AllLanguages))
.in(query[Boolean]("fallback").default(false))
.out(jsonBody[ArticleDump])
.out(jsonBody[ArticleDumpDTO])
.serverLogicPure { case (pageNo, pageSize, language, fallback) =>
readService.getArticlesByPage(pageNo, pageSize, language, fallback).asRight
}
Expand All @@ -129,7 +129,7 @@ trait InternController {
.in("dump" / "article")
.in(query[Int]("page").default(1))
.in(query[Int]("page-size").default(250))
.out(jsonBody[ArticleDomainDump])
.out(jsonBody[ArticleDomainDumpDTO])
.serverLogicPure { case (pageNo, pageSize) =>
readService.getArticleDomainDump(pageNo, pageSize).asRight
}
Expand Down Expand Up @@ -182,7 +182,7 @@ trait InternController {
.in("article" / path[Long]("id"))
.in(query[Option[Int]]("revision"))
.errorOut(errorOutputsFor(401, 403, 404))
.out(jsonBody[ArticleIdV2])
.out(jsonBody[ArticleIdV2DTO])
.requirePermission(ARTICLE_API_WRITE)
.serverLogicPure { _ => params =>
val (id, revision) = params
Expand All @@ -193,7 +193,7 @@ trait InternController {
.in("article" / path[Long]("id") / "unpublish")
.in(query[Option[Int]]("revision"))
.errorOut(errorOutputsFor(401, 403, 404))
.out(jsonBody[ArticleIdV2])
.out(jsonBody[ArticleIdV2DTO])
.requirePermission(ARTICLE_API_WRITE)
.serverLogicPure { _ => params =>
val (id, revision) = params
Expand All @@ -202,11 +202,11 @@ trait InternController {

def partialPublishArticle: ServerEndpoint[Any, Eff] = endpoint.patch
.in("partial-publish" / path[Long]("article_id"))
.in(jsonBody[PartialPublishArticle])
.in(jsonBody[PartialPublishArticleDTO])
.in(query[String]("language").default(Language.AllLanguages))
.in(query[Boolean]("fallback").default(false))
.errorOut(errorOutputsFor(401, 403, 404))
.out(jsonBody[ArticleV2])
.out(jsonBody[ArticleV2DTO])
.requirePermission(ARTICLE_API_WRITE)
.serverLogicPure { _ => params =>
val (articleId, partialUpdateBody, language, fallback) = params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package no.ndla.articleapi.integration
import com.typesafe.scalalogging.StrictLogging
import no.ndla.articleapi.Props
import no.ndla.articleapi.service.ConverterService
import no.ndla.common.model.api.FrontPage
import no.ndla.common.model.api.FrontPageDTO
import no.ndla.network.NdlaClient
import sttp.client3.quick.*

Expand All @@ -24,9 +24,9 @@ trait FrontpageApiClient {

private val frontpageApiBaseUrl = s"$FrontpageApiBaseUrl/frontpage-api/v1/frontpage"

def getFrontpage: Try[FrontPage] = {
def getFrontpage: Try[FrontPageDTO] = {
val req = quickRequest.get(uri"$frontpageApiBaseUrl")
ndlaClient.fetch[FrontPage](req)
ndlaClient.fetch[FrontPageDTO](req)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import io.circe.{Decoder, Encoder}
import sttp.tapir.Schema.annotations.description

@description("The content of the article in the specified language")
case class ArticleContentV2(
case class ArticleContentV2DTO(
@description("The html content") content: String,
@description("ISO 639-1 code that represents the language used in the content") language: String
)

object ArticleContentV2 {
implicit val encoder: Encoder[ArticleContentV2] = deriveEncoder
implicit val decoder: Decoder[ArticleContentV2] = deriveDecoder
object ArticleContentV2DTO {
implicit val encoder: Encoder[ArticleContentV2DTO] = deriveEncoder
implicit val decoder: Decoder[ArticleContentV2DTO] = deriveDecoder
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import no.ndla.common.model.domain.article.Article
import sttp.tapir.Schema.annotations.description

@description("Information about articles")
case class ArticleDomainDump(
case class ArticleDomainDumpDTO(
@description("The total number of articles in the database") totalCount: Long,
@description("For which page results are shown from") page: Int,
@description("The number of results per page") pageSize: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ package no.ndla.articleapi.model.api
import sttp.tapir.Schema.annotations.description

@description("Id for a single Article")
case class ArticleIdV2(@description("The unique id of the article") id: Long)
case class ArticleIdV2DTO(@description("The unique id of the article") id: Long)
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

package no.ndla.articleapi.model.api

case class ArticleIds(articleId: Long, externalIds: List[String])
case class ArticleIdsDTO(articleId: Long, externalIds: List[String])
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import io.circe.{Decoder, Encoder}
import sttp.tapir.Schema.annotations.description

@description("Description of the article introduction")
case class ArticleIntroduction(
case class ArticleIntroductionDTO(
@description("The introduction content") introduction: String,
@description("The html-version introduction content") htmlIntroduction: String,
@description(
"The ISO 639-1 language code describing which article translation this introduction belongs to"
) language: String
)

object ArticleIntroduction {
implicit val encoder: Encoder[ArticleIntroduction] = deriveEncoder
implicit val decoder: Decoder[ArticleIntroduction] = deriveDecoder
object ArticleIntroductionDTO {
implicit val encoder: Encoder[ArticleIntroductionDTO] = deriveEncoder
implicit val decoder: Decoder[ArticleIntroductionDTO] = deriveDecoder
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import io.circe.{Decoder, Encoder}
import sttp.tapir.Schema.annotations.description

@description("Meta description of the article")
case class ArticleMetaDescription(
case class ArticleMetaDescriptionDTO(
@description("The meta description") metaDescription: String,
@description(
"The ISO 639-1 language code describing which article translation this meta description belongs to"
) language: String
)

object ArticleMetaDescription {
implicit val encoder: Encoder.AsObject[ArticleMetaDescription] = deriveEncoder[ArticleMetaDescription]
implicit val decoder: Decoder[ArticleMetaDescription] = deriveDecoder[ArticleMetaDescription]
object ArticleMetaDescriptionDTO {
implicit val encoder: Encoder.AsObject[ArticleMetaDescriptionDTO] = deriveEncoder[ArticleMetaDescriptionDTO]
implicit val decoder: Decoder[ArticleMetaDescriptionDTO] = deriveDecoder[ArticleMetaDescriptionDTO]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import io.circe.{Decoder, Encoder}
import sttp.tapir.Schema.annotations.description

@description("Meta description of the article")
case class ArticleMetaImage(
case class ArticleMetaImageDTO(
@description("The meta image url") url: String,
@description("The alt text for the meta image") alt: String,
@description(
"The ISO 639-1 language code describing which article translation this meta description belongs to"
) language: String
)

object ArticleMetaImage {
implicit val encoder: Encoder[ArticleMetaImage] = deriveEncoder
implicit val decoder: Decoder[ArticleMetaImage] = deriveDecoder
object ArticleMetaImageDTO {
implicit val encoder: Encoder[ArticleMetaImageDTO] = deriveEncoder
implicit val decoder: Decoder[ArticleMetaImageDTO] = deriveDecoder
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import sttp.tapir.Schema.annotations.description

// format: off
@description("The search parameters")
case class ArticleSearchParams(
case class ArticleSearchParamsDTO(
@description("The search query") query: Option[String],
@description("The ISO 639-1 language code describing language used in query-params") language: Option[String],
@description("Return only articles with provided license.") license: Option[String],
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Part of NDLA article-api
* Copyright (C) 2016 NDLA
*
* See LICENSE
*
*/

package no.ndla.articleapi.model.api

import no.ndla.common.model.NDLADate
import sttp.tapir.Schema.annotations.description

@description("Short summary of information about the article")
case class ArticleSummaryV2DTO(
@description("The unique id of the article")
id: Long,
@description("The title of the article")
title: ArticleTitleDTO,
@description("A visual element article")
visualElement: Option[VisualElementDTO],
@description("An introduction for the article")
introduction: Option[ArticleIntroductionDTO],
@description("A metaDescription for the article")
metaDescription: Option[ArticleMetaDescriptionDTO],
@description("A meta image for the article")
metaImage: Option[ArticleMetaImageDTO],
@description("The full url to where the complete information about the article can be found")
url: String,
@description("Describes the license of the article")
license: String,
@description("The type of article this is. Possible values are frontpage-article, standard, topic-article")
articleType: String,
@description("The time when the article was last updated")
lastUpdated: NDLADate,
@description("A list of available languages for this article")
supportedLanguages: Seq[String],
@description("A list of codes from GREP API attached to this article")
grepCodes: Seq[String],
@description("Value that dictates who gets to see the article. Possible values are: everyone/teacher")
availability: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import io.circe.{Decoder, Encoder}
import sttp.tapir.Schema.annotations.description

@description("Description of the tags of the article")
case class ArticleTag(
case class ArticleTagDTO(
@description("The searchable tag.") tags: Seq[String],
@description("ISO 639-1 code that represents the language used in tag") language: String
)

object ArticleTag {
implicit val encoder: Encoder.AsObject[ArticleTag] = deriveEncoder[ArticleTag]
implicit val decoder: Decoder[ArticleTag] = deriveDecoder[ArticleTag]
object ArticleTagDTO {
implicit val encoder: Encoder.AsObject[ArticleTagDTO] = deriveEncoder[ArticleTagDTO]
implicit val decoder: Decoder[ArticleTagDTO] = deriveDecoder[ArticleTagDTO]
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import io.circe.{Decoder, Encoder}
import sttp.tapir.Schema.annotations.description

@description("Description of a title")
case class ArticleTitle(
case class ArticleTitleDTO(
@description("The freetext title of the article") title: String,
@description("The freetext html-version title of the article") htmlTitle: String,
@description("ISO 639-1 code that represents the language used in title") language: String
)

object ArticleTitle {
implicit val encoder: Encoder[ArticleTitle] = deriveEncoder
implicit val decoder: Decoder[ArticleTitle] = deriveDecoder
object ArticleTitleDTO {
implicit val encoder: Encoder[ArticleTitleDTO] = deriveEncoder
implicit val decoder: Decoder[ArticleTitleDTO] = deriveDecoder
}
Loading

0 comments on commit a25b03e

Please sign in to comment.