|
1 | 1 | package de.innfactory.bootstrapplay2.companies.application
|
2 | 2 |
|
3 |
| -import akka.NotUsed |
4 | 3 | import akka.stream.Materializer
|
5 |
| -import akka.stream.scaladsl.Source |
6 |
| -import cats.data.EitherT |
7 |
| -import de.innfactory.bootstrapplay2.commons.RequestContextWithUser |
| 4 | +import de.innfactory.bootstrapplay2.application.controller.BaseController |
| 5 | +import de.innfactory.bootstrapplay2.companies.application.mapper.CompanyMapper |
8 | 6 | import de.innfactory.play.smithy4play.ImplicitLogContext
|
9 |
| -import de.innfactory.bootstrapplay2.commons.application.actions.{TracingAction, TracingUserAction} |
10 |
| -import de.innfactory.bootstrapplay2.commons.application.actions.models.{RequestWithTrace, RequestWithUser} |
11 | 7 | import de.innfactory.bootstrapplay2.companies.domain.interfaces.CompanyService
|
12 |
| -import play.api.mvc.{Action, AnyContent, ControllerComponents} |
13 |
| -import de.innfactory.bootstrapplay2.companies.application.models.{CompanyRequest, CompanyResponse} |
14 |
| -import de.innfactory.bootstrapplay2.companies.domain.models.{Company, CompanyId} |
| 8 | +import play.api.mvc.ControllerComponents |
| 9 | +import de.innfactory.bootstrapplay2.companies.domain.models.CompanyId |
15 | 10 | import de.innfactory.bootstrapplay2.definition
|
16 |
| -import de.innfactory.bootstrapplay2.definition.{CompaniesResponse, CompanyAPIController} |
17 |
| -import de.innfactory.play.controller.{BaseController, ResultStatus} |
| 11 | +import de.innfactory.bootstrapplay2.definition.{ |
| 12 | + CompaniesResponse, |
| 13 | + CompanyAPIController, |
| 14 | + CompanyRequestBody, |
| 15 | + CompanyResponse |
| 16 | +} |
18 | 17 | import de.innfactory.smithy4play.{AutoRouting, ContextRoute}
|
19 |
| -import smithy4s.Document |
| 18 | +import play.api.Application |
20 | 19 |
|
21 | 20 | import javax.inject.{Inject, Singleton}
|
22 |
| -import scala.concurrent.{ExecutionContext, Future} |
| 21 | +import scala.concurrent.ExecutionContext |
23 | 22 | import scala.language.implicitConversions
|
24 | 23 |
|
25 | 24 | @AutoRouting
|
26 | 25 | @Singleton
|
27 | 26 | class CompanyController @Inject() (
|
28 |
| - tracingUserAction: TracingUserAction, |
29 |
| - companyService: CompanyService, |
30 |
| - tracingAction: TracingAction |
| 27 | + companyService: CompanyService |
31 | 28 | )(implicit
|
32 | 29 | ec: ExecutionContext,
|
33 | 30 | cc: ControllerComponents,
|
34 |
| - mat: Materializer |
| 31 | + app: Application |
35 | 32 | ) extends BaseController
|
36 | 33 | with ImplicitLogContext
|
37 |
| - with CompanyAPIController[ContextRoute] { |
| 34 | + with CompanyAPIController[ContextRoute] |
| 35 | + with CompanyMapper { |
38 | 36 |
|
39 |
| -// implicit private def companyRequestToCompany(companyRequest: CompanyRequest): Company = companyRequest.toCompany() |
40 |
| -// |
41 |
| -// implicit private val outMapperSeq: OutMapper[Seq[Company], Seq[CompanyResponse]] = |
42 |
| -// OutMapper[Seq[Company], Seq[CompanyResponse]](companies => companies.map(CompanyResponse.fromCompany)) |
43 |
| -// |
44 |
| -// implicit private val outMapper: OutMapper[Company, CompanyResponse] = |
45 |
| -// OutMapper[Company, CompanyResponse](CompanyResponse.fromCompany) |
46 |
| -// |
47 |
| -// implicit private val outMapperBoolean: OutMapper[Boolean, Boolean] = |
48 |
| -// OutMapper[Boolean, Boolean](b => b) |
49 |
| -// |
50 |
| -// implicit private val outMapperSource: OutMapper[Source[Company, NotUsed], Source[CompanyResponse, NotUsed]] = |
51 |
| -// OutMapper[Source[Company, NotUsed], Source[CompanyResponse, NotUsed]](v => v.map(CompanyResponse.fromCompany)) |
52 |
| -// |
53 |
| -// private val UserInEndpoint = Endpoint.in[RequestWithUser](tracingUserAction()) |
54 |
| -// |
55 |
| -// def getById(id: Long): Action[AnyContent] = |
56 |
| -// UserInEndpoint |
57 |
| -// .logic((_, rc) => companyService.getById(CompanyId(id))(requestContextWithUser(rc))) |
58 |
| -// .mapOutTo[CompanyResponse] |
59 |
| -// .result(r => r.completeResult()) |
60 |
| -// |
61 |
| -// def getAll: Action[AnyContent] = |
62 |
| -// UserInEndpoint |
63 |
| -// .logic((_, rc) => companyService.getAll()(requestContextWithUser(rc))) |
64 |
| -// .mapOutTo[Seq[CompanyResponse]] |
65 |
| -// .result(_.completeResult()) |
66 |
| -// |
67 |
| -// def getAllPublic(filter: Option[String]): Action[AnyContent] = |
68 |
| -// UserInEndpoint |
69 |
| -// .logic((_, rc) => EitherT.right[ResultStatus](companyService.getAllForGraphQL(filter)(requestContext(rc)))) |
70 |
| -// .mapOutTo[Seq[CompanyResponse]] |
71 |
| -// .result(_.completeResult()) |
72 |
| -// |
73 |
| -// def delete(id: Long): Action[AnyContent] = |
74 |
| -// UserInEndpoint |
75 |
| -// .logic((_, r) => companyService.deleteCompany(CompanyId(id))(requestContextWithUser(r))) |
76 |
| -// .mapOutTo[Boolean] |
77 |
| -// .result(_.completeResultWithoutBody(statusCode = 204)) |
78 |
| -// |
79 |
| -// private def UpdateCreateEndpoint( |
80 |
| -// logic: (Company, RequestContextWithUser) => EitherT[Future, ResultStatus, Company] |
81 |
| -// ): Endpoint[CompanyRequest, CompanyResponse, RequestWithUser, Company, Company] = |
82 |
| -// Endpoint |
83 |
| -// .in[CompanyRequest, RequestWithUser, Company](tracingUserAction()) |
84 |
| -// .logic((companyRequest, rc) => logic(companyRequest, requestContextWithUser(rc))) |
85 |
| -// .mapOutTo[CompanyResponse] |
86 |
| -// |
87 |
| -// def update: Action[CompanyRequest] = |
88 |
| -// UpdateCreateEndpoint((c, r) => companyService.updateCompany(c)(r)) |
89 |
| -// .result(_.completeResultWithoutBody(statusCode = 204)) |
90 |
| -// |
91 |
| -// def create: Action[CompanyRequest] = |
92 |
| -// UpdateCreateEndpoint((c, r) => companyService.createCompany(c)(r)) |
93 |
| -// .result(_.completeResult()) |
94 |
| -// |
95 |
| -// def getAllCompaniesAsSource: Action[AnyContent] = |
96 |
| -// UserInEndpoint |
97 |
| -// .logic[Source[Company, NotUsed]]((_, r) => companyService.getAllCompaniesAsStream()(requestContextWithUser(r))) |
98 |
| -// .mapOutTo[Source[CompanyResponse, NotUsed]] |
99 |
| -// .result(_.completeSourceChunked()) |
| 37 | + override def getCompanyById(companyId: Long): ContextRoute[definition.CompanyResponse] = |
| 38 | + Endpoint.withAuth |
| 39 | + .execute(companyService.getById(CompanyId(companyId))(_)) |
| 40 | + .complete |
100 | 41 |
|
101 |
| - override def getCompanyById(companyId: String): ContextRoute[definition.CompanyResponse] = ??? |
| 42 | + override def getAllCompanies(): ContextRoute[CompaniesResponse] = |
| 43 | + Endpoint.withAuth |
| 44 | + .execute(companyService.getAll()(_)) |
| 45 | + .complete |
102 | 46 |
|
103 |
| - override def getAllCompanies(): ContextRoute[CompaniesResponse] = ??? |
| 47 | + override def createCompany(body: CompanyRequestBody): ContextRoute[CompanyResponse] = Endpoint.withAuth |
| 48 | + .execute(companyService.createCompany(body)(_)) |
| 49 | + .complete |
104 | 50 |
|
105 |
| - override def createCompany( |
106 |
| - id: Option[Long], |
107 |
| - settings: Option[Document], |
108 |
| - stringAttribute1: Option[String], |
109 |
| - stringAttribute2: Option[String], |
110 |
| - longAttribute1: Option[Long], |
111 |
| - booleanAttribute: Option[Boolean] |
112 |
| - ): ContextRoute[definition.CompanyResponse] = ??? |
| 51 | + override def updateCompany(body: CompanyRequestBody): ContextRoute[CompanyResponse] = Endpoint.withAuth |
| 52 | + .execute(companyService.updateCompany(body)(_)) |
| 53 | + .complete |
113 | 54 |
|
114 |
| - override def updateCompany( |
115 |
| - id: Option[Long], |
116 |
| - settings: Option[Document], |
117 |
| - stringAttribute1: Option[String], |
118 |
| - stringAttribute2: Option[String], |
119 |
| - longAttribute1: Option[Long], |
120 |
| - booleanAttribute: Option[Boolean] |
121 |
| - ): ContextRoute[definition.CompanyResponse] = ??? |
| 55 | + override def deleteCompany(companyId: Long): ContextRoute[Unit] = Endpoint.withAuth |
| 56 | + .execute(companyService.deleteCompany(CompanyId(companyId))(_)) |
| 57 | + .complete |
122 | 58 |
|
123 |
| - override def deleteCompany(companyId: String): ContextRoute[Unit] = ??? |
124 | 59 | }
|
0 commit comments