Skip to content

Commit

Permalink
Merge pull request #10 from hmrc/DC-2845
Browse files Browse the repository at this point in the history
DC-2845: creating conversation inbox partial
  • Loading branch information
rwalpole authored Feb 11, 2021
2 parents 5a0ac6d + cb0d9b1 commit 02b6ac0
Show file tree
Hide file tree
Showing 56 changed files with 964 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package uk.gov.hmrc.securemessagefrontend.config
package config

import javax.inject.{ Inject, Singleton }
import play.api.i18n.Lang
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* limitations under the License.
*/

package uk.gov.hmrc.securemessagefrontend.config
package config

import javax.inject.{ Inject, Singleton }

import play.api.i18n.MessagesApi
import play.api.mvc.Request
import play.twirl.api.Html
import uk.gov.hmrc.play.bootstrap.frontend.http.FrontendErrorHandler
import uk.gov.hmrc.securemessagefrontend.views.html.ErrorTemplate
import views.html.ErrorTemplate

@Singleton
class ErrorHandler @Inject()(errorTemplate: ErrorTemplate, val messagesApi: MessagesApi)(implicit appConfig: AppConfig)
Expand Down
35 changes: 35 additions & 0 deletions app/connectors/SecureMessageConnector.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package connectors

import javax.inject.Inject
import models.ConversationHeader
import uk.gov.hmrc.http.HttpReads.Implicits._
import uk.gov.hmrc.http.{ HeaderCarrier, HttpClient }
import uk.gov.hmrc.play.bootstrap.config.ServicesConfig

import scala.concurrent.{ ExecutionContext, Future }

class SecureMessageConnector @Inject()(httpClient: HttpClient, servicesConfig: ServicesConfig) {

private val secureMessageBaseUrl = servicesConfig.baseUrl("secure-message")

def getConversationList()(implicit ec: ExecutionContext, hc: HeaderCarrier): Future[List[ConversationHeader]] =
httpClient.GET[List[ConversationHeader]](
s"$secureMessageBaseUrl/secure-messaging/conversations/HMRC-CUS-ORG/EORINumber")

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
* limitations under the License.
*/

package uk.gov.hmrc.securemessagefrontend.controllers
package controllers

import cats.implicits.catsSyntaxEq
import com.google.inject.Inject
import play.api.i18n.I18nSupport
import play.api.mvc.{ Action, AnyContent, MessagesControllerComponents, Request }
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
import uk.gov.hmrc.securemessagefrontend.models.FakeData
import uk.gov.hmrc.securemessagefrontend.views.html.partials.{ message, messageContent }
import views.html.partials.{ message, messageContent }
import javax.inject.Singleton
import models.FakeData

@Singleton
class MessagesController @Inject()(
class ConversationController @Inject()(
controllerComponents: MessagesControllerComponents,
messageContent: messageContent,
message: message)
Expand Down
62 changes: 62 additions & 0 deletions app/controllers/ConversationInboxController.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2021 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package controllers

import play.api.i18n.I18nSupport
import play.api.mvc.{ MessagesControllerComponents, _ }
import uk.gov.hmrc.auth.core.{ AuthConnector, AuthorisedFunctions }
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
import config.AppConfig

import scala.concurrent.{ ExecutionContext, Future }
import views.html.partials.conversationInbox
import javax.inject.{ Inject, Singleton }
import play.api.Logger
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.play.http.HeaderCarrierConverter
import connectors.SecureMessageConnector
import views.viewmodels.ConversationInbox

@Singleton
class ConversationInboxController @Inject()(
appConfig: AppConfig,
controllerComponents: MessagesControllerComponents,
inbox: conversationInbox,
secureMessageConnector: SecureMessageConnector,
val authConnector: AuthConnector)(implicit ec: ExecutionContext)
extends FrontendController(controllerComponents) with I18nSupport with AuthorisedFunctions {

private val logger = Logger(getClass)

implicit val config: AppConfig = appConfig

def display(clientService: String, apiFilters: Option[List[String]]): Action[AnyContent] = Action.async {
implicit request =>
implicit val hc: HeaderCarrier = HeaderCarrierConverter.fromRequest(request)
val apiFilterValues = apiFilters.getOrElse(List("NONE")).mkString("&apiFilter=")
// FIXME the logging is just to keep the compiler happy until the filters are implemented
logger.info(s"apiFilter=$apiFilterValues")
authorised() {
secureMessageConnector.getConversationList().flatMap { conversations =>
val messages = this.messagesApi.preferred(request)
Future.successful(
Ok(inbox.apply(ConversationInbox(clientService, messages("conversation.inbox.title"), conversations))))
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

package uk.gov.hmrc.securemessagefrontend.controllers
package controllers

import com.google.inject.Inject
import javax.inject.Singleton
import play.api.i18n.Lang
import play.api.mvc._
import uk.gov.hmrc.securemessagefrontend.config.AppConfig
import uk.gov.hmrc.securemessagefrontend.models.Language
import config.AppConfig
import models.Language
import uk.gov.hmrc.play.language.{ LanguageController, LanguageUtils }

@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

package uk.gov.hmrc.securemessagefrontend.controllers.swagger
package controllers.swagger

import com.iheart.playSwagger.PrefixDomainModelQualifier
import javax.inject.{ Inject, Singleton }
import play.api.libs.json.Json
import play.api.mvc._
import uk.gov.hmrc.BuildInfo
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController

@Singleton
Expand All @@ -28,12 +28,8 @@ class ApiSpecsController @Inject()(
) extends FrontendController(mcc) {

implicit val cl: ClassLoader = getClass.getClassLoader
val domainPackage = "uk.gov.hmrc.securemessagefrontend"
lazy val generator =
com.iheart.playSwagger.SwaggerSpecGenerator(
swaggerV3 = true,
modelQualifier = PrefixDomainModelQualifier(domainPackage),
apiVersion = Some(uk.gov.hmrc.securemessagefrontend.BuildInfo.version))
com.iheart.playSwagger.SwaggerSpecGenerator(swaggerV3 = true, apiVersion = Some(BuildInfo.version))

lazy val swagger = Action { _ =>
generator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package uk.gov.hmrc.securemessagefrontend.models
package models

final case class Conversation(id: String, url: String, topic: String, mrn: String, date: String)

Expand Down
41 changes: 41 additions & 0 deletions app/models/ConversationHeader.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2021 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package models

import org.joda.time.DateTime
import play.api.libs.json.JodaReads.jodaDateReads
import play.api.libs.json.JodaWrites.jodaDateWrites
import play.api.libs.json.{ Format, Json, OFormat }

final case class ConversationHeader(
client: String,
conversationId: String,
subject: String,
issueDate: DateTime,
senderName: Option[String],
unreadMessages: Boolean,
count: Int)

object ConversationHeader {

private val dateFormatString = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"

implicit val dateFormat: Format[DateTime] = Format(jodaDateReads(dateFormatString), jodaDateWrites(dateFormatString))

implicit val conversationHeaderReads: OFormat[ConversationHeader] = Json.format[ConversationHeader]

}
2 changes: 1 addition & 1 deletion app/models/Language.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package uk.gov.hmrc.securemessagefrontend.models
package models

import play.api.i18n.Lang
import play.api.mvc.PathBindable
Expand Down
2 changes: 1 addition & 1 deletion app/models/WithName.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package uk.gov.hmrc.securemessagefrontend.models
package models

class WithName(string: String) {
override val toString: String = string
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*@

@import uk.gov.hmrc.securemessagefrontend.config.AppConfig
@import config.AppConfig

@this(layout: Layout)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*@

@import uk.gov.hmrc.securemessagefrontend.controllers.routes.LanguageSwitchController._
@import uk.gov.hmrc.securemessagefrontend.config.AppConfig
@import uk.gov.hmrc.securemessagefrontend.models.Language
@import controllers.routes.LanguageSwitchController._
@import config.AppConfig
@import models.Language
@import uk.gov.hmrc.hmrcfrontend.views.html.components.HmrcLanguageSelect
@import uk.gov.hmrc.hmrcfrontend.views.viewmodels.language.LanguageSelect

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*@

@import uk.gov.hmrc.securemessagefrontend.config.AppConfig
@import config.AppConfig
@import uk.gov.hmrc.govukfrontend.views.Layouts
@import uk.gov.hmrc.hmrcfrontend.views.html.components.{Header, HmrcHeader}

Expand Down
Loading

0 comments on commit 02b6ac0

Please sign in to comment.