diff --git a/app/connectors/SecureMessageConnector.scala b/app/connectors/SecureMessageConnector.scala index 96a09fd..f5b1013 100644 --- a/app/connectors/SecureMessageConnector.scala +++ b/app/connectors/SecureMessageConnector.scala @@ -17,7 +17,7 @@ package connectors import controllers.generic.models.{ CustomerEnrolment, Tag } -import models.{ Conversation, ConversationHeader, Count, CustomerMessage, Letter } +import models.{ Conversation, Count, CustomerMessage, Letter, MessageHeader } import play.api.Logging import play.mvc.Http.Status.CREATED import uk.gov.hmrc.http.HttpReads.Implicits._ @@ -34,12 +34,10 @@ class SecureMessageConnector @Inject()(httpClient: HttpClient, servicesConfig: S def getConversationList( enrolmentKeys: Option[List[String]], customerEnrolments: Option[List[CustomerEnrolment]], - tags: Option[List[Tag]])(implicit ec: ExecutionContext, hc: HeaderCarrier): Future[List[ConversationHeader]] = { + tags: Option[List[Tag]])(implicit ec: ExecutionContext, hc: HeaderCarrier): Future[List[MessageHeader]] = { val queryParams = queryParamsBuilder(enrolmentKeys, customerEnrolments, tags) httpClient - .GET[List[ConversationHeader]]( - s"$secureMessageBaseUrl/secure-messaging/conversations", - queryParams.getOrElse(List())) + .GET[List[MessageHeader]](s"$secureMessageBaseUrl/secure-messaging/messages", queryParams.getOrElse(List())) } def getCount( diff --git a/app/controllers/ConversationInboxController.scala b/app/controllers/ConversationInboxController.scala index cb78cb4..77e793f 100644 --- a/app/controllers/ConversationInboxController.scala +++ b/app/controllers/ConversationInboxController.scala @@ -26,8 +26,8 @@ import uk.gov.hmrc.auth.core.{ AuthConnector, AuthorisedFunctions } import uk.gov.hmrc.http.HeaderCarrier import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController import uk.gov.hmrc.play.http.HeaderCarrierConverter -import views.html.partials.conversationInbox -import views.viewmodels.ConversationInbox +import views.html.partials.messageInbox +import views.viewmodels.MessageInbox import javax.inject.{ Inject, Singleton } import scala.concurrent.{ ExecutionContext, Future } @@ -36,7 +36,7 @@ import scala.concurrent.{ ExecutionContext, Future } class ConversationInboxController @Inject()( appConfig: AppConfig, controllerComponents: MessagesControllerComponents, - inbox: conversationInbox, + inbox: messageInbox, secureMessageConnector: SecureMessageConnector, val authConnector: AuthConnector)(implicit ec: ExecutionContext) extends FrontendController(controllerComponents) with I18nSupport with AuthorisedFunctions @@ -59,7 +59,7 @@ class ConversationInboxController @Inject()( Future.successful( Ok( inbox.apply( - ConversationInbox( + MessageInbox( clientService, messages("conversation.inbox.title"), conversations.size, diff --git a/app/models/ConversationHeader.scala b/app/models/MessageHeader.scala similarity index 80% rename from app/models/ConversationHeader.scala rename to app/models/MessageHeader.scala index 90aa95d..60118d2 100644 --- a/app/models/ConversationHeader.scala +++ b/app/models/MessageHeader.scala @@ -21,21 +21,24 @@ 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, +final case class MessageHeader( + messageType: MessageType, + id: String, subject: String, issueDate: DateTime, senderName: Option[String], unreadMessages: Boolean, - count: Int) + count: Int, + conversationId: Option[String], + client: Option[String] +) -object ConversationHeader { +object MessageHeader { 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] + implicit val conversationHeaderReads: OFormat[MessageHeader] = Json.format[MessageHeader] } diff --git a/app/models/MessageType.scala b/app/models/MessageType.scala new file mode 100644 index 0000000..e09e62c --- /dev/null +++ b/app/models/MessageType.scala @@ -0,0 +1,27 @@ +/* + * 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 enumeratum.EnumEntry.{ Lowercase } +import enumeratum.{ Enum, EnumEntry, PlayEnum } + +sealed trait MessageType extends EnumEntry with Lowercase + +object MessageType extends Enum[MessageType] with PlayEnum[MessageType] { + val values = findValues + case object Conversation extends MessageType + case object Letter extends MessageType +} diff --git a/app/views/helpers/HtmlUtil.scala b/app/views/helpers/HtmlUtil.scala index 3c909e7..812a4bc 100644 --- a/app/views/helpers/HtmlUtil.scala +++ b/app/views/helpers/HtmlUtil.scala @@ -17,7 +17,7 @@ package views.helpers import cats.implicits.catsSyntaxEq -import models.{ ConversationHeader, FirstReaderInformation, SenderInformation } +import models.{ FirstReaderInformation, MessageHeader, MessageType, SenderInformation } import org.apache.commons.codec.binary.Base64 import org.joda.time._ import org.joda.time.format.DateTimeFormat @@ -37,19 +37,26 @@ object HtmlUtil { private def dateTimeFormatWithLondonZone(pattern: String) = DateTimeFormat.forPattern(pattern).withZone(DateTimeZone.forID("Europe/London")) - def getSenderName(conversationHeader: ConversationHeader)(implicit messages: Messages): String = + def getSenderName(conversationHeader: MessageHeader)(implicit messages: Messages): String = conversationHeader.senderName match { case Some(name) => name case _ => messages("conversation.inbox.default.sender") } - def getMessageDate(conversationHeader: ConversationHeader): String = + def getMessageDate(conversationHeader: MessageHeader): String = if (conversationHeader.issueDate.toLocalDate.toString === DateTime.now.toLocalDate.toString) { dtfHours.print(conversationHeader.issueDate) + amOrPm.print(conversationHeader.issueDate).toLowerCase } else { dtf.print(conversationHeader.issueDate) } - def getConversationUrl(clientService: String, conversationHeader: ConversationHeader): String = - s"/$clientService/conversation/${conversationHeader.client}/${conversationHeader.conversationId}" + def getMessageUrl(clientService: String, messageHeader: MessageHeader): String = + if (messageHeader.messageType.entryName === MessageType.Conversation.entryName) { + (messageHeader.client, messageHeader.conversationId) match { + case (Some(client), Some(conversationId)) => s"/$clientService/conversation/$client/$conversationId" + case _ => "" + } + } else { + s"/$clientService/messages/${messageHeader.id}" + } def readableTime(dateTime: DateTime): String = conversationDateTimeFormat.print(dateTime) + amOrPm.print(dateTime).toLowerCase diff --git a/app/views/partials/conversationInbox.scala.html b/app/views/partials/messageInbox.scala.html similarity index 91% rename from app/views/partials/conversationInbox.scala.html rename to app/views/partials/messageInbox.scala.html index dc777c3..7fec09c 100644 --- a/app/views/partials/conversationInbox.scala.html +++ b/app/views/partials/messageInbox.scala.html @@ -14,13 +14,13 @@ * limitations under the License. *@ -@import models.ConversationHeader +@import models.MessageHeader @import views.helpers.HtmlUtil._ @import uk.gov.hmrc.urls.Link -@import views.viewmodels.ConversationInbox +@import views.viewmodels.MessageInbox @this() -@(params: ConversationInbox)(implicit messages: Messages) +@(params: MessageInbox)(implicit messages: Messages) @import params._