Skip to content

Commit

Permalink
Merge pull request #64 from mayorJAY/feat-workflow-overrides
Browse files Browse the repository at this point in the history
Implement Workflow Overrides API
  • Loading branch information
Cliftonz authored Feb 12, 2024
2 parents e96ae8c + c94b516 commit 8744c32
Show file tree
Hide file tree
Showing 9 changed files with 425 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ The client methods map directly to the Novu API endpoints. Here is a list of all
- `fetchMembersOfOrganization()`
- `updateOrganizationBrand(body)`

### Workflow Override

- `createWorkflowOverride(createWorkflowOverrideRequest)`
- `getWorkflowOverrides(getWorkflowOverrideRequest)`
- `getWorkflowOverride(workflowId, tenantId)`
- `getWorkflowOverrideById(overrideId)`
- `updateWorkflowOverride(workflowId, tenantId)`
- `updateWorkflowOverrideById(overrideId)`
- `deleteWorkflowOverride(overrideId)`

### For more information about these methods and their parameters, see the [API documentation](https://docs.novu.co/api-reference/overview).

## Contributing
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/Novu.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.novu

import api.WorkflowOverrideApi
import co.novu.api.BlueprintsApi
import co.novu.api.ChangesApi
import co.novu.api.EnvironmentsApi
Expand Down Expand Up @@ -68,4 +69,6 @@ class Novu(
internal val tenantsApi by lazy { retrofitInstance.create(TenantsApi::class.java) }

internal val organizationsApi by lazy { retrofitInstance.create(OrganizationsApi::class.java) }

internal val workflowOverrideApi by lazy { retrofitInstance.create(WorkflowOverrideApi::class.java) }
}
54 changes: 54 additions & 0 deletions src/main/kotlin/api/WorkflowOverrideApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package api

import co.novu.dto.response.PaginatedResponseWrapper
import co.novu.dto.response.ResponseWrapper
import dto.request.CreateWorkflowOverrideRequest
import dto.workflowoverrides.UpdateWorkflowOverrideRequest
import dto.workflowoverrides.WorkflowOverride
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.QueryMap

interface WorkflowOverrideApi {

companion object {
const val ENDPOINT = "workflow-overrides"
}

@POST(ENDPOINT)
suspend fun createWorkflowOverride(@Body request: CreateWorkflowOverrideRequest): Response<ResponseWrapper<WorkflowOverride>>

@GET(ENDPOINT)
@JvmSuppressWildcards
suspend fun getWorkflowOverrides(@QueryMap params: Map<String, Any>): Response<PaginatedResponseWrapper<WorkflowOverride>>

@GET("$ENDPOINT/workflows/{workflowId}/tenants/{tenantId}")
suspend fun getWorkflowOverride(
@Path("workflowId") workflowId: String,
@Path("tenantId") tenantId: String
): Response<ResponseWrapper<WorkflowOverride>>

@GET("$ENDPOINT/{overrideId}")
suspend fun getWorkflowOverrideById(@Path("overrideId") overrideId: String): Response<ResponseWrapper<WorkflowOverride>>

@PUT("$ENDPOINT/{overrideId}")
suspend fun updateWorkflowOverrideById(
@Path("overrideId") overrideId: String,
@Body request: UpdateWorkflowOverrideRequest
): Response<ResponseWrapper<WorkflowOverride>>

@PUT("$ENDPOINT/workflows/{workflowId}/tenants/{tenantId}")
suspend fun updateWorkflowOverride(
@Path("workflowId") workflowId: String,
@Path("tenantId") tenantId: String,
@Body request: UpdateWorkflowOverrideRequest
): Response<ResponseWrapper<WorkflowOverride>>

@DELETE("$ENDPOINT/{overrideId}")
suspend fun deleteWorkflowOverride(@Path("overrideId") overrideId: String): Response<ResponseWrapper<Boolean>>
}
10 changes: 10 additions & 0 deletions src/main/kotlin/dto/request/CreateWorkflowOverrideRequest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dto.request

import co.novu.dto.PreferenceSettings

data class CreateWorkflowOverrideRequest(
var workflowId: String,
var tenantId: String,
var active: Boolean? = null,
var preferenceSettings: PreferenceSettings? = null
)
6 changes: 6 additions & 0 deletions src/main/kotlin/dto/request/GetWorkflowOverrideRequest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package co.novu.dto.request

data class GetWorkflowOverrideRequest(
var page: Int? = null,
var limit: Int? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dto.workflowoverrides

import co.novu.dto.PreferenceSettings

data class UpdateWorkflowOverrideRequest(
var active: Boolean? = null,
var preferenceSettings: PreferenceSettings? = null
)
24 changes: 24 additions & 0 deletions src/main/kotlin/dto/workflowoverrides/WorkflowOverride.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dto.workflowoverrides

import co.novu.dto.PreferenceSettings
import com.google.gson.annotations.SerializedName

data class WorkflowOverride(
@SerializedName("_id")
var id: String? = null,
@SerializedName("_organizationId")
var organizationId: String? = null,
@SerializedName("_environmentId")
var environmentId: String? = null,
@SerializedName("_workflowId")
var workflowId: String? = null,
@SerializedName("_tenantId")
var tenantId: String? = null,
var active: Boolean? = null,
var preferenceSettings: PreferenceSettings? = null,
var deleted: Boolean? = null,
var deletedAt: String? = null,
var deletedBy: String? = null,
var createdAt: String? = null,
var updatedAt: String? = null
)
51 changes: 51 additions & 0 deletions src/main/kotlin/extensions/WorkflowOverrideExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package co.novu.extensions

import co.novu.Novu
import co.novu.dto.request.GetWorkflowOverrideRequest
import co.novu.dto.response.PaginatedResponseWrapper
import co.novu.dto.response.ResponseWrapper
import co.novu.helpers.extractResponse
import dto.request.CreateWorkflowOverrideRequest
import dto.workflowoverrides.UpdateWorkflowOverrideRequest
import dto.workflowoverrides.WorkflowOverride
import mu.KotlinLogging

private val logger = KotlinLogging.logger {}

suspend fun Novu.createWorkflowOverride(request: CreateWorkflowOverrideRequest): ResponseWrapper<WorkflowOverride>? {
val response = workflowOverrideApi.createWorkflowOverride(request)
return response.extractResponse(logger)
}

suspend fun Novu.getWorkflowOverrides(request: GetWorkflowOverrideRequest): PaginatedResponseWrapper<WorkflowOverride>? {
val params: MutableMap<String, Any> = HashMap()
request.page?.let { params["page"] = it }
request.limit?.let { params["limit"] = it }
val response = workflowOverrideApi.getWorkflowOverrides(params)
return response.extractResponse(logger)
}

suspend fun Novu.getWorkflowOverride(workflowId: String, tenantId: String): ResponseWrapper<WorkflowOverride>? {
val response = workflowOverrideApi.getWorkflowOverride(workflowId, tenantId)
return response.extractResponse(logger)
}

suspend fun Novu.getWorkflowOverrideById(overrideId: String): ResponseWrapper<WorkflowOverride>? {
val response = workflowOverrideApi.getWorkflowOverrideById(overrideId)
return response.extractResponse(logger)
}

suspend fun Novu.updateWorkflowOverrideById(overrideId: String, request: UpdateWorkflowOverrideRequest): ResponseWrapper<WorkflowOverride>? {
val response = workflowOverrideApi.updateWorkflowOverrideById(overrideId, request)
return response.extractResponse(logger)
}

suspend fun Novu.updateWorkflowOverride(workflowId: String, tenantId: String, request: UpdateWorkflowOverrideRequest): ResponseWrapper<WorkflowOverride>? {
val response = workflowOverrideApi.updateWorkflowOverride(workflowId, tenantId, request)
return response.extractResponse(logger)
}

suspend fun Novu.deleteWorkflowOverride(overrideId: String): ResponseWrapper<Boolean>? {
val response = workflowOverrideApi.deleteWorkflowOverride(overrideId)
return response.extractResponse(logger)
}
Loading

0 comments on commit 8744c32

Please sign in to comment.