Skip to content

Commit

Permalink
Merge pull request #545 from NDLANO/new-learningpath-status
Browse files Browse the repository at this point in the history
New learningpath status `READY_FOR_PUBLISHING`
  • Loading branch information
jnatten authored Nov 19, 2024
2 parents 4df9a32 + 4ad8f3e commit c397caa
Show file tree
Hide file tree
Showing 50 changed files with 820 additions and 780 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Part of NDLA learningpath-api
* Copyright (C) 2016 NDLA
* Part of NDLA common
* Copyright (C) 2024 NDLA
*
* See LICENSE
*
*/

package no.ndla.learningpathapi.model.domain
package no.ndla.common.model.domain.learningpath

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Part of NDLA common
* Copyright (C) 2024 NDLA
*
* See LICENSE
*
*/

package no.ndla.common.model.domain.learningpath

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import no.ndla.common.model.NDLADate
import no.ndla.common.model.domain.{Content, Tag, Title}
import no.ndla.language.Language.getSupportedLanguages

case class LearningPath(
id: Option[Long],
revision: Option[Int],
externalId: Option[String],
isBasedOn: Option[Long],
title: Seq[Title],
description: Seq[Description],
coverPhotoId: Option[String],
duration: Option[Int],
status: LearningPathStatus,
verificationStatus: LearningPathVerificationStatus,
lastUpdated: NDLADate,
tags: Seq[Tag],
owner: String,
copyright: LearningpathCopyright,
learningsteps: Option[Seq[LearningStep]] = None,
message: Option[Message] = None
) extends Content {

def supportedLanguages: Seq[String] = {
val stepLanguages = learningsteps.getOrElse(Seq.empty).flatMap(_.supportedLanguages)

(getSupportedLanguages(
title,
description,
tags
) ++ stepLanguages).distinct
}

def isPrivate: Boolean = status == LearningPathStatus.PRIVATE
def isPublished: Boolean = status == LearningPathStatus.PUBLISHED
def isDeleted: Boolean = status == LearningPathStatus.DELETED

}

object LearningPath {
implicit val encoder: Encoder[LearningPath] = deriveEncoder
implicit val decoder: Decoder[LearningPath] = deriveDecoder

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Part of NDLA common
* Copyright (C) 2024 NDLA
*
* See LICENSE
*
*/

package no.ndla.common.model.domain.learningpath

import enumeratum.*
import no.ndla.common.errors.{ValidationException, ValidationMessage}

import scala.util.{Failure, Success, Try}

sealed trait LearningPathStatus extends EnumEntry {}
object LearningPathStatus extends Enum[LearningPathStatus] with CirceEnum[LearningPathStatus] {

case object PUBLISHED extends LearningPathStatus
case object PRIVATE extends LearningPathStatus
case object DELETED extends LearningPathStatus
case object UNLISTED extends LearningPathStatus
case object SUBMITTED extends LearningPathStatus
case object READY_FOR_SHARING extends LearningPathStatus

override def values: IndexedSeq[LearningPathStatus] = findValues

def valueOf(s: String): Option[LearningPathStatus] = {
LearningPathStatus.values.find(_.toString == s.toUpperCase)
}

def valueOfOrError(status: String): Try[LearningPathStatus] = {
valueOf(status) match {
case Some(status) => Success(status)
case None =>
Failure(
new ValidationException(
errors = List(ValidationMessage("status", s"'$status' is not a valid publishingstatus."))
)
)
}

}

def valueOfOrDefault(s: String): LearningPathStatus = {
valueOf(s).getOrElse(LearningPathStatus.PRIVATE)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Part of NDLA common
* Copyright (C) 2024 NDLA
*
* See LICENSE
*
*/

package no.ndla.common.model.domain.learningpath

import enumeratum.*

sealed trait LearningPathVerificationStatus extends EnumEntry {}
object LearningPathVerificationStatus
extends Enum[LearningPathVerificationStatus]
with CirceEnum[LearningPathVerificationStatus] {

case object EXTERNAL extends LearningPathVerificationStatus
case object CREATED_BY_NDLA extends LearningPathVerificationStatus
case object VERIFIED_BY_NDLA extends LearningPathVerificationStatus

override def values: IndexedSeq[LearningPathVerificationStatus] = findValues

def valueOf(s: String): Option[LearningPathVerificationStatus] = {
LearningPathVerificationStatus.values.find(_.toString == s.toUpperCase)
}

def valueOfOrDefault(s: String): LearningPathVerificationStatus = {
valueOf(s).getOrElse(LearningPathVerificationStatus.EXTERNAL)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Part of NDLA common
* Copyright (C) 2024 NDLA
*
* See LICENSE
*
*/

package no.ndla.common.model.domain.learningpath

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import no.ndla.common.model.domain.Title
import no.ndla.language.Language.getSupportedLanguages

case class LearningStep(
id: Option[Long],
revision: Option[Int],
externalId: Option[String],
learningPathId: Option[Long],
seqNo: Int,
title: Seq[Title],
description: Seq[Description],
embedUrl: Seq[EmbedUrl],
`type`: StepType,
license: Option[String],
showTitle: Boolean = false,
status: StepStatus = StepStatus.ACTIVE
) {
def supportedLanguages: Seq[String] = {
getSupportedLanguages(
title,
description,
embedUrl
)
}
}

object LearningStep {
implicit val encoder: Encoder[LearningStep] = deriveEncoder
implicit val decoder: Decoder[LearningStep] = deriveDecoder
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* Part of NDLA learningpath-api
* Copyright (C) 2018 NDLA
* Part of NDLA common
* Copyright (C) 2024 NDLA
*
* See LICENSE
*
*/

package no.ndla.learningpathapi.model.domain
package no.ndla.common.model.domain.learningpath

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
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.learningpath

import enumeratum.*
import no.ndla.common.errors.{ValidationException, ValidationMessage}

sealed abstract class StepStatus(override val entryName: String) extends EnumEntry
object StepStatus extends Enum[StepStatus] with CirceEnum[StepStatus] {

case object ACTIVE extends StepStatus("ACTIVE")
case object DELETED extends StepStatus("DELETED")

def values: IndexedSeq[StepStatus] = findValues

def valueOf(s: String): Option[StepStatus] = {
StepStatus.values.find(_.entryName == s)
}

def valueOfOrError(status: String): StepStatus = {
valueOf(status) match {
case Some(s) => s
case None =>
throw new ValidationException(errors = List(ValidationMessage("status", s"'$status' is not a valid status.")))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Part of NDLA common
* Copyright (C) 2024 NDLA
*
* See LICENSE
*
*/

package no.ndla.common.model.domain.learningpath

import enumeratum.*
import no.ndla.common.errors.{ValidationException, ValidationMessage}

sealed trait StepType extends EnumEntry
object StepType extends Enum[StepType] with CirceEnum[StepType] {
case object INTRODUCTION extends StepType
case object TEXT extends StepType
case object QUIZ extends StepType
case object TASK extends StepType
case object MULTIMEDIA extends StepType
case object SUMMARY extends StepType
case object TEST extends StepType

def valueOf(s: String): Option[StepType] = StepType.values.find(_.toString == s)
def valueOfOrDefault(s: String): StepType = valueOf(s).getOrElse(StepType.TEXT)

def valueOfOrError(s: String): StepType = {
valueOf(s) match {
case Some(stepType) => stepType
case None =>
throw new ValidationException(errors = List(ValidationMessage("type", s"'$s' is not a valid steptype.")))
}
}

override def values: IndexedSeq[StepType] = findValues
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
package no.ndla.integrationtests.searchapi.learningpathapi

import no.ndla.common.model.NDLADate
import no.ndla.common.model.domain.learningpath.LearningPath
import no.ndla.integrationtests.UnitSuite
import no.ndla.learningpathapi.LearningpathApiProperties
import no.ndla.network.AuthUser
import no.ndla.scalatestsuite.IntegrationSuite
import no.ndla.search.model.LanguageValue
import no.ndla.searchapi.model.domain
import no.ndla.searchapi.model.domain.IndexingBundle
import no.ndla.{learningpathapi, searchapi}
import org.mockito.ArgumentMatchers.any
Expand Down Expand Up @@ -87,7 +87,7 @@ class LearningpathApiClientTest
AuthUser.setHeader(s"Bearer $exampleToken")
val learningPathApiClient = new LearningPathApiClient(learningpathApiBaseUrl)

val chunks = learningPathApiClient.getChunks[domain.learningpath.LearningPath].toList
val chunks = learningPathApiClient.getChunks[LearningPath].toList
val fetchedLearningPath = chunks.head.get.head

val searchable =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ package no.ndla.learningpathapi.controller

import cats.implicits.catsSyntaxEitherId
import no.ndla.common.model.api.CommaSeparatedList.*
import no.ndla.learningpathapi.model.api.{ErrorHandling, LearningPathDomainDump, LearningPathSummaryV2}
import no.ndla.common.model.domain.learningpath as commonDomain
import no.ndla.learningpathapi.Props
import no.ndla.learningpathapi.model.domain
import no.ndla.learningpathapi.model.api.{ErrorHandling, LearningPathDomainDump, LearningPathSummaryV2}
import no.ndla.learningpathapi.repository.LearningPathRepositoryComponent
import no.ndla.learningpathapi.service.search.{SearchIndexService, SearchService}
import no.ndla.learningpathapi.service.{ReadService, UpdateService}
Expand All @@ -35,7 +35,7 @@ trait InternController {
override val prefix: EndpointInput[Unit] = "intern"
override val enableSwagger = false
private val stringInternalServerError = statusCode(StatusCode.InternalServerError).and(stringBody)
import ErrorHelpers._
import ErrorHelpers.*

override val endpoints: List[ServerEndpoint[Any, Eff]] = List(
getByExternalId,
Expand Down Expand Up @@ -117,7 +117,7 @@ trait InternController {

def dumpSingleLearningPath: ServerEndpoint[Any, Eff] = endpoint.get
.in("dump" / "learningpath" / path[Long]("learningpath_id"))
.out(jsonBody[domain.LearningPath])
.out(jsonBody[commonDomain.LearningPath])
.errorOut(errorOutputsFor(404))
.serverLogicPure { learningpathId =>
learningPathRepository.withId(learningpathId) match {
Expand All @@ -128,8 +128,8 @@ trait InternController {

def postLearningPathDump: ServerEndpoint[Any, Eff] = endpoint.post
.in("dump" / "learningpath")
.in(jsonBody[domain.LearningPath])
.out(jsonBody[domain.LearningPath])
.in(jsonBody[commonDomain.LearningPath])
.out(jsonBody[commonDomain.LearningPath])
.errorOut(errorOutputsFor(404))
.serverLogicPure { dumpToInsert =>
updateService.insertDump(dumpToInsert).asRight
Expand Down
Loading

0 comments on commit c397caa

Please sign in to comment.