Skip to content

Commit

Permalink
lalalal
Browse files Browse the repository at this point in the history
  • Loading branch information
jnatten committed Dec 5, 2023
1 parent 2eef796 commit d6a7f2c
Show file tree
Hide file tree
Showing 27 changed files with 455 additions and 341 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import no.ndla.learningpathapi.controller.{
import no.ndla.learningpathapi.integration._
import no.ndla.learningpathapi.model.api.ErrorHelpers
import no.ndla.learningpathapi.model.domain.{DBLearningPath, DBLearningStep}
import no.ndla.learningpathapi.model.domain.config.DBConfigMeta
import no.ndla.learningpathapi.repository.{ConfigRepository, LearningPathRepositoryComponent}
import no.ndla.learningpathapi.repository.LearningPathRepositoryComponent
import no.ndla.learningpathapi.service._
import no.ndla.learningpathapi.service.search.{SearchConverterServiceComponent, SearchIndexService, SearchService}
import no.ndla.learningpathapi.validation.{
Expand All @@ -36,8 +35,16 @@ import no.ndla.learningpathapi.validation.{
TitleValidator,
UrlValidator
}
import no.ndla.myndla.model.domain.config.DBConfigMeta
import no.ndla.myndla.model.domain.{DBFolder, DBFolderResource, DBMyNDLAUser, DBResource}
import no.ndla.myndla.repository.{FolderRepository, UserRepository}
import no.ndla.myndla.repository.{ConfigRepository, FolderRepository, UserRepository}
import no.ndla.myndla.service.{
ConfigService,
FolderConverterService,
FolderReadService,
FolderWriteService,
UserService
}
import no.ndla.network.NdlaClient
import no.ndla.network.clients.{FeideApiClient, RedisClient}
import no.ndla.network.scalatra.{NdlaControllerBase, NdlaSwaggerSupport}
Expand All @@ -59,6 +66,11 @@ class ComponentRegistry(properties: LearningpathApiProperties)
with FolderRepository
with UserRepository
with ReadService
with ConfigService
with UserService
with FolderConverterService
with FolderReadService
with FolderWriteService
with UpdateService
with SearchConverterServiceComponent
with SearchService
Expand Down Expand Up @@ -100,35 +112,40 @@ class ComponentRegistry(properties: LearningpathApiProperties)

implicit val swagger: LearningpathSwagger = new LearningpathSwagger

lazy val learningPathRepository = new LearningPathRepository
lazy val configRepository = new ConfigRepository
lazy val folderRepository = new FolderRepository
lazy val userRepository = new UserRepository
lazy val readService = new ReadService
lazy val updateService = new UpdateService
lazy val searchConverterService = new SearchConverterService
lazy val searchService = new SearchService
lazy val searchIndexService = new SearchIndexService
lazy val converterService = new ConverterService
lazy val clock = new SystemClock
lazy val learningpathControllerV2 = new LearningpathControllerV2
lazy val internController = new InternController
lazy val configController = new ConfigController
lazy val folderController = new FolderController
lazy val statsController = new StatsController
lazy val userController = new UserController
lazy val resourcesApp = new ResourcesApp
lazy val taxonomyApiClient = new TaxonomyApiClient
lazy val ndlaClient = new NdlaClient
lazy val imageApiClient = new ImageApiClient
lazy val feideApiClient = new FeideApiClient
lazy val healthController = new HealthController
lazy val languageValidator = new LanguageValidator
lazy val titleValidator = new TitleValidator
lazy val learningPathValidator = new LearningPathValidator
lazy val learningStepValidator = new LearningStepValidator
var e4sClient: NdlaE4sClient = Elastic4sClientFactory.getClient(props.SearchServer)
lazy val searchApiClient = new SearchApiClient
lazy val oembedProxyClient = new OembedProxyClient
lazy val redisClient = new RedisClient(props.RedisHost, props.RedisPort)
lazy val learningPathRepository = new LearningPathRepository
lazy val configRepository = new ConfigRepository
lazy val folderRepository = new FolderRepository
lazy val userRepository = new UserRepository
lazy val readService = new ReadService
lazy val updateService = new UpdateService
lazy val searchConverterService = new SearchConverterService
lazy val searchService = new SearchService
lazy val searchIndexService = new SearchIndexService
lazy val converterService = new ConverterService
lazy val clock = new SystemClock
lazy val learningpathControllerV2 = new LearningpathControllerV2
lazy val internController = new InternController
lazy val configController = new ConfigController
lazy val folderController = new FolderController
lazy val statsController = new StatsController
lazy val userController = new UserController
lazy val resourcesApp = new ResourcesApp
lazy val taxonomyApiClient = new TaxonomyApiClient
lazy val ndlaClient = new NdlaClient
lazy val imageApiClient = new ImageApiClient
lazy val feideApiClient = new FeideApiClient
lazy val healthController = new HealthController
lazy val languageValidator = new LanguageValidator
lazy val titleValidator = new TitleValidator
lazy val learningPathValidator = new LearningPathValidator
lazy val learningStepValidator = new LearningStepValidator
var e4sClient: NdlaE4sClient = Elastic4sClientFactory.getClient(props.SearchServer)
lazy val searchApiClient = new SearchApiClient
lazy val oembedProxyClient = new OembedProxyClient
lazy val redisClient = new RedisClient(props.RedisHost, props.RedisPort)
lazy val configService: ConfigService = new ConfigService
lazy val userService: UserService = new UserService
lazy val folderConverterService: FolderConverterService = new FolderConverterService
lazy val folderReadService: FolderReadService = new FolderReadService
lazy val folderWriteService: FolderWriteService = new FolderWriteService
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ package no.ndla.learningpathapi.controller

import no.ndla.common.model.NDLADate
import no.ndla.learningpathapi.Props
import no.ndla.learningpathapi.model.api.config.{ConfigMeta, ConfigMetaRestricted, ConfigMetaValue}
import no.ndla.learningpathapi.model.api.{Error, ValidationError}
import no.ndla.learningpathapi.model.domain.config.ConfigKey
import no.ndla.learningpathapi.service.{ReadService, UpdateService}
import no.ndla.myndla.model.api.config.{ConfigMeta, ConfigMetaRestricted, ConfigMetaValue}
import no.ndla.myndla.model.domain.config.ConfigKey
import no.ndla.myndla.service.ConfigService
import no.ndla.network.scalatra.NdlaSwaggerSupport
import org.json4s.ext.JavaTimeSerializers
import org.json4s.{DefaultFormats, Formats}
Expand All @@ -24,7 +25,7 @@ import scala.util.{Failure, Success}

trait ConfigController {

this: ReadService with UpdateService with NdlaController with Props with NdlaSwaggerSupport =>
this: ReadService with UpdateService with NdlaController with Props with NdlaSwaggerSupport with ConfigService =>
val configController: ConfigController

class ConfigController(implicit val swagger: Swagger) extends NdlaController with NdlaSwaggerSupport {
Expand Down Expand Up @@ -76,7 +77,7 @@ trait ConfigController {
.authorizations("oauth2")
)
) {
withConfigKey(readService.getConfig)
withConfigKey(configService.getConfig)
}: Unit

post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ package no.ndla.learningpathapi.controller

import no.ndla.common.model.NDLADate
import no.ndla.learningpathapi.model.api.{Error, ValidationError}
import no.ndla.common.model.domain.myndla.FolderSortObject.{FolderSorting, ResourceSorting, RootFolderSorting}
import no.ndla.learningpathapi.service.{ConverterService, ReadService, UpdateService}
import no.ndla.myndla.model.api.{
Folder,
FolderSortRequest,
NewFolder,
NewResource,
Resource,
UpdatedFolder,
UpdatedResource
}
import no.ndla.myndla.model.domain.FolderSortObject.{FolderSorting, ResourceSorting, RootFolderSorting}
import no.ndla.myndla.service.{FolderReadService, FolderWriteService}
import no.ndla.network.scalatra.NdlaSwaggerSupport
import org.json4s.ext.{JavaTimeSerializers, JavaTypesSerializers}
import org.json4s.{DefaultFormats, Formats}
Expand All @@ -23,7 +33,13 @@ import javax.servlet.http.HttpServletRequest
import scala.util.{Failure, Success}

trait FolderController {
this: ReadService with UpdateService with ConverterService with NdlaController with NdlaSwaggerSupport =>
this: ReadService
with UpdateService
with ConverterService
with NdlaController
with NdlaSwaggerSupport
with FolderReadService
with FolderWriteService =>
val folderController: FolderController

class FolderController(implicit val swagger: Swagger) extends NdlaController with NdlaSwaggerSupport {
Expand Down Expand Up @@ -82,7 +98,7 @@ trait FolderController {
) {
val includeSubfolders = booleanOrDefault(this.includeSubfolders.paramName, default = false)
val includeResources = booleanOrDefault(this.includeResources.paramName, default = false)
readService.getFolders(includeSubfolders, includeResources, requestFeideToken) match {
folderReadService.getFolders(includeSubfolders, includeResources, requestFeideToken) match {
case Failure(ex) => errorHandler(ex)
case Success(folders) => folders
}
Expand All @@ -107,7 +123,7 @@ trait FolderController {
uuidParam(this.folderId.paramName).flatMap(id => {
val includeResources = booleanOrDefault(this.includeResources.paramName, default = false)
val includeSubfolders = booleanOrDefault(this.includeSubfolders.paramName, default = false)
readService.getSingleFolder(id, includeSubfolders, includeResources, requestFeideToken)
folderReadService.getSingleFolder(id, includeSubfolders, includeResources, requestFeideToken)
})
}: Unit

Expand All @@ -126,7 +142,7 @@ trait FolderController {
)
) {
val newFolder = extract[NewFolder](request.body)
updateService.newFolder(newFolder, requestFeideToken) match {
folderWriteService.newFolder(newFolder, requestFeideToken) match {
case Failure(ex) => errorHandler(ex)
case Success(folder) => folder
}
Expand All @@ -149,7 +165,7 @@ trait FolderController {
) {
uuidParam(this.folderId.paramName).flatMap(id => {
val updatedFolder = extract[UpdatedFolder](request.body)
updateService.updateFolder(id, updatedFolder, requestFeideToken)
folderWriteService.updateFolder(id, updatedFolder, requestFeideToken)
})
}: Unit

Expand All @@ -169,7 +185,7 @@ trait FolderController {
) {
uuidParam(this.folderId.paramName)
.flatMap(id => {
updateService.deleteFolder(id, requestFeideToken)
folderWriteService.deleteFolder(id, requestFeideToken)
})
.map(_ => NoContent())
}: Unit
Expand All @@ -193,7 +209,7 @@ trait FolderController {
case tooSmall if tooSmall < 1 => defaultSize
case x => x
}
readService.getAllResources(size, requestFeideToken) match {
folderReadService.getAllResources(size, requestFeideToken) match {
case Failure(ex) => errorHandler(ex)
case Success(folders) => folders
}
Expand All @@ -216,7 +232,7 @@ trait FolderController {
) {
uuidParam(this.folderId.paramName).flatMap(id => {
val newResource = extract[NewResource](request.body)
updateService.newFolderResourceConnection(id, newResource, requestFeideToken)
folderWriteService.newFolderResourceConnection(id, newResource, requestFeideToken)
})
}: Unit

Expand All @@ -237,7 +253,7 @@ trait FolderController {
) {
uuidParam(this.resourceId.paramName).flatMap(id => {
val updatedResource = extract[UpdatedResource](request.body)
updateService.updateResource(id, updatedResource, requestFeideToken)
folderWriteService.updateResource(id, updatedResource, requestFeideToken)
})
}: Unit

Expand All @@ -259,7 +275,7 @@ trait FolderController {
uuidParam(this.folderId.paramName)
.flatMap(folderId => {
uuidParam(this.resourceId.paramName).flatMap(resourceId => {
updateService.deleteConnection(folderId, resourceId, requestFeideToken)
folderWriteService.deleteConnection(folderId, resourceId, requestFeideToken)
})
})
.map(_ => NoContent())
Expand All @@ -278,7 +294,7 @@ trait FolderController {
.authorizations("oauth2")
)
) {
uuidParam(this.folderId.paramName).flatMap(id => readService.getSharedFolder(id))
uuidParam(this.folderId.paramName).flatMap(id => folderReadService.getSharedFolder(id))
}: Unit

patch(
Expand All @@ -299,7 +315,7 @@ trait FolderController {
for {
folderId <- uuidParam(this.folderId.paramName)
status <- folderStatusParam(this.folderStatus.paramName)
updatedIds <- updateService.changeStatusOfFolderAndItsSubfolders(folderId, status, requestFeideToken)
updatedIds <- folderWriteService.changeStatusOfFolderAndItsSubfolders(folderId, status, requestFeideToken)
} yield updatedIds
}: Unit

Expand All @@ -321,7 +337,7 @@ trait FolderController {
for {
source <- uuidParam(this.sourceId.paramName)
destination <- uuidParamOrNone(this.destinationId.paramName)
cloned <- updateService.cloneFolder(source, destination, requestFeideToken)
cloned <- folderWriteService.cloneFolder(source, destination, requestFeideToken)
} yield cloned
}: Unit

Expand All @@ -341,7 +357,7 @@ trait FolderController {
folderId <- uuidParam(this.folderId.paramName)
sortRequest <- tryExtract[FolderSortRequest](request.body)
sortObject = ResourceSorting(folderId)
sorted <- updateService.sortFolder(sortObject, sortRequest, requestFeideToken)
sorted <- folderWriteService.sortFolder(sortObject, sortRequest, requestFeideToken)
} yield sorted
}: Unit

Expand All @@ -362,7 +378,7 @@ trait FolderController {
folderId <- uuidParamOrNone(this.folderIdQuery.paramName)
sortRequest <- tryExtract[FolderSortRequest](request.body)
sortObject = folderId.map(id => FolderSorting(id)).getOrElse(RootFolderSorting())
sorted <- updateService.sortFolder(sortObject, sortRequest, requestFeideToken)
sorted <- folderWriteService.sortFolder(sortObject, sortRequest, requestFeideToken)
} yield sorted
}: Unit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import no.ndla.learningpathapi.integration.DataSource
import no.ndla.learningpathapi.model.api.{Error, ErrorHelpers, ValidationError}
import no.ndla.learningpathapi.model.domain._
import no.ndla.learningpathapi.service.ConverterService
import no.ndla.myndla.model.api.ImportReport
import no.ndla.myndla.model.domain.{FolderStatus, InvalidStatusException}
import no.ndla.myndla.service.FolderConverterService
import no.ndla.network.model.HttpRequestException
import no.ndla.network.scalatra.NdlaSwaggerSupport
import no.ndla.search.{IndexNotFoundException, NdlaSearchException}
Expand All @@ -26,7 +29,7 @@ import javax.servlet.http.HttpServletRequest
import scala.util.{Failure, Success, Try}

trait NdlaController {
this: DataSource with ErrorHelpers with ConverterService with NdlaSwaggerSupport =>
this: DataSource with ErrorHelpers with ConverterService with FolderConverterService with NdlaSwaggerSupport =>

abstract class NdlaController extends NdlaSwaggerSupport {
protected implicit override val jsonFormats: Formats = DefaultFormats
Expand Down Expand Up @@ -88,12 +91,12 @@ trait NdlaController {

def uuidParam(paramName: String)(implicit request: HttpServletRequest): Try[UUID] = {
val maybeParam = paramOrNone(paramName)(request)
converterService.toUUIDValidated(maybeParam, paramName)
folderConverterService.toUUIDValidated(maybeParam, paramName)
}

def uuidParamOrNone(paramName: String)(implicit request: HttpServletRequest): Try[Option[UUID]] = {
paramOrNone(paramName)(request) match {
case Some(param) => converterService.toUUIDValidated(Some(param), paramName).map(_.some)
case Some(param) => folderConverterService.toUUIDValidated(Some(param), paramName).map(_.some)
case None => Success(None)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ package no.ndla.learningpathapi.controller
import no.ndla.learningpathapi.Props
import no.ndla.learningpathapi.model.api.Error
import no.ndla.learningpathapi.service.ReadService
import no.ndla.myndla.model.api.Stats
import no.ndla.myndla.service.FolderReadService
import no.ndla.network.scalatra.NdlaSwaggerSupport
import org.json4s.{DefaultFormats, Formats}
import org.scalatra.swagger.{ResponseMessage, Swagger}
import org.scalatra.{NotFound, Ok}

trait StatsController {
this: ReadService with NdlaController with Props with NdlaSwaggerSupport =>
this: ReadService with NdlaController with Props with NdlaSwaggerSupport with FolderReadService =>
val statsController: StatsController

class StatsController(implicit val swagger: Swagger) extends NdlaController with NdlaSwaggerSupport {
Expand All @@ -40,7 +42,7 @@ trait StatsController {
.responseMessages(response404, response500, response502)
)
) {
readService.getStats match {
folderReadService.getStats match {
case Some(c) => Ok(c)
case None => NotFound("No stats found")
}
Expand Down
Loading

0 comments on commit d6a7f2c

Please sign in to comment.