-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
179 additions
and
1,044 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 33 additions & 98 deletions
131
app/de/innfactory/bootstrapplay2/companies/application/CompanyController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,59 @@ | ||
package de.innfactory.bootstrapplay2.companies.application | ||
|
||
import akka.NotUsed | ||
import akka.stream.Materializer | ||
import akka.stream.scaladsl.Source | ||
import cats.data.EitherT | ||
import de.innfactory.bootstrapplay2.commons.RequestContextWithUser | ||
import de.innfactory.bootstrapplay2.application.controller.BaseController | ||
import de.innfactory.bootstrapplay2.companies.application.mapper.CompanyMapper | ||
import de.innfactory.play.smithy4play.ImplicitLogContext | ||
import de.innfactory.bootstrapplay2.commons.application.actions.{TracingAction, TracingUserAction} | ||
import de.innfactory.bootstrapplay2.commons.application.actions.models.{RequestWithTrace, RequestWithUser} | ||
import de.innfactory.bootstrapplay2.companies.domain.interfaces.CompanyService | ||
import play.api.mvc.{Action, AnyContent, ControllerComponents} | ||
import de.innfactory.bootstrapplay2.companies.application.models.{CompanyRequest, CompanyResponse} | ||
import de.innfactory.bootstrapplay2.companies.domain.models.{Company, CompanyId} | ||
import play.api.mvc.ControllerComponents | ||
import de.innfactory.bootstrapplay2.companies.domain.models.CompanyId | ||
import de.innfactory.bootstrapplay2.definition | ||
import de.innfactory.bootstrapplay2.definition.{CompaniesResponse, CompanyAPIController} | ||
import de.innfactory.play.controller.{BaseController, ResultStatus} | ||
import de.innfactory.bootstrapplay2.definition.{ | ||
CompaniesResponse, | ||
CompanyAPIController, | ||
CompanyRequestBody, | ||
CompanyResponse | ||
} | ||
import de.innfactory.smithy4play.{AutoRouting, ContextRoute} | ||
import smithy4s.Document | ||
import play.api.Application | ||
|
||
import javax.inject.{Inject, Singleton} | ||
import scala.concurrent.{ExecutionContext, Future} | ||
import scala.concurrent.ExecutionContext | ||
import scala.language.implicitConversions | ||
|
||
@AutoRouting | ||
@Singleton | ||
class CompanyController @Inject() ( | ||
tracingUserAction: TracingUserAction, | ||
companyService: CompanyService, | ||
tracingAction: TracingAction | ||
companyService: CompanyService | ||
)(implicit | ||
ec: ExecutionContext, | ||
cc: ControllerComponents, | ||
mat: Materializer | ||
app: Application | ||
) extends BaseController | ||
with ImplicitLogContext | ||
with CompanyAPIController[ContextRoute] { | ||
with CompanyAPIController[ContextRoute] | ||
with CompanyMapper { | ||
|
||
// implicit private def companyRequestToCompany(companyRequest: CompanyRequest): Company = companyRequest.toCompany() | ||
// | ||
// implicit private val outMapperSeq: OutMapper[Seq[Company], Seq[CompanyResponse]] = | ||
// OutMapper[Seq[Company], Seq[CompanyResponse]](companies => companies.map(CompanyResponse.fromCompany)) | ||
// | ||
// implicit private val outMapper: OutMapper[Company, CompanyResponse] = | ||
// OutMapper[Company, CompanyResponse](CompanyResponse.fromCompany) | ||
// | ||
// implicit private val outMapperBoolean: OutMapper[Boolean, Boolean] = | ||
// OutMapper[Boolean, Boolean](b => b) | ||
// | ||
// implicit private val outMapperSource: OutMapper[Source[Company, NotUsed], Source[CompanyResponse, NotUsed]] = | ||
// OutMapper[Source[Company, NotUsed], Source[CompanyResponse, NotUsed]](v => v.map(CompanyResponse.fromCompany)) | ||
// | ||
// private val UserInEndpoint = Endpoint.in[RequestWithUser](tracingUserAction()) | ||
// | ||
// def getById(id: Long): Action[AnyContent] = | ||
// UserInEndpoint | ||
// .logic((_, rc) => companyService.getById(CompanyId(id))(requestContextWithUser(rc))) | ||
// .mapOutTo[CompanyResponse] | ||
// .result(r => r.completeResult()) | ||
// | ||
// def getAll: Action[AnyContent] = | ||
// UserInEndpoint | ||
// .logic((_, rc) => companyService.getAll()(requestContextWithUser(rc))) | ||
// .mapOutTo[Seq[CompanyResponse]] | ||
// .result(_.completeResult()) | ||
// | ||
// def getAllPublic(filter: Option[String]): Action[AnyContent] = | ||
// UserInEndpoint | ||
// .logic((_, rc) => EitherT.right[ResultStatus](companyService.getAllForGraphQL(filter)(requestContext(rc)))) | ||
// .mapOutTo[Seq[CompanyResponse]] | ||
// .result(_.completeResult()) | ||
// | ||
// def delete(id: Long): Action[AnyContent] = | ||
// UserInEndpoint | ||
// .logic((_, r) => companyService.deleteCompany(CompanyId(id))(requestContextWithUser(r))) | ||
// .mapOutTo[Boolean] | ||
// .result(_.completeResultWithoutBody(statusCode = 204)) | ||
// | ||
// private def UpdateCreateEndpoint( | ||
// logic: (Company, RequestContextWithUser) => EitherT[Future, ResultStatus, Company] | ||
// ): Endpoint[CompanyRequest, CompanyResponse, RequestWithUser, Company, Company] = | ||
// Endpoint | ||
// .in[CompanyRequest, RequestWithUser, Company](tracingUserAction()) | ||
// .logic((companyRequest, rc) => logic(companyRequest, requestContextWithUser(rc))) | ||
// .mapOutTo[CompanyResponse] | ||
// | ||
// def update: Action[CompanyRequest] = | ||
// UpdateCreateEndpoint((c, r) => companyService.updateCompany(c)(r)) | ||
// .result(_.completeResultWithoutBody(statusCode = 204)) | ||
// | ||
// def create: Action[CompanyRequest] = | ||
// UpdateCreateEndpoint((c, r) => companyService.createCompany(c)(r)) | ||
// .result(_.completeResult()) | ||
// | ||
// def getAllCompaniesAsSource: Action[AnyContent] = | ||
// UserInEndpoint | ||
// .logic[Source[Company, NotUsed]]((_, r) => companyService.getAllCompaniesAsStream()(requestContextWithUser(r))) | ||
// .mapOutTo[Source[CompanyResponse, NotUsed]] | ||
// .result(_.completeSourceChunked()) | ||
override def getCompanyById(companyId: Long): ContextRoute[definition.CompanyResponse] = | ||
Endpoint.withAuth | ||
.execute(companyService.getById(CompanyId(companyId))(_)) | ||
.complete | ||
|
||
override def getCompanyById(companyId: String): ContextRoute[definition.CompanyResponse] = ??? | ||
override def getAllCompanies(): ContextRoute[CompaniesResponse] = | ||
Endpoint.withAuth | ||
.execute(companyService.getAll()(_)) | ||
.complete | ||
|
||
override def getAllCompanies(): ContextRoute[CompaniesResponse] = ??? | ||
override def createCompany(body: CompanyRequestBody): ContextRoute[CompanyResponse] = Endpoint.withAuth | ||
.execute(companyService.createCompany(body)(_)) | ||
.complete | ||
|
||
override def createCompany( | ||
id: Option[Long], | ||
settings: Option[Document], | ||
stringAttribute1: Option[String], | ||
stringAttribute2: Option[String], | ||
longAttribute1: Option[Long], | ||
booleanAttribute: Option[Boolean] | ||
): ContextRoute[definition.CompanyResponse] = ??? | ||
override def updateCompany(body: CompanyRequestBody): ContextRoute[CompanyResponse] = Endpoint.withAuth | ||
.execute(companyService.updateCompany(body)(_)) | ||
.complete | ||
|
||
override def updateCompany( | ||
id: Option[Long], | ||
settings: Option[Document], | ||
stringAttribute1: Option[String], | ||
stringAttribute2: Option[String], | ||
longAttribute1: Option[Long], | ||
booleanAttribute: Option[Boolean] | ||
): ContextRoute[definition.CompanyResponse] = ??? | ||
override def deleteCompany(companyId: Long): ContextRoute[Unit] = Endpoint.withAuth | ||
.execute(companyService.deleteCompany(CompanyId(companyId))(_)) | ||
.complete | ||
|
||
override def deleteCompany(companyId: String): ContextRoute[Unit] = ??? | ||
} |
29 changes: 29 additions & 0 deletions
29
app/de/innfactory/bootstrapplay2/companies/application/mapper/CompanyMapper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package de.innfactory.bootstrapplay2.companies.application.mapper | ||
|
||
import de.innfactory.bootstrapplay2.application.controller.BaseMapper | ||
import de.innfactory.bootstrapplay2.companies.domain.models.{Company, CompanyId} | ||
import de.innfactory.bootstrapplay2.definition.{CompaniesResponse, CompanyRequestBody, CompanyResponse} | ||
import io.scalaland.chimney.dsl.TransformerOps | ||
|
||
trait CompanyMapper extends BaseMapper { | ||
implicit val companyToCompanyResponse: Company => CompanyResponse = ( | ||
company: Company | ||
) => | ||
company | ||
.into[CompanyResponse] | ||
.withFieldComputed(_.id, c => c.id.get.value) | ||
.withFieldComputed(_.created, c => dateTimeToDateWithTime(c.created.get)) | ||
.withFieldComputed(_.updated, c => dateTimeToDateWithTime(c.updated.get)) | ||
.transform | ||
|
||
implicit val companiesToCompaniesResponse: Seq[Company] => CompaniesResponse = (companies: Seq[Company]) => | ||
CompaniesResponse(companies.map(companyToCompanyResponse)) | ||
|
||
implicit val companyRequestBodyToCompany: CompanyRequestBody => Company = (companyRequestBody: CompanyRequestBody) => | ||
companyRequestBody | ||
.into[Company] | ||
.withFieldComputed(_.id, c => c.id.map(CompanyId)) | ||
.withFieldConst(_.created, None) | ||
.withFieldConst(_.updated, None) | ||
.transform | ||
} |
30 changes: 0 additions & 30 deletions
30
app/de/innfactory/bootstrapplay2/companies/application/models/CompanyRequest.scala
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
app/de/innfactory/bootstrapplay2/companies/application/models/CompanyResponse.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.