vendredi 28 juin 2019

If-else expression in slick run, update method scala function

I want to check with if-else statement if the variable newPsInfo.clearedCanLoadSC

is true then i want to make a Timestamp of Today else of some other Date so i tried the

ternary if-else with 
condition? true : false

newPsInfo.clearedCanLoadSc.equals(true) ? 
LocalDate.now() : LocalDate.of(2000,1,1)

but unfortunately doesn't work

First I .filter by _.id then I .map the results by productSettingsTable class to the new updated values of new productSettingsInfo parameter. So my question is can i insert an if - else statement into the .map or .update methods like this:

    newPsInfo.clearedCanLoadSc.equals(true) ? 
    LocalDate.now() : LocalDate.of(2000,1,1))

def update(employer: Employer, newPsInfo: PsInfo): Future[Int] =

    db.run(
      productSettingsQuery.filter(_.employerId === employer.id).map(productSettings =>
        (productSettings.enableSc, productSettings.enableConversion,
          productSettings.enableRefundDays, productSettings.enableOutOfPocketPayment,
          productSettings.clearedCanLoadSc, productSettings.enableL, productSettings.clearedAt)).
     update((newPsInfo.enableSc, newPsInfo.enableConversion,
          newPsInfo.enableRefundDays, newPsInfo.enableOutOfPocketPayment,
          newPsInfo.clearedCanLoadSc, newPsInfo.enableL,newPsInfo.clearedCanLoadSc.equals(true) ? LocalDate.now() : LocalDate.of(2000,1,1)))
    )

The problem is that my if else clause is not working the Intelli j shows errors Cannot resolve symbols ?

So is there a way to insert an if-else-statement into the .map or .update function?

Aucun commentaire:

Enregistrer un commentaire