Skip to content

Commit

Permalink
Merge pull request #176 from DeamonDev/improvement/use-scala3-interse…
Browse files Browse the repository at this point in the history
…ction-types-operator-instead-of-with-keyword

Rename `with` keyword by `&` in ZIO environment type argument
  • Loading branch information
adamw authored Jul 29, 2023
2 parents be9a746 + 8961e73 commit 722d2d6
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/com/softwaremill/realworld/Endpoints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Endpoints(

object Endpoints:
val live: ZLayer[
ArticlesServerEndpoints with CommentsServerEndpoints with TagsServerEndpoints with UsersServerEndpoints,
ArticlesServerEndpoints & CommentsServerEndpoints & TagsServerEndpoints & UsersServerEndpoints,
Nothing,
Endpoints
] =
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/softwaremill/realworld/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object Main extends ZIOAppDefault:

override val bootstrap: ZLayer[ZIOAppArgs, Any, Any] = SLF4J.slf4j(LogFormat.colored)

override def run: ZIO[Any with ZIOAppArgs with Scope, Any, Any] =
override def run: ZIO[Any & ZIOAppArgs & Scope, Any, Any] =

val port = sys.env.get("HTTP_PORT").flatMap(_.toIntOption).getOrElse(8080)
val options: ZioHttpServerOptions[Any] = ZioHttpServerOptions.customiseInterceptors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ class CommentsServerEndpoints(commentsService: CommentsService, commentsEndpoint
)

object CommentsServerEndpoints:
val live: ZLayer[CommentsService with CommentsEndpoints, Nothing, CommentsServerEndpoints] =
val live: ZLayer[CommentsService & CommentsEndpoints, Nothing, CommentsServerEndpoints] =
ZLayer.fromFunction(new CommentsServerEndpoints(_, _))
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ class CommentsService(

object CommentsService:

val live: ZLayer[CommentsRepository with ArticlesRepository, Nothing, CommentsService] =
val live: ZLayer[CommentsRepository & ArticlesRepository, Nothing, CommentsService] =
ZLayer.fromFunction(CommentsService(_, _))
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ class ArticlesServerEndpoints(articlesEndpoints: ArticlesEndpoints, articlesServ
)

object ArticlesServerEndpoints:
val live: ZLayer[ArticlesEndpoints with ArticlesService, Nothing, ArticlesServerEndpoints] =
val live: ZLayer[ArticlesEndpoints & ArticlesService, Nothing, ArticlesServerEndpoints] =
ZLayer.fromFunction(new ArticlesServerEndpoints(_, _))
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ class ArticlesService(
object ArticlesService:
private def ArticleNotFoundMessage(slug: ArticleSlug): String = s"Article with slug ${slug.value} doesn't exist."

val live: ZLayer[ArticlesRepository with UsersRepository, Nothing, ArticlesService] =
val live: ZLayer[ArticlesRepository & UsersRepository, Nothing, ArticlesService] =
ZLayer.fromFunction(ArticlesService(_, _))
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ class TagsServerEndpoints(tagsEndpoints: TagsEndpoints, tagsService: TagsService
List(getTagsServerEndpoint)

object TagsServerEndpoints:
val live: ZLayer[TagsEndpoints with TagsService, Nothing, TagsServerEndpoints] = ZLayer.fromFunction(new TagsServerEndpoints(_, _))
val live: ZLayer[TagsEndpoints & TagsService, Nothing, TagsServerEndpoints] = ZLayer.fromFunction(new TagsServerEndpoints(_, _))
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class BaseEndpoints(authService: AuthService, usersRepository: UsersRepository):
object BaseEndpoints:
private val UserWithEmailNotFoundMessage: String => String = (email: String) => s"User with email $email doesn't exist"

val live: ZLayer[AuthService with UsersRepository, Nothing, BaseEndpoints] = ZLayer.fromFunction(new BaseEndpoints(_, _))
val live: ZLayer[AuthService & UsersRepository, Nothing, BaseEndpoints] = ZLayer.fromFunction(new BaseEndpoints(_, _))

val defaultErrorOutputs: EndpointOutput.OneOf[ErrorInfo, ErrorInfo] = oneOf[ErrorInfo](
oneOfVariant(statusCode(StatusCode.BadRequest).and(jsonBody[BadRequest])),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ class UsersServerEndpoints(usersService: UsersService, userEndpoints: UsersEndpo
)

object UsersServerEndpoints:
val live: ZLayer[UsersService with UsersEndpoints, Nothing, UsersServerEndpoints] =
val live: ZLayer[UsersService & UsersEndpoints, Nothing, UsersServerEndpoints] =
ZLayer.fromFunction(new UsersServerEndpoints(_, _))
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ object UsersService:
private def UserWithEmailAlreadyInUseMessage(email: String): String = s"User with email $email already in use"
private def UserWithUsernameAlreadyInUseMessage(username: String): String = s"User with username $username already in use"

val live: ZLayer[AuthService with UsersRepository, Nothing, UsersService] = ZLayer.fromFunction(UsersService(_, _))
val live: ZLayer[AuthService & UsersRepository, Nothing, UsersService] = ZLayer.fromFunction(UsersService(_, _))
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ object ArticleRepositoryTestSupport:
def checkIfArticleAlreadyExistsInCreate(
articleCreateData: ArticleCreateData,
userEmail: String
): ZIO[ArticlesRepository with UsersRepository, Object, TestResult] =
): ZIO[ArticlesRepository & UsersRepository, Object, TestResult] =
assertZIO((for {
userId <- callFindUserIdByEmail(userEmail).someOrFail(s"User $userEmail doesn't exist")
_ <- callCreateArticle(articleCreateData, userId)
Expand All @@ -151,7 +151,7 @@ object ArticleRepositoryTestSupport:
updatedDescription: String,
updatedBody: String,
viewerId: Int
): ZIO[ArticlesRepository with UsersRepository, Object, TestResult] =
): ZIO[ArticlesRepository & UsersRepository, Object, TestResult] =
assertZIO((for {
articleId <- callFindArticleIdBySlug(existingSlug).someOrFail(s"Article $existingSlug doesn't exist")
articleToUpdate = Article(
Expand Down Expand Up @@ -179,7 +179,7 @@ object ArticleRepositoryTestSupport:
articleCreateData: ArticleCreateData,
userEmail: String,
viewerId: Int
): ZIO[ArticlesRepository with UsersRepository, Object, TestResult] =
): ZIO[ArticlesRepository & UsersRepository, Object, TestResult] =
for {
userId <- callFindUserIdByEmail(userEmail).someOrFail(s"User $userEmail doesn't exist")
articleOrError <- callCreateArticle(articleCreateData, userId).either
Expand Down Expand Up @@ -544,7 +544,7 @@ object ArticleRepositoryTestSupport:
articleCreateData: ArticleCreateData,
userEmail: String,
viewerId: Int
): ZIO[ArticlesRepository with UsersRepository, Object, TestResult] =
): ZIO[ArticlesRepository & UsersRepository, Object, TestResult] =
for {
userId <- callFindUserIdByEmail(userEmail).someOrFail(s"User $userEmail doesn't exist")
_ <- callCreateArticle(articleCreateData, userId)
Expand Down Expand Up @@ -577,7 +577,7 @@ object ArticleRepositoryTestSupport:
updatedDescription: String,
updatedBody: String,
viewerId: Int
): ZIO[ArticlesRepository with UsersRepository, Object, TestResult] =
): ZIO[ArticlesRepository & UsersRepository, Object, TestResult] =
for {
articleId <- callFindArticleIdBySlug(existingSlug).someOrFail(s"Article $existingSlug doesn't exist")
articleUpdateData = Article(
Expand Down Expand Up @@ -606,7 +606,7 @@ object ArticleRepositoryTestSupport:
def deleteArticle(
slug: ArticleSlug,
viewerId: Int
): ZIO[ArticlesRepository with UsersRepository with CommentsRepository with TagsRepository, Object, TestResult] =
): ZIO[ArticlesRepository & UsersRepository & CommentsRepository & TagsRepository, Object, TestResult] =
for {
articleId <- callFindArticleIdBySlug(slug).someOrFail(s"Article $slug doesn't exist")
commentsBefore <- callFindComments(articleId, Some(viewerId))
Expand All @@ -630,7 +630,7 @@ object ArticleRepositoryTestSupport:
def checkMarkFavorite(
slug: ArticleSlug,
viewerId: Int
): ZIO[ArticlesRepository with UsersRepository, Object, TestResult] =
): ZIO[ArticlesRepository & UsersRepository, Object, TestResult] =
for {
articleId <- callFindArticleIdBySlug(slug).someOrFail(s"Article $slug doesn't exist")
_ <- callMakeFavorite(articleId, viewerId)
Expand All @@ -645,7 +645,7 @@ object ArticleRepositoryTestSupport:
def checkRemoveFavorite(
slug: ArticleSlug,
viewerId: Int
): ZIO[ArticlesRepository with UsersRepository, Object, TestResult] =
): ZIO[ArticlesRepository & UsersRepository, Object, TestResult] =
for {
articleId <- callFindArticleIdBySlug(slug).someOrFail(s"Article $slug doesn't exist")
_ <- callRemoveFavorite(articleId, viewerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object TestUtils:
.thenRunLogic()
.backend()

type TestDbLayer = DbConfig with DataSource with DbMigrator with Quill.Sqlite[SnakeCase]
type TestDbLayer = DbConfig & DataSource & DbMigrator & Quill.Sqlite[SnakeCase]

def getValidTokenAuthenticationHeader(email: String = exampleUser1.email): RIO[AuthService, Map[String, String]] =
for {
Expand Down

0 comments on commit 722d2d6

Please sign in to comment.