Hi,
I have a search form submitted from a web page, where one or more of the search parameters are optional. What is the best way to build a series of conjunctions, against each column, only if a search parameter has been specified for a given column?
case class OpaqueInstruction(id: String,
paymentType: String,
receiveDate : Timestamp,
receiverBic : String,
rawSource : String,
hostSystemId : String,
status : String,
region : String)
class OpaqueInstructionT(tag: Tag) extends Table[OpaqueInstruction](tag, "V_OPAQUE_INSTRUCTION_UI") {
def id = column[String]("OPAQUE_INSTRUCTION_ID", O.PrimaryKey)
def paymentType = column[String]("PAYMENT_TYPE")
def receiveDate = column[Timestamp]("RECEIVE_DATE")
def receiverBic = column[String]("RECEIVER_BIC")
def rawSource = column[String]("RAW_SOURCE")
def hostSystemId = column[String]("HOST_SYSTEM_ID")
def status = column[String]("STATUS")
def region = column[String]("REGION")
def * = (id, paymentType, receiveDate, receiverBic, rawSource, hostSystemId, status, region) <>
(OpaqueInstruction.tupled, OpaqueInstruction.unapply)
}
val opaqueInstructionQ = TableQuery[OpaqueInstructionT]
case class SearchRequest(fromDate : Option[String], toDate : Option[String], hostSystem : Option[String],
status : Option[String], format : Option[String], receiverBic : Option[String])
def search(sr : SearchRequest)(implicit session : Session) = {
// TODO apply predicates
// TODO apply paging
// TODO apply sorting
opaqueInstructionQ filter(_.paymentType === sr.format.get) list
}
I want to apply the filter against each column, only if the option resolves in a value.
Many thanks
Meeraj