Skip to content

Commit

Permalink
Merge pull request #467 from NDLANO/quality-evaluation
Browse files Browse the repository at this point in the history
draft-api: Quality evaluation
  • Loading branch information
katrinewi authored May 7, 2024
2 parents 2b7c05f + 8d4d858 commit 59a3bf8
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ case class Draft(
slug: Option[String],
comments: Seq[Comment],
priority: Priority,
started: Boolean
started: Boolean,
qualityEvaluation: Option[QualityEvaluation]
) extends Content {

def supportedLanguages: Seq[String] =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Part of NDLA common
* Copyright (C) 2024 NDLA
*
* See LICENSE
*/

package no.ndla.common.model.domain.draft

import com.scalatsi.TypescriptType.{TSLiteralNumber, TSUnion}
import com.scalatsi.{TSNamedType, TSType}
import enumeratum.values.{IntCirceEnum, IntEnum, IntEnumEntry}
import sttp.tapir.Schema
import sttp.tapir.codec.enumeratum.*

sealed abstract class Grade(val value: Int) extends IntEnumEntry

object Grade extends IntEnum[Grade] with IntCirceEnum[Grade] {

val values: IndexedSeq[Grade] = findValues
implicit val schema: Schema[Grade] = schemaForIntEnumEntry[Grade]

case object One extends Grade(1)
case object Two extends Grade(2)
case object Three extends Grade(3)
case object Four extends Grade(4)
case object Five extends Grade(5)

implicit val enumTsType: TSNamedType[Grade] = TSType.alias[Grade](
"Grade",
TSUnion(values.map(e => TSLiteralNumber(e.value)))
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Part of NDLA common
* Copyright (C) 2024 NDLA
*
* See LICENSE
*/

package no.ndla.common.model.domain.draft

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}

case class QualityEvaluation(
grade: Grade,
note: String
)

object QualityEvaluation {
implicit def encoder: Encoder[QualityEvaluation] = deriveEncoder
implicit def decoder: Decoder[QualityEvaluation] = deriveDecoder
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ case class Article(
@description("Information about comments attached to the article") comments: Seq[Comment],
@description("If the article should be prioritized") prioritized: Boolean,
@description("If the article should be prioritized. Possible values are prioritized, on-hold, unspecified") priority: String,
@description("If the article has been edited after last status or responsible change") started: Boolean
@description("If the article has been edited after last status or responsible change") started: Boolean,
@description("The quality evaluation of the article. Consist of a score from 1 to 5 and a comment.") qualityEvaluation : Option[QualityEvaluation],
)

object Article {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ case class NewArticle(
@description("The path to the frontpage article") slug: Option[String],
@description("Information about a comment attached to an article") comments: Option[List[NewComment]],
@description("If the article should be prioritized") prioritized: Option[Boolean],
@description("If the article should be prioritized. Possible values are prioritized, on-hold, unspecified") priority: Option[String]
@description("If the article should be prioritized. Possible values are prioritized, on-hold, unspecified") priority: Option[String],
@description("The quality evaluation of the article. Consist of a score from 1 to 5 and a comment.") qualityEvaluation : Option[QualityEvaluation],
)
// format: on

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Part of NDLA draft-api
* Copyright (C) 2024 NDLA
*
* See LICENSE
*/

package no.ndla.draftapi.model.api

import io.circe.{Decoder, Encoder}
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import no.ndla.common.model.domain.draft.Grade
import sttp.tapir.Schema.annotations.description

@description("Quality evaluation of the article")
case class QualityEvaluation(
@description("The grade (1-5) of the article") grade: Grade,
@description("Note explaining the score") note: String
)

object QualityEvaluation {
implicit def encoder: Encoder[QualityEvaluation] = deriveEncoder
implicit def decoder: Decoder[QualityEvaluation] = deriveDecoder
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ case class UpdatedArticle(
@description("The path to the frontpage article") slug: Option[String],
@description("Information about a comment attached to an article") comments: Option[List[UpdatedComment]],
@description("If the article should be prioritized") prioritized: Option[Boolean],
@description("If the article should be prioritized. Possible values are prioritized, on-hold, unspecified") priority: Option[String]
)
@description("If the article should be prioritized. Possible values are prioritized, on-hold, unspecified") priority: Option[String],
@description("The quality evaluation of the article. Consist of a score from 1 to 5 and a comment.") qualityEvaluation : Option[QualityEvaluation],

)
// format: on

object UpdatedArticle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ trait ConverterService {
slug = newArticle.slug,
comments = newCommentToDomain(newArticle.comments.getOrElse(List.empty)),
priority = priority,
started = false
started = false,
qualityEvaluation = qualityEvaluationToDomain(newArticle.qualityEvaluation)
)
)
}
Expand Down Expand Up @@ -168,6 +169,11 @@ trait ConverterService {
)
}

private[service] def qualityEvaluationToDomain(
newQualityEvaluation: Option[api.QualityEvaluation]
): Option[common.draft.QualityEvaluation] =
newQualityEvaluation.map(qe => common.draft.QualityEvaluation(grade = qe.grade, note = qe.note))

private[service] def updatedCommentToDomainNullDocument(
updatedComments: List[UpdatedComment]
): Try[Seq[Comment]] = {
Expand Down Expand Up @@ -403,7 +409,8 @@ trait ConverterService {
comments = article.comments.map(toApiComment),
prioritized = article.priority == Priority.Prioritized,
priority = article.priority.entryName,
started = article.started
started = article.started,
qualityEvaluation = toApiQualityEvaluation(article.qualityEvaluation)
)
)
} else {
Expand Down Expand Up @@ -481,6 +488,12 @@ trait ConverterService {
solved = comment.solved
)

private def toApiQualityEvaluation(
qualityEvaluation: Option[common.draft.QualityEvaluation]
): Option[api.QualityEvaluation] = {
qualityEvaluation.map(qe => api.QualityEvaluation(grade = qe.grade, note = qe.note))
}

def toApiArticleTag(tag: common.Tag): api.ArticleTag = api.ArticleTag(tag.tags, tag.language)

private def toApiRequiredLibrary(required: common.RequiredLibrary): api.RequiredLibrary = {
Expand Down Expand Up @@ -760,7 +773,8 @@ trait ConverterService {
responsible = responsible,
slug = article.slug.orElse(toMergeInto.slug),
comments = updatedComments,
priority = priority
priority = priority,
qualityEvaluation = qualityEvaluationToDomain(article.qualityEvaluation)
)

val articleWithNewContent = article.copy(content = newContent)
Expand Down Expand Up @@ -885,7 +899,8 @@ trait ConverterService {
slug = article.slug,
comments = comments,
priority = priority,
started = false
started = false,
qualityEvaluation = qualityEvaluationToDomain(article.qualityEvaluation)
)
}

Expand Down
28 changes: 19 additions & 9 deletions draft-api/src/test/scala/no/ndla/draftapi/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ object TestData {
Seq.empty,
priority = Priority.Unspecified.entryName,
started = false,
prioritized = false
prioritized = false,
qualityEvaluation = None
)

val blankUpdatedArticle: UpdatedArticle = api.UpdatedArticle(
Expand Down Expand Up @@ -140,7 +141,8 @@ object TestData {
slug = None,
comments = None,
prioritized = None,
priority = None
priority = None,
qualityEvaluation = None
)

val sampleApiUpdateArticle: UpdatedArticle = blankUpdatedArticle.copy(
Expand Down Expand Up @@ -227,7 +229,8 @@ object TestData {
Seq.empty,
false,
Priority.Unspecified.entryName,
false
false,
None
)

val apiArticleUserTest: api.Article = api.Article(
Expand Down Expand Up @@ -279,7 +282,8 @@ object TestData {
Seq.empty,
false,
Priority.Unspecified.entryName,
false
false,
None
)

val sampleTopicArticle: Draft = Draft(
Expand Down Expand Up @@ -312,7 +316,8 @@ object TestData {
None,
Seq.empty,
Priority.Unspecified,
false
false,
None
)

val sampleArticleWithPublicDomain: Draft = Draft(
Expand Down Expand Up @@ -345,7 +350,8 @@ object TestData {
None,
Seq.empty,
Priority.Unspecified,
false
false,
None
)

val sampleDomainArticle: Draft = Draft(
Expand Down Expand Up @@ -380,7 +386,8 @@ object TestData {
None,
Seq.empty,
Priority.Unspecified,
false
false,
None
)

val newArticle: NewArticle = api.NewArticle(
Expand Down Expand Up @@ -418,6 +425,7 @@ object TestData {
None,
None,
None,
None,
None
)

Expand Down Expand Up @@ -467,7 +475,8 @@ object TestData {
slug = None,
comments = Seq.empty,
priority = Priority.Unspecified,
started = false
started = false,
qualityEvaluation = None
)

val apiArticleWithHtmlFaultV2: api.Article = api.Article(
Expand Down Expand Up @@ -522,7 +531,8 @@ object TestData {
comments = Seq.empty,
prioritized = false,
priority = Priority.Unspecified.entryName,
started = false
started = false,
qualityEvaluation = None
)

val (nodeId, nodeId2) = ("1234", "4321")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
slug = None,
comments = Seq.empty,
priority = Priority.Unspecified,
started = false
started = false,
qualityEvaluation = None
)

val updatedNothing = TestData.blankUpdatedArticle.copy(
Expand Down Expand Up @@ -369,7 +370,8 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
slug = None,
comments = Seq.empty,
priority = Priority.Unspecified,
started = false
started = false,
qualityEvaluation = None
)

val expectedArticle = Draft(
Expand Down Expand Up @@ -402,7 +404,8 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
slug = None,
comments = Seq.empty,
priority = Priority.Unspecified,
started = false
started = false,
qualityEvaluation = None
)

val updatedEverything = TestData.blankUpdatedArticle.copy(
Expand Down Expand Up @@ -463,7 +466,8 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
slug = None,
comments = Seq.empty,
priority = Priority.Unspecified,
started = false
started = false,
qualityEvaluation = None
)

val expectedArticle = Draft(
Expand Down Expand Up @@ -496,7 +500,8 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
slug = None,
comments = Seq.empty,
priority = Priority.Unspecified,
started = false
started = false,
qualityEvaluation = None
)

val updatedEverything = TestData.blankUpdatedArticle.copy(
Expand Down Expand Up @@ -1095,7 +1100,8 @@ class ConverterServiceTest extends UnitSuite with TestEnvironment {
slug = Some("kjempe-slug"),
comments = Seq.empty,
priority = Priority.Unspecified,
started = false
started = false,
qualityEvaluation = None
)
val article = common.model.domain.article.Article(
id = Some(articleId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ class StateTransitionRulesTest extends UnitSuite with TestEnvironment {
slug = None,
comments = Seq.empty,
priority = Priority.Unspecified,
started = false
started = false,
qualityEvaluation = None
)
val article = common.article.Article(
id = Some(articleId),
Expand Down Expand Up @@ -477,7 +478,8 @@ class StateTransitionRulesTest extends UnitSuite with TestEnvironment {
slug = None,
comments = Seq.empty,
priority = Priority.Unspecified,
started = false
started = false,
qualityEvaluation = None
)
val status = common.Status(PLANNED, Set.empty)
val transitionsToTest = StateTransitionRules.StateTransitions.filter(_.to == PUBLISHED)
Expand Down Expand Up @@ -532,7 +534,8 @@ class StateTransitionRulesTest extends UnitSuite with TestEnvironment {
slug = None,
comments = Seq.empty,
priority = Priority.Unspecified,
started = false
started = false,
qualityEvaluation = None
)
val status = common.Status(PLANNED, Set.empty)
val transitionsToTest = StateTransitionRules.StateTransitions.filter(_.to == ARCHIVED)
Expand Down Expand Up @@ -591,7 +594,8 @@ class StateTransitionRulesTest extends UnitSuite with TestEnvironment {
slug = None,
comments = Seq.empty,
priority = Priority.Unspecified,
started = false
started = false,
qualityEvaluation = None
)
val status = common.Status(PLANNED, Set.empty)
val transitionsToTest = StateTransitionRules.StateTransitions.filter(_.to == UNPUBLISHED)
Expand Down Expand Up @@ -652,7 +656,8 @@ class StateTransitionRulesTest extends UnitSuite with TestEnvironment {
slug = None,
comments = Seq.empty,
priority = Priority.Unspecified,
started = false
started = false,
qualityEvaluation = None
)
val status = common.Status(PUBLISHED, Set.empty)
val transitionToTest: StateTransition = PUBLISHED -> IN_PROGRESS
Expand Down
Loading

0 comments on commit 59a3bf8

Please sign in to comment.