1 /* 2 * Make.org Core API 3 * Copyright (C) 2020 Make.org 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Affero General Public License for more details. 14 * 15 * You should have received a copy of the GNU Affero General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package org.make.api.technical.graphql 21 22 import cats.Id 23 import org.make.api.user.UserServiceComponent 24 import org.make.core.user.{UserId, UserType} 25 import zio.query.DataSource 26 27 import scala.concurrent.{ExecutionContext, Future} 28 29 trait GraphQLAuthorServiceComponent { 30 def authorDataSource: DataSource[Any, GetAuthor] 31 } 32 33 trait DefaultGraphQLAuthorServiceComponent extends GraphQLAuthorServiceComponent { 34 this: UserServiceComponent => 35 36 override val authorDataSource: DataSource[Any, GetAuthor] = { 37 def findFromIds(userIds: Seq[UserId])(ec: ExecutionContext): Future[Map[UserId, GraphQLAuthor]] = 38 userService 39 .getUsersByUserIds(userIds) 40 .map( 41 _.map( 42 user => 43 user.userId -> GraphQLAuthor( 44 user.userId, 45 user.firstName, 46 user.profile.flatMap(_.avatarUrl), 47 user.userType 48 ) 49 ).toMap 50 )(ec) 51 52 DataSourceHelper.one("user-datasource", findFromIds) 53 } 54 } 55 56 final case class GetAuthor(ids: UserId) extends IdsRequest[Id, UserId, GraphQLAuthor] 57 58 final case class GraphQLAuthor(id: UserId, firstName: Option[String], avatar: Option[String], userType: UserType)
| Line | Stmt Id | Pos | Tree | Symbol | Tests | Code |
|---|---|---|---|---|---|---|
| 50 | 46307 | 1352 - 1684 | Apply | scala.concurrent.Future.map | DefaultGraphQLAuthorServiceComponent.this.userService.getUsersByUserIds(userIds).map[scala.collection.immutable.Map[org.make.core.user.UserId,org.make.api.technical.graphql.GraphQLAuthor]](((x$1: Seq[org.make.core.user.User]) => x$1.map[(org.make.core.user.UserId, org.make.api.technical.graphql.GraphQLAuthor)](((user: org.make.core.user.User) => scala.Predef.ArrowAssoc[org.make.core.user.UserId](user.userId).->[org.make.api.technical.graphql.GraphQLAuthor](GraphQLAuthor.apply(user.userId, user.firstName, user.profile.flatMap[String](((x$2: org.make.core.profile.Profile) => x$2.avatarUrl)), user.userType)))).toMap[org.make.core.user.UserId, org.make.api.technical.graphql.GraphQLAuthor](scala.this.<:<.refl[(org.make.core.user.UserId, org.make.api.technical.graphql.GraphQLAuthor)])))(ec) | |
| 52 | 38733 | 1711 - 1728 | Literal | <nosymbol> | "user-datasource" | |
| 52 | 30905 | 1730 - 1741 | Apply | org.make.api.technical.graphql.DefaultGraphQLAuthorServiceComponent.findFromIds | findFromIds(userIds)(ec) | |
| 52 | 47954 | 1690 - 1742 | Apply | org.make.api.technical.graphql.DataSourceHelper.one | DataSourceHelper.one[org.make.core.user.UserId, org.make.api.technical.graphql.GraphQLAuthor, org.make.api.technical.graphql.GetAuthor]("user-datasource", ((userIds: Seq[org.make.core.user.UserId]) => ((ec: scala.concurrent.ExecutionContext) => findFromIds(userIds)(ec)))) |