Skip to content

Commit

Permalink
feat #728: Modify validUntil type to String
Browse files Browse the repository at this point in the history
  • Loading branch information
helakaraa committed Sep 12, 2024
1 parent 20dd4bf commit d8e480b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
5 changes: 3 additions & 2 deletions daikoku/app/controllers/ApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ class ApiController(
apiKey = data.apiKey,
plan = data.plan,
createdAt = DateTime.now(),
validUntil = DateTime.now(),
validUntil = None,
team = data.team,
api = data.api,
by = ctx.user.id,
Expand Down Expand Up @@ -1750,7 +1750,8 @@ class ApiController(
customMaxPerDay = (body \ "customMaxPerDay").asOpt[Long],
customMaxPerMonth = (body \ "customMaxPerMonth").asOpt[Long],
customReadOnly = (body \ "customReadOnly").asOpt[Boolean],
adminCustomName = (body \ "adminCustomName").asOpt[String]
adminCustomName = (body \ "adminCustomName").asOpt[String],
validUntil = (body \ "validUntil").asOpt[String],
)
result <-
EitherT(apiService.updateSubscription(ctx.tenant, subToSave, plan))
Expand Down
4 changes: 3 additions & 1 deletion daikoku/app/domain/SchemaDefinition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,9 @@ object SchemaDefinition {
)
),
Field("createdAt", DateTimeUnitype, resolve = _.value.createdAt),
Field("validUntil", DateTimeUnitype, resolve = _.value.validUntil),
Field("validUntil",
OptionType(StringType),
resolve = _.value.validUntil),
Field(
"team",
OptionType(TeamObjectType),
Expand Down
4 changes: 2 additions & 2 deletions daikoku/app/domain/apikeyEntities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ case class ApiSubscription(
apiKey: OtoroshiApiKey, // TODO: add the actual plan at the time of the subscription
plan: UsagePlanId,
createdAt: DateTime,
validUntil: DateTime,
validUntil: Option[String] = None,
team: TeamId,
api: ApiId,
by: UserId,
Expand Down Expand Up @@ -109,7 +109,7 @@ case class ApiSubscription(
"team" -> json.TeamIdFormat.writes(team),
"api" -> json.ApiIdFormat.writes(api),
"createdAt" -> json.DateTimeFormat.writes(createdAt),
"validUntil" -> json.DateTimeFormat.writes(validUntil),
"validUntil" -> validUntil.map(JsString).getOrElse(JsNull).as[JsValue],
"customName" -> customName
.map(id => JsString(id))
.getOrElse(JsNull)
Expand Down
7 changes: 5 additions & 2 deletions daikoku/app/domain/json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2731,7 +2731,7 @@ object json {
team = (json \ "team").as(TeamIdFormat),
api = (json \ "api").as(ApiIdFormat),
createdAt = (json \ "createdAt").as(DateTimeFormat),
validUntil = (json \ "validUntil").as(DateTimeFormat),
validUntil = (json \ "validUntil").asOpt[String],
by = (json \ "by").as(UserIdFormat),
customName = (json \ "customName").asOpt[String],
adminCustomName = (json \ "adminCustomName").asOpt[String],
Expand Down Expand Up @@ -2780,7 +2780,10 @@ object json {
"team" -> TeamIdFormat.writes(o.team),
"api" -> ApiIdFormat.writes(o.api),
"createdAt" -> DateTimeFormat.writes(o.createdAt),
"validUntil"-> DateTimeFormat.writes(o.validUntil),
"validUntil"-> o.validUntil
.map(id => JsString(id))
.getOrElse(JsNull)
.as[JsValue],
"by" -> UserIdFormat.writes(o.by),
"customName" -> o.customName
.map(id => JsString(id))
Expand Down
4 changes: 2 additions & 2 deletions daikoku/app/utils/ApiService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class ApiService(
apiKey = tunedApiKey.asOtoroshiApiKey,
plan = plan.id,
createdAt = DateTime.now(),
validUntil = DateTime.now(),
validUntil = None,
team = team.id,
api = api.id,
by = user.id,
Expand Down Expand Up @@ -360,7 +360,7 @@ class ApiService(
apiKey = OtoroshiApiKey(clientName, clientId, clientSecret),
plan = plan.id,
createdAt = DateTime.now(),
validUntil = DateTime.now(),
validUntil = None,
team = team.id,
api = api.id,
by = user.id,
Expand Down

0 comments on commit d8e480b

Please sign in to comment.