Skip to content

Commit

Permalink
WIppers
Browse files Browse the repository at this point in the history
  • Loading branch information
jnatten committed Oct 24, 2024
1 parent 8467388 commit 53a9f88
Show file tree
Hide file tree
Showing 27 changed files with 168 additions and 167 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Part of NDLA common
* Copyright (C) 2024 NDLA
*
* See LICENSE
*/

package no.ndla.common.model.domain.myndla

import com.scalatsi.TypescriptType.{TSLiteralString, TSUnion}
import com.scalatsi.{TSNamedType, TSType}
import enumeratum.*

sealed trait ArenaGroup extends EnumEntry
object ArenaGroup extends Enum[ArenaGroup] with CirceEnum[ArenaGroup] {
case object ADMIN extends ArenaGroup
override def values: IndexedSeq[ArenaGroup] = findValues

implicit val enumTsType: TSNamedType[ArenaGroup] =
TSType.alias[ArenaGroup]("ArenaGroup", TSUnion(values.map(e => TSLiteralString(e.entryName))))
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

package no.ndla.common.model.domain.myndla

import com.scalatsi.TypescriptType.{TSLiteralString, TSUnion}
import com.scalatsi.{TSNamedType, TSType}
import enumeratum.*
import io.circe.{Decoder, Encoder}
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import no.ndla.common.model.NDLADate
Expand Down Expand Up @@ -57,15 +54,6 @@ object MyNDLAUserDocument {
implicit val decoder: Decoder[MyNDLAUserDocument] = deriveDecoder
}

sealed trait ArenaGroup extends EnumEntry
object ArenaGroup extends Enum[ArenaGroup] with CirceEnum[ArenaGroup] {
case object ADMIN extends ArenaGroup
override def values: IndexedSeq[ArenaGroup] = findValues

implicit val enumTsType: TSNamedType[ArenaGroup] =
TSType.alias[ArenaGroup]("ArenaGroup", TSUnion(values.map(e => TSLiteralString(e.entryName))))
}

case class MyNDLAUser(
id: Long,
feideId: String,
Expand All @@ -88,3 +76,8 @@ case class MyNDLAUser(
def isTeacher: Boolean = userRole == UserRole.EMPLOYEE
def isAdmin: Boolean = arenaGroups.contains(ArenaGroup.ADMIN)
}

object MyNDLAUser {
implicit val encoder: Encoder[MyNDLAUser] = deriveEncoder
implicit val decoder: Decoder[MyNDLAUser] = deriveDecoder
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

package no.ndla.myndlaapi

import no.ndla.myndlaapi.model.domain.{ArenaGroup, MyNDLAUser}
import no.ndla.common.model.domain.myndla.{ArenaGroup, MyNDLAUser}
import no.ndla.myndlaapi.service.UserService
import no.ndla.network.model.FeideAccessToken
import no.ndla.network.tapir.{AllErrors, TapirErrorHandling}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package no.ndla.myndlaapi.model.api

import io.circe.{Decoder, Encoder}
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import no.ndla.myndlaapi.model.domain.{ArenaGroup, MyNDLAUser}
import no.ndla.common.model.domain
import sttp.tapir.Schema.annotations.description

@description("Arena owner data")
Expand All @@ -19,12 +19,12 @@ case class ArenaUser(
@description("The name") displayName: String,
@description("The username") username: String,
@description("The location") location: String,
@description("Which groups the user belongs to") groups: List[ArenaGroup]
@description("Which groups the user belongs to") groups: List[domain.myndla.ArenaGroup]
)

object ArenaUser {

def from(user: MyNDLAUser): ArenaUser = {
def from(user: domain.myndla.MyNDLAUser): ArenaUser = {
val location = user.groups
.find(_.isPrimarySchool)
.map(_.displayName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package no.ndla.myndlaapi.model.api

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import no.ndla.myndlaapi.model.domain.ArenaGroup
import no.ndla.common.model.domain.myndla.ArenaGroup
import sttp.tapir.Schema.annotations.description

case class MyNDLAGroup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

package no.ndla.myndlaapi.model.arena.domain.database

import no.ndla.common.model.domain.myndla.MyNDLAUser
import no.ndla.myndlaapi.model.arena.domain
import no.ndla.myndlaapi.model.domain.MyNDLAUser

case class CompiledFlag(
flag: domain.Flag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@

package no.ndla.myndlaapi.model.domain

import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder}
import io.circe.{Decoder, Encoder}
import no.ndla.common.CirceUtil
import no.ndla.common.model.domain.myndla.{MyNDLAUser, MyNDLAUserDocument}
import scalikejdbc.*

object MyNDLAUser extends SQLSyntaxSupport[MyNDLAUser] {
implicit val encoder: Encoder[MyNDLAUser] = deriveEncoder
implicit val decoder: Decoder[MyNDLAUser] = deriveDecoder
object DBMyNDLAUser extends SQLSyntaxSupport[MyNDLAUser] {

override val tableName = "my_ndla_users"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package no.ndla.myndlaapi.model.domain

import cats.implicits.catsSyntaxOptionId
import no.ndla.common.model.NDLADate
import no.ndla.common.model.domain.myndla.FolderStatus
import no.ndla.common.model.domain.myndla.{FolderStatus, MyNDLAUser}
import no.ndla.network.model.FeideID
import scalikejdbc.*

Expand Down
Loading

0 comments on commit 53a9f88

Please sign in to comment.