Skip to content

Commit

Permalink
sunset endpoitn working
Browse files Browse the repository at this point in the history
  • Loading branch information
coleji committed Dec 3, 2023
1 parent 20cc6a9 commit 82ac24b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
13 changes: 9 additions & 4 deletions app/org/sailcbi/APIServer/Api/Endpoints/Public/Sunset.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package org.sailcbi.APIServer.Api.Endpoints.Public

import com.coleji.neptune.Core.{ParsedRequest, PermissionsAuthority}
import org.sailcbi.APIServer.Entities.EntityDefinitions.SunsetTime
import org.sailcbi.APIServer.Entities.cacheable.sunset.{SunsetCache, SunsetCacheKey}
import org.sailcbi.APIServer.UserTypes.{PublicRequestCache}
import play.api.libs.json.Json
import org.sailcbi.APIServer.UserTypes.PublicRequestCache
import play.api.libs.json.{Json, Writes}
import play.api.mvc.{Action, AnyContent, InjectedController}

import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}

class Sunset @Inject()(implicit val exec: ExecutionContext) extends InjectedController {
def get(year: Int, month: Int)(implicit PA: PermissionsAuthority): Action[AnyContent] = Action.async(req => {
def get(year: Int, month: Int, day: Int)(implicit PA: PermissionsAuthority): Action[AnyContent] = Action.async(req => {
PA.withRequestCache(PublicRequestCache)(None, ParsedRequest(req), rc => {
val (rows, _) = SunsetCache.get(rc, SunsetCacheKey(year, month))
Future(Ok(Json.toJson(rows)))
// implicit val writes: Writes[SunsetTime] = SunsetTime.storableJsonWrites
rows.find(_.values.forDate.get.getDayOfMonth == day) match {
case Some(r) => Future(Ok(Json.toJson(r)))
case None => Future(NotFound)
}
})
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ object SunsetCache extends CacheableFactory[SunsetCacheKey, List[SunsetTime]] {
SunsetTime.fields.forDate.alias.lessThanConstant(LocalDate.of(config.year, config.month, 1).plusMonths(1))
))
.select(List(
SunsetTime.fields.forDate
SunsetTime.fields.forDate,
SunsetTime.fields.twilightStart,
SunsetTime.fields.sunrise,
SunsetTime.fields.sunset,
SunsetTime.fields.twilightEnd,
SunsetTime.fields.dayLengthSeconds,
SunsetTime.fields.sonarNoon,
SunsetTime.fields.nauticalTwilightStart,
SunsetTime.fields.nauticalTwilightEnd,
SunsetTime.fields.astronomicalTwilightStart,
SunsetTime.fields.astronomicalTwilightEnd
))

rc.executeQueryBuilder(qb).map(SunsetTime.construct)
rc.executeQueryBuilder(qb).map(SunsetTime.construct).sortWith((a, b) => a.values.forDate.get.isBefore(b.values.forDate.get))
}
}
2 changes: 1 addition & 1 deletion conf/routes-build/src/01_internet
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ POST /stripe/create-charge-from-token org.sailcbi.APIServer.Api.Endpoints.
GET /stripe/token-details org.sailcbi.APIServer.Api.Endpoints.Stripe.GetTokenDetails.get(token: String)
POST /stripe/sync-db org.sailcbi.APIServer.Api.Endpoints.Stripe.SyncLocalDBWithStripe.post()

GET /sunset org.sailcbi.APIServer.Api.Endpoints.Public.Subset.get(year: Int, month: Int)
GET /sunset org.sailcbi.APIServer.Api.Endpoints.Public.Sunset.get(year: Int, month: Int, day: Int)

GET /efuse/cbidb-public-web org.sailcbi.APIServer.Api.Endpoints.Public.CheckEFusePublicWeb.get()

Expand Down

0 comments on commit 82ac24b

Please sign in to comment.