Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.5.9
fe05258d37df5c81047c86083354a1d5ae225ae3
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.5.2
version = 3.5.9
runner.dialect = scala213
align.preset = more
maxColumn = 120
24 changes: 12 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ lazy val authentication = (project in file("modules/auth"))
lazy val projects = (project in file("modules/projects"))
.disablePlugins(RevolverPlugin)
.configs((IntegrationTest extend Test))
.settings(Defaults.itSettings,sharedSettings)
.settings(Defaults.itSettings, sharedSettings)
.dependsOn(
authentication % "compile->compile;test->test",
common % "test->test;it->it;test->it"
Expand All @@ -116,7 +116,7 @@ lazy val projects = (project in file("modules/projects"))
lazy val tasks = (project in file("modules/tasks"))
.disablePlugins(RevolverPlugin)
.configs((IntegrationTest extend Test))
.settings(Defaults.itSettings,sharedSettings)
.settings(Defaults.itSettings, sharedSettings)
.dependsOn(
authentication % "compile->compile;test->test",
common % "test->test;it->it;compile->compile;test->it"
Expand All @@ -137,7 +137,7 @@ lazy val filters = (project in file("modules/filters"))

lazy val stats = (project in file("modules/stats"))
.disablePlugins(RevolverPlugin)
.settings(Defaults.itSettings,sharedSettings)
.settings(Defaults.itSettings, sharedSettings)
.dependsOn(
authentication % "compile->compile;test->test",
common % "test->test"
Expand All @@ -159,13 +159,13 @@ lazy val sharedSettings = Seq(
).map(_.exclude("org.slf4j", "*")),
addCompilerPlugin(kindProjector),
scalacOptions ++= Seq(
"-deprecation",
"-encoding",
"UTF-8",
"-language:higherKinds",
"-language:postfixOps",
"-feature",
"-Xlint:unused",
"-Ymacro-annotations"
)
"-deprecation",
"-encoding",
"UTF-8",
"-language:higherKinds",
"-language:postfixOps",
"-feature",
"-Xlint:unused",
"-Ymacro-annotations"
)
)
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
package taskforce.authentication


import doobie.implicits._
import doobie.postgres.implicits._
import doobie.util.transactor.Transactor
import taskforce.common.NewTypeDoobieMeta
import cats.effect.kernel.MonadCancelThrow


trait UserRepository[F[_]] {
def find(userId: UserId): F[Option[User]]
def create(user: User): F[Int]
}

object UserRepository {
def make[F[_] : MonadCancelThrow](xa: Transactor[F]) =
def make[F[_]: MonadCancelThrow](xa: Transactor[F]) =
new UserRepository[F] with NewTypeDoobieMeta {

override def create(user: User): F[Int] =
sql.insert(user).update.run.transact(xa)
override def create(user: User): F[Int] =
sql.insert(user).update.run.transact(xa)

override def find(userId: UserId): F[Option[User]] =
sql
.find(userId)
.query[User]
.option
.transact(xa)
override def find(userId: UserId): F[Option[User]] =
sql
.find(userId)
.query[User]
.option
.transact(xa)

private object sql {
def insert(user: User) = sql"insert into users(id) values(${user.id})"
def find(userId: UserId) =
sql"select id from users where id =${userId.value}"
}
private object sql {
def insert(user: User) = sql"insert into users(id) values(${user.id})"
def find(userId: UserId) =
sql"select id from users where id =${userId.value}"
}

}
}
}
17 changes: 8 additions & 9 deletions modules/common/src/it/scala/taskforce/BasicRepositorySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.typelevel.log4cats.slf4j.Slf4jLogger

trait BasicRepositorySuite extends CatsEffectSuite with ScalaCheckEffectSuite {

implicit def unsafeLogger[F[_]: Sync] = Slf4jLogger.getLogger[F]
implicit def unsafeLogger[F[_]: Sync] = Slf4jLogger.getLogger[F]
var db: DatabaseConfig = null
var flyway: Flyway = null
var xa: transactor.Transactor.Aux[IO, Unit] = null
Expand All @@ -26,14 +26,13 @@ trait BasicRepositorySuite extends CatsEffectSuite with ScalaCheckEffectSuite {

db = ConfigSource.default
.at("database")
.load[DatabaseConfig]
match {
case Left(errors) =>
throw new RuntimeException(s"Configuration loading Err: ${errors.toList.mkString("\n")}")
case Right(value) =>
value
}

.load[DatabaseConfig] match {
case Left(errors) =>
throw new RuntimeException(s"Configuration loading Err: ${errors.toList.mkString("\n")}")
case Right(value) =>
value
}

flyway = Flyway.configure().dataSource(db.url.value, db.user.value, db.pass.value).load()
flyway.clean()
flyway.migrate()
Expand Down
7 changes: 2 additions & 5 deletions modules/common/src/main/scala/taskforce/common/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import java.time.Instant
package object common {

type CreationDate = CreationDate.Type
object CreationDate
extends NewtypeWrapped[Instant]

object CreationDate extends NewtypeWrapped[Instant]

type DeletionDate = DeletionDate.Type
object DeletionDate
extends NewtypeWrapped[Instant]
object DeletionDate extends NewtypeWrapped[Instant]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package taskforce.filter


import cats.implicits._
import doobie._
import doobie.implicits._
Expand All @@ -20,7 +19,6 @@ import org.typelevel.log4cats.Logger
import cats.Show
import java.time.Instant


trait FilterRepository[F[_]] {
def create(filter: Filter): F[Filter]
def delete(id: FilterId): F[Int]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import taskforce.common.Sqlizer.ops._
import taskforce.filter._
import taskforce.common.NewTypeDoobieMeta



trait Doobie extends taskforce.task.instances.Doobie with NewTypeDoobieMeta with doobie.util.meta.LegacyInstantMetaInstance {
trait Doobie
extends taskforce.task.instances.Doobie
with NewTypeDoobieMeta
with doobie.util.meta.LegacyInstantMetaInstance {

implicit val putNonEmptyList: Put[List[NonEmptyString]] =
Put[List[String]].contramap(_.map(_.value))
Expand Down
10 changes: 5 additions & 5 deletions modules/filters/src/test/scala/taskforce/filter/generators.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package taskforce.filter


import eu.timepit.refined.api.Refined
import eu.timepit.refined.numeric.Positive
import eu.timepit.refined.types.string.NonEmptyString
Expand Down Expand Up @@ -28,7 +27,8 @@ object generators {
} yield LocalDate
.parse("2000.01.01", DateTimeFormatter.ofPattern("yyyy.MM.dd"))
.atStartOfDay()
.plusMinutes(minutes.toLong).toInstant(ZoneOffset.UTC)
.plusMinutes(minutes.toLong)
.toInstant(ZoneOffset.UTC)
val operatorGen: Gen[Operator] = Gen.oneOf(List(Eq, Gt, Gteq, Lteq, Lt))

val statusGen: Gen[Status] = Gen.oneOf(List(Active, Deactive, All))
Expand All @@ -39,7 +39,7 @@ object generators {
.map(In.apply)

val taskCreatedGen: Gen[TaskCreatedDate] = for {
op <- operatorGen
op <- operatorGen
date <- instantGen
} yield TaskCreatedDate(op, date)

Expand All @@ -57,7 +57,7 @@ object generators {
val newFilterGen = conditionsGen.map(NewFilter.apply)

val filterGen = for {
c <- conditionsGen
c <- conditionsGen
id <- filterIdGen
} yield Filter(id, c)

Expand All @@ -71,7 +71,7 @@ object generators {

val pageGen = for {
size <- pageSizeGen
no <- pageNoGen
no <- pageNoGen
} yield Page(no, size)

val sortByGen = for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ProjectRoutesSuite extends HttpTestSuite with Circe {
DuplicateProjectNameError(newProject).asLeft[Project].pure[IO]
}
val routes =
ProjectRoutes.make[IO](authMiddleware(p1.author), ProjectService.make[IO](projectRepo)).routes(errHandler)
ProjectRoutes.make[IO](authMiddleware(p1.author), ProjectService.make[IO](projectRepo)).routes(errHandler)
PUT(p2.name, Uri.unsafeFromString(s"api/v1/projects/${p1.id.value}")).pure[IO].flatMap { req =>
assertHttp(routes, req)(
Status.Conflict,
Expand Down Expand Up @@ -89,7 +89,7 @@ class ProjectRoutesSuite extends HttpTestSuite with Circe {
test("cannot delete others project") {
PropF.forAllF { (p: Project, u: UserId) =>
val projectRepo = new TestProjectRepository(List(p), currentTime)
val routes = ProjectRoutes.make[IO](authMiddleware(u), ProjectService.make[IO](projectRepo)).routes(errHandler)
val routes = ProjectRoutes.make[IO](authMiddleware(u), ProjectService.make[IO](projectRepo)).routes(errHandler)

DELETE(Uri.unsafeFromString(s"api/v1/projects/${p.id.value}")).pure[IO].flatMap { req =>
assertHttp(routes, req)(Status.Forbidden, ErrorMessage("BASIC-003", "User is not an owner of the resource"))
Expand All @@ -99,7 +99,7 @@ class ProjectRoutesSuite extends HttpTestSuite with Circe {
test("provide valid response where project is not found") {
PropF.forAllF { (p: ProjectId, u: UserId) =>
val projectRepo = new TestProjectRepository(List(), currentTime)
val routes = ProjectRoutes.make[IO](authMiddleware(u), ProjectService.make[IO](projectRepo)).routes(errHandler)
val routes = ProjectRoutes.make[IO](authMiddleware(u), ProjectService.make[IO](projectRepo)).routes(errHandler)

DELETE(Uri.unsafeFromString(s"api/v1/projects/${p.value}")).pure[IO].flatMap { req =>
assertHttp(routes, req)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ object generators {
} yield LocalDate
.parse("2000.01.01", DateTimeFormatter.ofPattern("yyyy.MM.dd"))
.atStartOfDay()
.plusMinutes(minutes.toLong).toInstant(ZoneOffset.UTC)
.plusMinutes(minutes.toLong)
.toInstant(ZoneOffset.UTC)

val projectGen: Gen[Project] =
for {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package taskforce.stats


final class StatsService[F[_]] private (statsRepo: StatsRepository[F]) {
def getStats(query: StatsQuery) = statsRepo.get(query)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class TaskRepositorySuite extends BasicRepositorySuite {
PropF.forAllF { (t: Task) =>
for {
repo <- taskRepo
_ <- Logger[IO].info("Before All PFL")
_ <- Logger[IO].info("Before All PFL")
allBefore <- repo.list(ProjectId(1)).compile.toList
task = t.copy(projectId = ProjectId(1), author = userID)
_ <- Logger[IO].info("Task created")
_ <- Logger[IO].info("Task created")
taskResult <- repo.create(task)
allAfter <- repo.list(ProjectId(1)).compile.toList
} yield assertEquals(
Expand Down
1 change: 0 additions & 1 deletion modules/tasks/src/main/scala/taskforce/task/Task.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package taskforce.task


import java.util.UUID
import taskforce.authentication.UserId
import taskforce.common._
Expand Down
Loading