Skip to content

Commit

Permalink
Setup S3 bucket URL
Browse files Browse the repository at this point in the history
  • Loading branch information
johnspade committed May 28, 2023
1 parent bb435d3 commit c69d9b0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ru.johnspade.nastenka.errors.InvestigationNotFound
import ru.johnspade.nastenka.models.Investigation
import ru.johnspade.nastenka.models.InvestigationFullModel
import ru.johnspade.nastenka.models.NewInvestigation
import ru.johnspade.nastenka.models.Pin
import ru.johnspade.nastenka.models.PinModel
import ru.johnspade.nastenka.models.UpdatedInvestigation
import zio.*
Expand All @@ -24,8 +25,15 @@ trait ApiInvestigationService:

def delete(id: UUID): ZIO[Any, Nothing, Unit]

class ApiInvestigationServiceLive(investigationRepo: ApiInvestigationRepository, emailConfig: EmailConfig)
extends ApiInvestigationService:
class ApiInvestigationServiceLive(
investigationRepo: ApiInvestigationRepository,
emailConfig: EmailConfig,
s3Config: S3PublicConfig
) extends ApiInvestigationService:
private val pinModelTransformer = Transformer
.define[Pin, PinModel]
.build(Field.computed(_.images, _.images.map(fileKey => s"${s3Config.publicBucketUrl}/$fileKey")))

override def getAll: ZIO[Any, Nothing, List[Investigation]] =
investigationRepo.getAll.orDie

Expand All @@ -37,7 +45,10 @@ class ApiInvestigationServiceLive(investigationRepo: ApiInvestigationRepository,
.refineToOrDie[InvestigationNotFound]
.map(
_.into[InvestigationFullModel]
.transform(Field.const(_.email, s"$username+$id@$domain"))
.transform(
Field.const(_.email, s"$username+$id@$domain"),
Field.computed(_.pins, _.pins.map(pinModelTransformer.transform))
)
)

override def create(newInvestigation: NewInvestigation): ZIO[Any, Nothing, Investigation] =
Expand Down Expand Up @@ -68,5 +79,6 @@ object ApiInvestigationServiceLive:
for
investigationRepo <- ZIO.service[ApiInvestigationRepository]
emailConfig <- ZIO.config(EmailConfig.descriptor)
yield new ApiInvestigationServiceLive(investigationRepo, emailConfig)
s3PublicConfig <- ZIO.config(S3PublicConfig.descriptor)
yield new ApiInvestigationServiceLive(investigationRepo, emailConfig, s3PublicConfig)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ru.johnspade.nastenka.api

import zio.*

final case class S3PublicConfig(publicBucketUrl: String)

object S3PublicConfig:
val descriptor: Config[S3PublicConfig] = Config.string("S3_PUBLIC_BUCKET_URL").map(url => S3PublicConfig(url))
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ final class InvestigationView(investigationPage: Signal[Page.InvestigationPage])
),
renderContent(pin),
div(
pin.images.map(k => s"http://localhost:9000/nastenka/$k").map { link =>
pin.images.map { link =>
img(
src(link)
)
Expand Down

0 comments on commit c69d9b0

Please sign in to comment.