Skip to content

Commit

Permalink
Merge pull request #579 from NDLANO/default-values-on-create-learning…
Browse files Browse the repository at this point in the history
…path

Default values on create learningpath
  • Loading branch information
gunnarvelle authored Jan 22, 2025
2 parents 3d1d8be + 3e4fcac commit e9028d0
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ trait ImageControllerV2 {
val imageControllerV2: ImageControllerV2

class ImageControllerV2 extends TapirController with BaseImageController {
import ErrorHelpers._
import props._
import ErrorHelpers.*
import props.*

override val serviceName: String = "images V2"
override val prefix: EndpointInput[Unit] = "image-api" / "v2" / "images"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ trait InternController {
override val endpoints: List[ServerEndpoint[Any, Eff]] = List(
getByExternalId,
postIndex,
deleteIndex,
deleteIndex(),
dumpLearningpaths,
dumpSingleLearningPath,
postLearningPathDump,
containsArticle
)

def getByExternalId: ServerEndpoint[Any, Eff] = endpoint.get
private def getByExternalId: ServerEndpoint[Any, Eff] = endpoint.get
.in("id" / path[String]("external_id"))
.out(stringBody)
.errorOut(errorOutputsFor(404))
Expand All @@ -59,7 +59,7 @@ trait InternController {

}

def postIndex: ServerEndpoint[Any, Eff] = endpoint.post
private def postIndex: ServerEndpoint[Any, Eff] = endpoint.post
.in("index")
.in(query[Option[Int]]("numShards"))
.out(stringBody)
Expand All @@ -77,7 +77,7 @@ trait InternController {
}
}

def deleteIndex: ServerEndpoint[Any, Eff] = endpoint.delete
private def deleteIndex(): ServerEndpoint[Any, Eff] = endpoint.delete
.in("index")
.out(stringBody)
.errorOut(stringInternalServerError)
Expand Down Expand Up @@ -105,7 +105,7 @@ trait InternController {
}
}

def dumpLearningpaths: ServerEndpoint[Any, Eff] = endpoint.get
private def dumpLearningpaths: ServerEndpoint[Any, Eff] = endpoint.get
.in("dump" / "learningpath")
.in(query[Int]("page").default(1))
.in(query[Int]("page-size").default(250))
Expand All @@ -115,7 +115,7 @@ trait InternController {
readService.getLearningPathDomainDump(pageNo, pageSize, onlyIncludePublished).asRight
}

def dumpSingleLearningPath: ServerEndpoint[Any, Eff] = endpoint.get
private def dumpSingleLearningPath: ServerEndpoint[Any, Eff] = endpoint.get
.in("dump" / "learningpath" / path[Long]("learningpath_id"))
.out(jsonBody[commonDomain.LearningPath])
.errorOut(errorOutputsFor(404))
Expand All @@ -126,7 +126,7 @@ trait InternController {
}
}

def postLearningPathDump: ServerEndpoint[Any, Eff] = endpoint.post
private def postLearningPathDump: ServerEndpoint[Any, Eff] = endpoint.post
.in("dump" / "learningpath")
.in(jsonBody[commonDomain.LearningPath])
.out(jsonBody[commonDomain.LearningPath])
Expand All @@ -135,7 +135,7 @@ trait InternController {
updateService.insertDump(dumpToInsert).asRight
}

def containsArticle: ServerEndpoint[Any, Eff] = endpoint.get
private def containsArticle: ServerEndpoint[Any, Eff] = endpoint.get
.in("containsArticle")
.in(listQuery[String]("paths"))
.out(jsonBody[Seq[LearningPathSummaryV2DTO]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,21 @@ trait LearningpathControllerV2 {
getLearningStep,
fetchLearningPathContainingArticle,
getLearningStepStatus,
addLearningpath,
addLearningpath(),
copyLearningpath,
updateLearningPath,
addLearningStep,
updateLearningStep,
updateLearningPath(),
addLearningStep(),
updateLearningStep(),
updatedLearningstepSeqNo,
updateLearningStepStatus,
updateLearningPathStatus,
updateLearningStepStatus(),
updateLearningPathStatus(),
withStatus,
deleteLearningpath,
deleteLearningStep,
updateLearningPathTaxonomy
deleteLearningpath(),
deleteLearningStep(),
updateLearningPathTaxonomy()
)

def getLearningpaths: ServerEndpoint[Any, Eff] = endpoint.get
private def getLearningpaths: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Find public learningpaths")
.description("Show public learningpaths.")
.in(queryParam)
Expand Down Expand Up @@ -248,7 +248,7 @@ trait LearningpathControllerV2 {
}.handleErrorsOrOk
}

def postSearch: ServerEndpoint[Any, Eff] = endpoint.post
private def postSearch: ServerEndpoint[Any, Eff] = endpoint.post
.summary("Find public learningpaths")
.description("Show public learningpaths")
.in("search")
Expand All @@ -274,7 +274,7 @@ trait LearningpathControllerV2 {
}.handleErrorsOrOk
}

def getLearningpathsByIds: ServerEndpoint[Any, Eff] = endpoint.get
private def getLearningpathsByIds: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Fetch learningpaths that matches ids parameter.")
.description("Returns learningpaths that matches ids parameter.")
.in("ids")
Expand Down Expand Up @@ -307,7 +307,7 @@ trait LearningpathControllerV2 {
}
}

def getLearningpath: ServerEndpoint[Any, Eff] = endpoint.get
private def getLearningpath: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Fetch details about the specified learningpath")
.description("Shows all information about the specified learningpath.")
.in(pathLearningpathId)
Expand All @@ -322,7 +322,7 @@ trait LearningpathControllerV2 {
}
}

def getLearningpathStatus: ServerEndpoint[Any, Eff] = endpoint.get
private def getLearningpathStatus: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Show status information for the learningpath")
.description("Shows publishingstatus for the learningpath")
.in(pathLearningpathId / "status")
Expand All @@ -331,7 +331,7 @@ trait LearningpathControllerV2 {
.withOptionalMyNDLAUserOrTokenUser
.serverLogicPure { maybeUser => id => readService.statusFor(id, maybeUser).handleErrorsOrOk }

def getLearningsteps: ServerEndpoint[Any, Eff] = endpoint.get
private def getLearningsteps: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Fetch learningsteps for given learningpath")
.description("Show all learningsteps for given learningpath id")
.in(pathLearningpathId / "learningsteps")
Expand All @@ -354,7 +354,7 @@ trait LearningpathControllerV2 {
}
}

def getLearningStep: ServerEndpoint[Any, Eff] = endpoint.get
private def getLearningStep: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Fetch details about the specified learningstep")
.description("Show the given learningstep for the given learningpath")
.in(pathLearningpathId / "learningsteps" / pathLearningstepId)
Expand All @@ -371,7 +371,7 @@ trait LearningpathControllerV2 {
}
}

def getLearningStepsInTrash: ServerEndpoint[Any, Eff] = endpoint.get
private def getLearningStepsInTrash: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Fetch deleted learningsteps for given learningpath")
.description("Show all learningsteps for the given learningpath that are marked as deleted")
.in(pathLearningpathId / "learningsteps" / "trash")
Expand All @@ -386,7 +386,7 @@ trait LearningpathControllerV2 {
}
}

def getLearningStepStatus: ServerEndpoint[Any, Eff] = endpoint.get
private def getLearningStepStatus: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Show status information for learningstep")
.description("Shows status for the learningstep")
.in(pathLearningpathId / "learningsteps" / pathLearningstepId / "status")
Expand All @@ -408,7 +408,7 @@ trait LearningpathControllerV2 {
}
}

def getMyLearningpaths: ServerEndpoint[Any, Eff] = endpoint.get
private def getMyLearningpaths: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Fetch all learningspaths you have created")
.description("Shows your learningpaths.")
.in("mine")
Expand All @@ -435,7 +435,7 @@ trait LearningpathControllerV2 {
licenses.map(x => LicenseDTO(x.license.toString, Option(x.description), x.url)).asRight
}

def addLearningpath: ServerEndpoint[Any, Eff] = endpoint.post
private def addLearningpath(): ServerEndpoint[Any, Eff] = endpoint.post
.summary("Store new learningpath")
.description("Adds the given learningpath")
.in(jsonBody[NewLearningPathV2DTO])
Expand All @@ -453,7 +453,7 @@ trait LearningpathControllerV2 {
}
}

def copyLearningpath: ServerEndpoint[Any, Eff] = endpoint.post
private def copyLearningpath: ServerEndpoint[Any, Eff] = endpoint.post
.summary("Copy given learningpath and store it as a new learningpath")
.description("Copies the given learningpath, with the option to override some fields")
.in(pathLearningpathId / "copy")
Expand All @@ -479,7 +479,7 @@ trait LearningpathControllerV2 {
}
}

def updateLearningPath: ServerEndpoint[Any, Eff] = endpoint.patch
def updateLearningPath(): ServerEndpoint[Any, Eff] = endpoint.patch
.summary("Update given learningpath")
.description("Updates the given learningPath")
.in(pathLearningpathId)
Expand All @@ -499,7 +499,7 @@ trait LearningpathControllerV2 {
}
}

def addLearningStep: ServerEndpoint[Any, Eff] = endpoint.post
private def addLearningStep(): ServerEndpoint[Any, Eff] = endpoint.post
.summary("Add new learningstep to learningpath")
.description("Adds the given LearningStep")
.in(pathLearningpathId / "learningsteps")
Expand All @@ -521,7 +521,7 @@ trait LearningpathControllerV2 {
}
}

def updateLearningStep: ServerEndpoint[Any, Eff] = endpoint.patch
def updateLearningStep(): ServerEndpoint[Any, Eff] = endpoint.patch
.summary("Update given learningstep")
.description("Update the given learningStep")
.in(pathLearningpathId / "learningsteps" / pathLearningstepId)
Expand All @@ -541,7 +541,7 @@ trait LearningpathControllerV2 {
}
}

def updatedLearningstepSeqNo: ServerEndpoint[Any, Eff] = endpoint.put
private def updatedLearningstepSeqNo: ServerEndpoint[Any, Eff] = endpoint.put
.summary("Store new sequence number for learningstep.")
.description(
"Updates the sequence number for the given learningstep. The sequence number of other learningsteps will be affected by this."
Expand All @@ -557,7 +557,7 @@ trait LearningpathControllerV2 {
}
}

def updateLearningStepStatus: ServerEndpoint[Any, Eff] = endpoint.put
private def updateLearningStepStatus(): ServerEndpoint[Any, Eff] = endpoint.put
.summary("Update status of given learningstep")
.description("Updates the status of the given learningstep")
.in(pathLearningpathId / "learningsteps" / pathLearningstepId / "status")
Expand All @@ -580,7 +580,7 @@ trait LearningpathControllerV2 {
}
}

def updateLearningPathStatus: ServerEndpoint[Any, Eff] = endpoint.put
private def updateLearningPathStatus(): ServerEndpoint[Any, Eff] = endpoint.put
.summary("Update status of given learningpath")
.description("Updates the status of the given learningPath")
.in(pathLearningpathId / "status")
Expand Down Expand Up @@ -609,7 +609,7 @@ trait LearningpathControllerV2 {
}
}

def withStatus: ServerEndpoint[Any, Eff] = endpoint.get
private def withStatus: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Fetch all learningpaths with specified status")
.description("Fetch all learningpaths with specified status")
.in("status" / learningPathStatus)
Expand All @@ -618,7 +618,7 @@ trait LearningpathControllerV2 {
.withOptionalMyNDLAUserOrTokenUser
.serverLogicPure { user => status => readService.learningPathWithStatus(status, user).handleErrorsOrOk }

def deleteLearningpath: ServerEndpoint[Any, Eff] = endpoint.delete
private def deleteLearningpath(): ServerEndpoint[Any, Eff] = endpoint.delete
.summary("Delete given learningpath")
.description("Deletes the given learningPath")
.in(pathLearningpathId)
Expand All @@ -639,7 +639,7 @@ trait LearningpathControllerV2 {
}
}

def deleteLearningStep: ServerEndpoint[Any, Eff] = endpoint.delete
private def deleteLearningStep(): ServerEndpoint[Any, Eff] = endpoint.delete
.summary("Delete given learningstep")
.description("Deletes the given learningStep")
.in(pathLearningpathId / "learningsteps" / pathLearningstepId)
Expand All @@ -657,7 +657,7 @@ trait LearningpathControllerV2 {
}
}

def getTags: ServerEndpoint[Any, Eff] = endpoint.get
private def getTags: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Fetch all previously used tags in learningpaths")
.description("Retrieves a list of all previously used tags in learningpaths")
.in("tags")
Expand All @@ -673,7 +673,7 @@ trait LearningpathControllerV2 {
}
}

def getContributors: ServerEndpoint[Any, Eff] = endpoint.get
private def getContributors: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Fetch all previously used contributors in learningpaths")
.description("Retrieves a list of all previously used contributors in learningpaths")
.in("contributors")
Expand All @@ -683,7 +683,7 @@ trait LearningpathControllerV2 {
readService.contributors.asRight
}

def updateLearningPathTaxonomy: ServerEndpoint[Any, Eff] = endpoint.post
private def updateLearningPathTaxonomy(): ServerEndpoint[Any, Eff] = endpoint.post
.summary("Update taxonomy for specified learningpath")
.description("Update taxonomy for specified learningpath")
.in(pathLearningpathId / "update-taxonomy")
Expand All @@ -707,7 +707,7 @@ trait LearningpathControllerV2 {
}
}

def fetchLearningPathContainingArticle: ServerEndpoint[Any, Eff] = endpoint.get
private def fetchLearningPathContainingArticle: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Fetch learningpaths containing specified article")
.description("Fetch learningpaths containing specified article")
.in("contains-article" / pathArticleId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait StatsController {
getStats
)

def getStats: ServerEndpoint[Any, Eff] = endpoint.get
private def getStats: ServerEndpoint[Any, Eff] = endpoint.get
.summary("Get stats for my-ndla usage.")
.description("Get stats for my-ndla usage.")
.deprecated()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import sttp.tapir.Schema.annotations.description
@description("Meta information for a new learningpath")
case class NewLearningPathV2DTO(
@description("The titles of the learningpath") title: String,
@description("The descriptions of the learningpath") description: String,
@description("The descriptions of the learningpath") description: Option[String],
@description("Url to cover-photo in NDLA image-api.") coverPhotoMetaUrl: Option[String],
@description("The duration of the learningpath in minutes. Must be greater than 0") duration: Option[Int],
@description("Searchable tags for the learningpath") tags: Seq[String],
@description("Searchable tags for the learningpath") tags: Option[Seq[String]],
@description("The chosen language") language: String,
@description("Describes the copyright information for the learningpath") copyright: CopyrightDTO
@description("Describes the copyright information for the learningpath") copyright: Option[CopyrightDTO]
)

object NewLearningPathV2DTO {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package no.ndla.learningpathapi.model.api

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

@description("Information about a new learningstep")
case class NewLearningStepV2DTO(
Expand All @@ -19,7 +19,9 @@ case class NewLearningStepV2DTO(
@description("The descriptions of the learningstep") description: Option[String],
@description("The chosen language") language: String,
@description("The embed content for the learningstep") embedUrl: Option[EmbedUrlV2DTO],
@description("Determines if the title of the step should be displayed in viewmode") showTitle: Boolean,
@description("Determines if the title of the step should be displayed in viewmode.") @default(
false
) showTitle: Boolean,
@description("The type of the step") `type`: String,
@description("Describes the copyright information for the learningstep") license: Option[String]
)
Expand Down
Loading

0 comments on commit e9028d0

Please sign in to comment.