Skip to content

Commit

Permalink
Generate typescript after renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
jnatten committed Dec 10, 2024
1 parent 9c13d37 commit 5b15973
Show file tree
Hide file tree
Showing 24 changed files with 655 additions and 651 deletions.
Original file line number Diff line number Diff line change
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ trait InternController {
.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 @@ -11,21 +11,32 @@ package no.ndla.articleapi.model.api
import no.ndla.common.model.NDLADate
import sttp.tapir.Schema.annotations.description

// format: off
@description("Short summary of information about the article")
case class ArticleSummaryV2(
@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,
@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
)
// format: on

This file was deleted.

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

package no.ndla.articleapi.model.api

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 sttp.tapir.Schema.annotations.description

@description("Information about the article")
case class ArticleV2DTO(
@description("The unique id of the article")
id: Long,
@description("Link to article on old platform")
oldNdlaUrl: Option[String],
@description("The revision number for the article")
revision: Int,
@description("Available titles for the article")
title: ArticleTitleDTO,
@description("The content of the article in available languages")
content: ArticleContentV2DTO,
@description("Describes the copyright information for the article")
copyright: CopyrightDTO,
@description("Searchable tags for the article")
tags: ArticleTagDTO,
@description("Required libraries in order to render the article")
requiredLibraries: Seq[RequiredLibraryDTO],
@description("A visual element article")
visualElement: Option[VisualElementDTO],
@description("A meta image for the article")
metaImage: Option[ArticleMetaImageDTO],
@description("An introduction for the article")
introduction: Option[ArticleIntroductionDTO],
@description("Meta description for the article")
metaDescription: ArticleMetaDescriptionDTO,
@description("When the article was created")
created: NDLADate,
@description("When the article was last updated")
updated: NDLADate,
@description("By whom the article was last updated")
updatedBy: String,
@description("When the article was last published")
published: NDLADate,
@description("The type of article this is. Possible values are frontpage-article, standard, topic-article")
articleType: String,
@description("The languages this article supports")
supportedLanguages: Seq[String],
@description("A list of codes from GREP API connected to the article")
grepCodes: Seq[String],
@description("A list of conceptIds connected to the article")
conceptIds: Seq[Long],
@description("Value that dictates who gets to see the article. Possible values are: everyone/teacher")
availability: String,
@description("A list of content related to the article")
relatedContent: Seq[RelatedContent],
@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]
)

object ArticleV2DTO {
implicit def eitherEnc: Encoder[Either[RelatedContentLinkDTO, Long]] = eitherEncoder[RelatedContentLinkDTO, Long]
implicit def eitherDec: Decoder[Either[RelatedContentLinkDTO, Long]] = eitherDecoder[RelatedContentLinkDTO, Long]
implicit val encoder: Encoder[ArticleV2DTO] = deriveEncoder
implicit val decoder: Decoder[ArticleV2DTO] = deriveDecoder
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ case class ArticleDumpDTO(
@description("For which page results are shown from") page: Int,
@description("The number of results per page") pageSize: Int,
@description("The chosen search language") language: String,
@description("The search results") results: Seq[ArticleV2]
@description("The search results") results: Seq[ArticleV2DTO]
)
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ trait ConverterService {
article: Article,
language: String,
fallback: Boolean
): Try[api.ArticleV2] = {
): Try[api.ArticleV2DTO] = {
val supportedLanguages = getSupportedArticleLanguages(article)
val isLanguageNeutral = supportedLanguages.contains(UnknownLanguage.toString) && supportedLanguages.length == 1

Expand All @@ -261,7 +261,7 @@ trait ConverterService {
val copyright = toApiCopyright(article.copyright)

Success(
api.ArticleV2(
api.ArticleV2DTO(
article.id.get,
article.id.flatMap(getMainNidUrlToOldNdla),
article.revision.get,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ trait ReadService {
fallback: Boolean,
revision: Option[Int],
feideAccessToken: Option[String]
): Try[Cachable[api.ArticleV2]] = {
): Try[Cachable[api.ArticleV2DTO]] = {
val article = revision match {
case Some(rev) => articleRepository.withIdAndRevision(id, rev)
case None => articleRepository.withId(id)
Expand Down Expand Up @@ -89,13 +89,13 @@ trait ReadService {
slug: String,
language: String,
fallback: Boolean
): Try[Cachable[api.ArticleV2]] = getDomainArticleBySlug(slug).flatMap {
): Try[Cachable[api.ArticleV2DTO]] = getDomainArticleBySlug(slug).flatMap {
case article if article.availability == Availability.everyone =>
val res: Try[Cachable[api.ArticleV2]] =
val res: Try[Cachable[api.ArticleV2DTO]] =
Cachable.yes(converterService.toApiArticleV2(article, language, fallback))
res
case article =>
val res: Try[Cachable[api.ArticleV2]] =
val res: Try[Cachable[api.ArticleV2DTO]] =
Cachable.no(converterService.toApiArticleV2(article, language, fallback))
res
}
Expand Down Expand Up @@ -267,7 +267,7 @@ trait ReadService {
page: Int,
pageSize: Int,
feideAccessToken: Option[String]
): Try[Seq[api.ArticleV2]] = {
): Try[Seq[api.ArticleV2DTO]] = {
if (articleIds.isEmpty) Failure(ValidationException("ids", "Query parameter 'ids' is missing"))
else {
val offset = (page - 1) * pageSize
Expand All @@ -280,7 +280,7 @@ trait ReadService {
}

@tailrec
private def findArticleMenu(article: api.ArticleV2, menus: List[MenuDTO]): Try[MenuDTO] = {
private def findArticleMenu(article: api.ArticleV2DTO, menus: List[MenuDTO]): Try[MenuDTO] = {
if (menus.isEmpty) Failure(NotFoundException(s"Could not find menu for article with id ${article.id}"))
else
menus.find(_.articleId == article.id) match {
Expand All @@ -291,7 +291,7 @@ trait ReadService {
}
}

private def getArticlesForRSSFeed(menu: MenuDTO): Try[Cachable[List[api.ArticleV2]]] = {
private def getArticlesForRSSFeed(menu: MenuDTO): Try[Cachable[List[api.ArticleV2DTO]]] = {
val articleIds = menu.menu.map { case x: MenuDTO => x.articleId }
val articles =
articleIds.traverse(id =>
Expand All @@ -300,7 +300,7 @@ trait ReadService {
articles.map(Cachable.merge)
}

private def toArticleItem(article: api.ArticleV2): String = {
private def toArticleItem(article: api.ArticleV2DTO): String = {
s"""<item>
| <title>${article.title.title}</title>
| <description>${article.metaDescription.metaDescription}</description>
Expand All @@ -315,7 +315,7 @@ trait ReadService {
.getOrElse(s"${props.ndlaFrontendUrl}/article/$id")

private val allBlankLinesRegex = """(?m)^\s*$[\r\n]*""".r
private def toRSSXML(parentArticle: api.ArticleV2, articles: List[api.ArticleV2]): String = {
private def toRSSXML(parentArticle: api.ArticleV2DTO, articles: List[api.ArticleV2DTO]): String = {
val rss = s"""<?xml version="1.0" encoding="utf-8"?>
|<rss version="2.0">
| <channel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ trait WriteService {
partialArticle: PartialPublishArticleDTO,
language: String,
fallback: Boolean
): Try[api.ArticleV2] = {
): Try[api.ArticleV2DTO] = {
articleRepository.withId(articleId).toArticle match {
case None => Failure(NotFoundException(s"Could not find article with id '$articleId' to partial publish"))
case Some(existingArticle) =>
Expand Down
6 changes: 3 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 @@ -49,7 +49,7 @@ trait TestData {

val (articleId, externalId) = (1L, "751234")

val sampleArticleV2: api.ArticleV2 = api.ArticleV2(
val sampleArticleV2: api.ArticleV2DTO = api.ArticleV2DTO(
id = 1,
oldNdlaUrl = None,
revision = 1,
Expand Down Expand Up @@ -85,7 +85,7 @@ trait TestData {
slug = None
)

val apiArticleV2: api.ArticleV2 = api.ArticleV2(
val apiArticleV2: api.ArticleV2DTO = api.ArticleV2DTO(
articleId,
Some(s"//red.ndla.no/node/$externalId"),
2,
Expand Down Expand Up @@ -242,7 +242,7 @@ trait TestData {
slug = None
)

val apiArticleWithHtmlFaultV2: api.ArticleV2 = api.ArticleV2(
val apiArticleWithHtmlFaultV2: api.ArticleV2DTO = api.ArticleV2DTO(
1,
None,
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ReadServiceTest extends UnitSuite with TestEnvironment {
when(articleRepository.withId(1)).thenReturn(Some(toArticleRow(article)))
when(articleRepository.getExternalIdsFromId(any[Long])(any[DBSession])).thenReturn(List("54321"))

val expectedResult: Try[Cachable[api.ArticleV2]] = Cachable.yes(
val expectedResult: Try[Cachable[api.ArticleV2DTO]] = Cachable.yes(
converterService.toApiArticleV2(
article
.copy(content = Seq(expectedArticleContent1), visualElement = Seq(VisualElement(visualElementAfter, "nb"))),
Expand Down
Loading

0 comments on commit 5b15973

Please sign in to comment.