Skip to content

Commit

Permalink
Merge pull request #567 from NDLANO/fix-isprivate
Browse files Browse the repository at this point in the history
Fix isprivate
  • Loading branch information
gunnarvelle authored Jan 2, 2025
2 parents f931cea + 88bad00 commit 0c48c7e
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ case class LearningPath(
) ++ stepLanguages).distinct
}

def isPrivate: Boolean = status == LearningPathStatus.PRIVATE
def isPrivate: Boolean = Seq(LearningPathStatus.PRIVATE, LearningPathStatus.READY_FOR_SHARING).contains(status)
def isPublished: Boolean = status == LearningPathStatus.PUBLISHED
def isDeleted: Boolean = status == LearningPathStatus.DELETED

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ import scala.util.{Failure, Success, Try}

trait LearningpathControllerV2 {

this: ReadService &
UpdateService with SearchService with LanguageValidator with ConverterService with TaxonomyApiClient with SearchConverterServiceComponent with Props with ErrorHandling with TapirController =>
this: ReadService & UpdateService & SearchService & LanguageValidator & ConverterService & TaxonomyApiClient &
SearchConverterServiceComponent & Props & ErrorHandling & TapirController =>
val learningpathControllerV2: LearningpathControllerV2

class LearningpathControllerV2 extends TapirController {

import ErrorHelpers._
import ErrorHelpers.*
import props.{
DefaultLanguage,
ElasticSearchIndexMaxResultWindow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import sttp.tapir.*
import sttp.tapir.server.ServerEndpoint

trait StatsController {
this: ReadService with Props with ErrorHandling with TapirController =>
this: ReadService & Props & ErrorHandling & TapirController =>
val statsController: StatsController

class StatsController extends TapirController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package no.ndla.learningpathapi.controller
import no.ndla.learningpathapi.Props
import no.ndla.network.tapir.auth.Permission
import no.ndla.network.tapir.{SwaggerControllerConfig, SwaggerInfo}
import sttp.tapir._
import sttp.tapir.*

trait SwaggerDocControllerConfig {
this: Props & SwaggerControllerConfig =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object OembedResponse {
}

trait OembedProxyClient {
this: NdlaClient with Props =>
this: NdlaClient & Props =>
val oembedProxyClient: OembedProxyClient

class OembedProxyClient extends StrictLogging {
Expand All @@ -48,7 +48,7 @@ trait OembedProxyClient {
}

private def getOembed(url: String): Try[OembedResponse] = {
get[OembedResponse](s"$OembedProxyBaseUrl/oembed", ("url" -> url))
get[OembedResponse](s"$OembedProxyBaseUrl/oembed", "url" -> url)
}

private def get[A: Decoder](url: String, params: (String, String)*): Try[A] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import sttp.client3.Response

import scala.annotation.unused
import scala.concurrent.duration.DurationInt
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.{ExecutionContext, ExecutionContextExecutor, Future}
import scala.util.{Failure, Success, Try}

trait SearchApiClient {
Expand All @@ -33,17 +33,17 @@ trait SearchApiClient {
@unused
private val SearchApiBaseUrl = s"http://$SearchApiHost"

def deleteLearningPathDocument(id: Long, user: Option[TokenUser]): Try[_] = {
def deleteLearningPathDocument(id: Long, user: Option[TokenUser]): Try[?] = {
val req = quickRequest
.delete(uri"http://$SearchApiHost/intern/learningpath/$id")
.readTimeout(IndexTimeout)

doRawRequest(req, user)
}

def indexLearningPathDocument(document: LearningPath, user: Option[TokenUser]): Future[Try[_]] = {
val idString = document.id.map(_.toString).getOrElse("<missing id>")
implicit val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(1))
def indexLearningPathDocument(document: LearningPath, user: Option[TokenUser]): Future[Try[?]] = {
val idString = document.id.map(_.toString).getOrElse("<missing id>")
implicit val ec: ExecutionContextExecutor = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(1))
val future = Future {
val body = CirceUtil.toJsonString(document)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import scala.concurrent.duration.DurationInt
import scala.util.{Failure, Success, Try}

trait TaxonomyApiClient {
this: NdlaClient with Props =>
this: NdlaClient & Props =>
val taxonomyApiClient: TaxonomyApiClient

class TaxonomyApiClient extends StrictLogging {
Expand Down Expand Up @@ -251,7 +251,7 @@ trait TaxonomyApiClient {

private def get[A: Decoder](url: String, user: Option[TokenUser], params: (String, String)*): Try[A] = {
val request = quickRequest
.get(uri"$url".withParams(params: _*))
.get(uri"$url".withParams(params*))
.readTimeout(taxonomyTimeout)
.header(TAXONOMY_VERSION_HEADER, defaultVersion)
ndlaClient.fetchWithForwardedAuth[A](request, user)
Expand All @@ -264,7 +264,7 @@ trait TaxonomyApiClient {
params: (String, String)*
): Try[A] = {
val request = quickRequest
.put(uri"$url".withParams(params: _*))
.put(uri"$url".withParams(params*))
.readTimeout(taxonomyTimeout)
.body(CirceUtil.toJsonString(data))
.header("content-type", "application/json", replaceExisting = true)
Expand All @@ -279,7 +279,7 @@ trait TaxonomyApiClient {
): Try[B] = {
logger.info(s"Doing call to $url")
val request = quickRequest
.put(uri"$url".withParams(params: _*))
.put(uri"$url".withParams(params*))
.body(CirceUtil.toJsonString(data))
.readTimeout(taxonomyTimeout)
.header("content-type", "application/json", replaceExisting = true)
Expand Down Expand Up @@ -311,7 +311,7 @@ trait TaxonomyApiClient {
private[integration] def delete(url: String, user: Option[TokenUser], params: (String, String)*): Try[Unit] =
ndlaClient.fetchRawWithForwardedAuth(
quickRequest
.delete(uri"$url".withParams(params: _*))
.delete(uri"$url".withParams(params*))
.readTimeout(taxonomyTimeout),
user
) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object Sort extends Enum[Sort] with CirceEnum[Sort] {
private val tsEnumValues: Seq[(String, String)] = values.map(e => e.toString -> e.entryName)
implicit val enumTsType: TSNamedType[Sort] = TSType.alias[Sort](
"Sort",
TSEnum.string("LearningpathSortEnum", tsEnumValues: _*)
TSEnum.string("LearningpathSortEnum", tsEnumValues*)
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class DurationValidator {
durationOpt match {
case None => Some(ValidationMessage("duration", DURATION_REQUIRED))
case Some(duration) =>
duration < 1 match {
case true => Some(ValidationMessage("duration", DURATION_INVALID))
case false => None
if (duration < 1) {
Some(ValidationMessage("duration", DURATION_INVALID))
} else {
None
}
}
}
Expand Down

0 comments on commit 0c48c7e

Please sign in to comment.