Skip to content

Commit

Permalink
database: Share DataSource code
Browse files Browse the repository at this point in the history
  • Loading branch information
jnatten committed Nov 4, 2024
1 parent e6ccbad commit fb7980a
Show file tree
Hide file tree
Showing 60 changed files with 124 additions and 414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,24 @@ package no.ndla.articleapi

import no.ndla.common.Environment.prop
import no.ndla.common.configuration.{BaseProps, HasBaseProps}
import no.ndla.common.secrets.PropertyKeys
import no.ndla.database.{DatabaseProps, HasDatabaseProps}
import no.ndla.network.{AuthUser, Domains}
import no.ndla.validation.ResourceType

import scala.util.Properties.*

trait Props extends HasBaseProps {
trait Props extends HasBaseProps with HasDatabaseProps {
val props: ArticleApiProperties
}

class ArticleApiProperties extends BaseProps {
class ArticleApiProperties extends BaseProps with DatabaseProps {

def ApplicationName = "article-api"
def Auth0LoginEndpoint: String = s"https://${AuthUser.getAuth0HostForEnv(Environment)}/authorize"

def ApplicationPort: Int = propOrElse("APPLICATION_PORT", "80").toInt
def DefaultLanguage: String = propOrElse("DEFAULT_LANGUAGE", "nb")

def MetaUserName: String = prop(PropertyKeys.MetaUserNameKey)
def MetaPassword: String = prop(PropertyKeys.MetaPasswordKey)
def MetaResource: String = prop(PropertyKeys.MetaResourceKey)
def MetaServer: String = prop(PropertyKeys.MetaServerKey)
def MetaPort: Int = prop(PropertyKeys.MetaPortKey).toInt
def MetaSchema: String = prop(PropertyKeys.MetaSchemaKey)
def MetaMaxConnections: Int = propOrElse(PropertyKeys.MetaMaxConnections, "10").toInt

def SearchServer: String = propOrElse("SEARCH_SERVER", "http://search-article-api.ndla-local")
def ArticleSearchIndex: String = propOrElse("SEARCH_INDEX_NAME", "articles")
def ArticleSearchDocument = "article"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import no.ndla.articleapi.model.api.ErrorHandling
import no.ndla.articleapi.model.domain.DBArticle
import no.ndla.common.Clock
import no.ndla.common.configuration.BaseComponentRegistry
import no.ndla.database.DataSource
import no.ndla.network.NdlaClient
import no.ndla.network.tapir.TapirApplication
import no.ndla.network.clients.{FeideApiClient, RedisClient}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package no.ndla.articleapi

import no.ndla.articleapi.db.migrationwithdependencies.*
import no.ndla.articleapi.integration.DataSource
import no.ndla.database.DataSource
import org.flywaydb.core.Flyway

trait DBMigrator {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ package no.ndla.articleapi.model.api
import cats.implicits.catsSyntaxOptionId
import com.typesafe.scalalogging.StrictLogging
import no.ndla.articleapi.Props
import no.ndla.articleapi.integration.DataSource
import no.ndla.common.Clock
import no.ndla.common.errors.{AccessDeniedException, ValidationException}
import no.ndla.database.DataSource
import no.ndla.network.tapir.{
AllErrors,
ErrorBody,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
package no.ndla.articleapi.repository

import com.typesafe.scalalogging.StrictLogging
import no.ndla.articleapi.integration.DataSource
import no.ndla.articleapi.model.api.NotFoundException
import no.ndla.articleapi.model.domain.{ArticleIds, ArticleRow, DBArticle}
import no.ndla.common.CirceUtil
import no.ndla.common.model.domain.article.Article
import no.ndla.database.DataSource
import org.postgresql.util.PGobject
import scalikejdbc.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import no.ndla.articleapi.integration.SearchApiClient
import no.ndla.articleapi.model.api.ErrorHandling
import no.ndla.articleapi.model.domain.DBArticle
import no.ndla.common.Clock
import no.ndla.database.DataSource
import no.ndla.network.NdlaClient
import no.ndla.network.clients.{FeideApiClient, RedisClient}
import no.ndla.network.tapir.TapirApplication
Expand Down
15 changes: 3 additions & 12 deletions audio-api/src/main/scala/no/ndla/audioapi/AudioApiProperties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
package no.ndla.audioapi

import com.typesafe.scalalogging.StrictLogging
import no.ndla.common.Environment.prop
import no.ndla.common.configuration.{BaseProps, HasBaseProps}
import no.ndla.common.secrets.PropertyKeys
import no.ndla.database.{DatabaseProps, HasDatabaseProps}
import no.ndla.network.{AuthUser, Domains}

import scala.util.Properties.*

trait Props extends HasBaseProps {
trait Props extends HasBaseProps with HasDatabaseProps {
val props: AudioApiProperties
}

class AudioApiProperties extends BaseProps with StrictLogging {
class AudioApiProperties extends BaseProps with DatabaseProps with StrictLogging {
val IsKubernetes: Boolean = propOrNone("NDLA_IS_KUBERNETES").isDefined

def ApplicationName = "audio-api"
Expand All @@ -32,14 +31,6 @@ class AudioApiProperties extends BaseProps with StrictLogging {
val AudioControllerPath = "/audio-api/v1/audio/"
val SeriesControllerPath = "/audio-api/v1/series/"

def MetaUserName: String = prop(PropertyKeys.MetaUserNameKey)
def MetaPassword: String = prop(PropertyKeys.MetaPasswordKey)
def MetaResource: String = prop(PropertyKeys.MetaResourceKey)
def MetaServer: String = prop(PropertyKeys.MetaServerKey)
def MetaPort: Int = prop(PropertyKeys.MetaPortKey).toInt
def MetaSchema: String = prop(PropertyKeys.MetaSchemaKey)
def MetaMaxConnections: Int = propOrElse(PropertyKeys.MetaMaxConnections, "10").toInt

val MaxAudioFileSizeBytes: Int = 1024 * 1024 * 100 // 100 MiB

val StorageName: String = propOrElse("AUDIO_FILE_S3_BUCKET", s"$Environment.audio.ndla")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ package no.ndla.audioapi

import com.zaxxer.hikari.HikariDataSource
import no.ndla.audioapi.controller.*
import no.ndla.audioapi.integration.*
import no.ndla.audioapi.model.api.ErrorHandling
import no.ndla.audioapi.repository.{AudioRepository, SeriesRepository}
import no.ndla.audioapi.service.*
import no.ndla.audioapi.service.search.*
import no.ndla.common.Clock
import no.ndla.common.aws.NdlaS3Client
import no.ndla.common.configuration.BaseComponentRegistry
import no.ndla.database.DataSource
import no.ndla.network.NdlaClient
import no.ndla.network.tapir.TapirApplication
import no.ndla.search.{BaseIndexService, Elastic4sClient}
Expand Down
2 changes: 1 addition & 1 deletion audio-api/src/main/scala/no/ndla/audioapi/DBMigrator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package no.ndla.audioapi

import no.ndla.audioapi.db.migrationwithdependencies.{V5__AddAgreementToAudio, V6__TranslateUntranslatedAuthors}
import no.ndla.audioapi.integration.DataSource
import no.ndla.database.DataSource
import org.flywaydb.core.Flyway
import org.flywaydb.core.api.output.MigrateResult

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
package no.ndla.audioapi.model.api

import no.ndla.audioapi.Props
import no.ndla.audioapi.integration.DataSource
import no.ndla.common.Clock
import no.ndla.common.errors.{AccessDeniedException, FileTooBigException, ValidationException}
import no.ndla.database.DataSource
import no.ndla.network.model.HttpRequestException
import no.ndla.network.tapir.{AllErrors, ErrorBody, TapirErrorHandling, ValidationErrorBody}
import no.ndla.search.NdlaSearchException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ package no.ndla.audioapi.repository

import com.typesafe.scalalogging.StrictLogging
import no.ndla.audioapi.Props
import no.ndla.audioapi.integration.DataSource
import no.ndla.audioapi.model.api.ErrorHandling
import no.ndla.audioapi.model.domain.{AudioMetaInformation, Series}
import no.ndla.common.CirceUtil
import no.ndla.database.DataSource
import org.postgresql.util.PGobject
import scalikejdbc.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package no.ndla.audioapi.repository

import com.typesafe.scalalogging.StrictLogging
import no.ndla.audioapi.integration.DataSource
import no.ndla.audioapi.model.domain.{AudioMetaInformation, Series}
import no.ndla.audioapi.model.domain
import org.postgresql.util.PGobject
Expand All @@ -19,6 +18,7 @@ import no.ndla.audioapi.Props
import no.ndla.audioapi.model.api.ErrorHandling
import no.ndla.common.CirceUtil
import no.ndla.common.model.NDLADate
import no.ndla.database.DataSource

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ package no.ndla.audioapi

import com.zaxxer.hikari.HikariDataSource
import no.ndla.audioapi.controller.{AudioController, HealthController, InternController, SeriesController}
import no.ndla.audioapi.integration.*
import no.ndla.audioapi.model.api.ErrorHandling
import no.ndla.audioapi.repository.{AudioRepository, SeriesRepository}
import no.ndla.audioapi.service.*
import no.ndla.audioapi.service.search.*
import no.ndla.common.Clock
import no.ndla.common.aws.NdlaS3Client
import no.ndla.database.DataSource
import no.ndla.network.NdlaClient
import no.ndla.network.tapir.TapirApplication
import no.ndla.search.{BaseIndexService, Elastic4sClient}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package no.ndla.conceptapi
import com.typesafe.scalalogging.StrictLogging
import com.zaxxer.hikari.HikariDataSource
import no.ndla.conceptapi.controller.*
import no.ndla.conceptapi.integration.{ArticleApiClient, DataSource, SearchApiClient, TaxonomyApiClient}
import no.ndla.conceptapi.integration.{ArticleApiClient, SearchApiClient, TaxonomyApiClient}
import no.ndla.conceptapi.model.api.ErrorHandling
import no.ndla.conceptapi.model.search.{DraftSearchSettingsHelper, SearchSettingsHelper}
import no.ndla.conceptapi.repository.{DraftConceptRepository, PublishedConceptRepository}
Expand All @@ -21,6 +21,7 @@ import no.ndla.network.NdlaClient
import no.ndla.search.{BaseIndexService, Elastic4sClient}
import no.ndla.common.Clock
import no.ndla.common.configuration.BaseComponentRegistry
import no.ndla.database.DataSource
import no.ndla.network.tapir.TapirApplication

class ComponentRegistry(properties: ConceptApiProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,28 @@
package no.ndla.conceptapi

import com.typesafe.scalalogging.StrictLogging
import no.ndla.common.Environment.prop
import no.ndla.common.configuration.{BaseProps, HasBaseProps}
import no.ndla.common.secrets.PropertyKeys
import no.ndla.database.{DatabaseProps, HasDatabaseProps}
import no.ndla.network.{AuthUser, Domains}
import no.ndla.validation.ResourceType

import scala.util.Properties.*

trait Props extends HasBaseProps {
trait Props extends HasBaseProps with HasDatabaseProps {
val props: ConceptApiProperties
}

class ConceptApiProperties extends BaseProps with StrictLogging {
class ConceptApiProperties extends BaseProps with DatabaseProps with StrictLogging {
def IsKubernetes: Boolean = propOrNone("NDLA_IS_KUBERNETES").isDefined

def ApplicationName = "concept-api"

def Auth0LoginEndpoint: String =
s"https://${AuthUser.getAuth0HostForEnv(Environment)}/authorize"
def ConceptRoleWithWriteAccess = "concept:write"

def ApplicationPort: Int = propOrElse("APPLICATION_PORT", "80").toInt
def DefaultLanguage: String = propOrElse("DEFAULT_LANGUAGE", "nb")

def MetaUserName: String = prop(PropertyKeys.MetaUserNameKey)
def MetaPassword: String = prop(PropertyKeys.MetaPasswordKey)
def MetaResource: String = prop(PropertyKeys.MetaResourceKey)
def MetaServer: String = prop(PropertyKeys.MetaServerKey)
def MetaPort: Int = prop(PropertyKeys.MetaPortKey).toInt
def MetaSchema: String = prop(PropertyKeys.MetaSchemaKey)
def MetaMaxConnections: Int = propOrElse(PropertyKeys.MetaMaxConnections, "10").toInt

def SearchServer: String = propOrElse("SEARCH_SERVER", "http://search-concept-api.ndla-local")
def DraftConceptSearchIndex: String = propOrElse("CONCEPT_SEARCH_INDEX_NAME", "concepts")
def PublishedConceptSearchIndex: String = propOrElse("PUBLISHED_CONCEPT_SEARCH_INDEX_NAME", "publishedconcepts")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package no.ndla.conceptapi

import no.ndla.conceptapi.integration.DataSource
import no.ndla.database.DataSource
import org.flywaydb.core.Flyway
import org.flywaydb.core.api.output.MigrateResult

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package no.ndla.conceptapi.model.api
import no.ndla.common.Clock
import no.ndla.common.errors.{AccessDeniedException, ValidationException}
import no.ndla.conceptapi.Props
import no.ndla.conceptapi.integration.DataSource
import no.ndla.database.DataSource
import no.ndla.network.model.HttpRequestException
import no.ndla.network.tapir.{AllErrors, TapirErrorHandling}
import no.ndla.search.{IndexNotFoundException, NdlaSearchException}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import no.ndla.common.CirceUtil
import no.ndla.common.model.domain.Tag
import no.ndla.common.model.domain.concept.Concept
import no.ndla.conceptapi.Props
import no.ndla.conceptapi.integration.DataSource
import no.ndla.conceptapi.model.api.{ConceptMissingIdException, ErrorHandling, NotFoundException}
import no.ndla.conceptapi.model.domain.DBConcept
import no.ndla.database.DataSource
import org.postgresql.util.PGobject
import scalikejdbc.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import com.typesafe.scalalogging.StrictLogging
import no.ndla.common.CirceUtil
import no.ndla.common.model.domain.Tag
import no.ndla.common.model.domain.concept.Concept
import no.ndla.conceptapi.integration.DataSource
import no.ndla.conceptapi.model.api.NotFoundException
import no.ndla.conceptapi.model.domain.{DBConcept, PublishedConcept}
import no.ndla.database.DataSource
import org.postgresql.util.PGobject
import scalikejdbc.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import no.ndla.conceptapi.controller.{
InternController,
PublishedConceptController
}
import no.ndla.conceptapi.integration.{ArticleApiClient, DataSource, SearchApiClient, TaxonomyApiClient}
import no.ndla.conceptapi.integration.{ArticleApiClient, SearchApiClient, TaxonomyApiClient}
import no.ndla.conceptapi.model.api.ErrorHandling
import no.ndla.conceptapi.model.search.{DraftSearchSettingsHelper, SearchSettingsHelper}
import no.ndla.conceptapi.repository.{DraftConceptRepository, PublishedConceptRepository}
import no.ndla.conceptapi.service.*
import no.ndla.conceptapi.service.search.*
import no.ndla.conceptapi.validation.ContentValidator
import no.ndla.database.DataSource
import no.ndla.network.NdlaClient
import no.ndla.network.tapir.TapirApplication
import no.ndla.search.{BaseIndexService, Elastic4sClient}
Expand Down
Loading

0 comments on commit fb7980a

Please sign in to comment.