Skip to content

Commit

Permalink
feat(admin-ui): refactored handleResponse function across code base #412
Browse files Browse the repository at this point in the history
  • Loading branch information
syntrydy committed Aug 31, 2022
1 parent a23191b commit 0176f02
Show file tree
Hide file tree
Showing 26 changed files with 152 additions and 275 deletions.
6 changes: 4 additions & 2 deletions admin-ui/app/redux/api/FidoApi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class FidoApi {
constructor(api) {
this.api = api
Expand All @@ -6,7 +8,7 @@ export default class FidoApi {
getFidoConfig = () => {
return new Promise((resolve, reject) => {
this.api.getPropertiesFido2((error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -15,7 +17,7 @@ export default class FidoApi {
updateFidoConfig = (input) => {
return new Promise((resolve, reject) => {
this.api.putPropertiesFido2(input, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand Down
8 changes: 3 additions & 5 deletions admin-ui/app/redux/api/HealthApi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class HealthApi {
constructor(api) {
this.api = api
Expand All @@ -6,11 +8,7 @@ export default class HealthApi {
getHealthStatus = () => {
return new Promise((resolve, reject) => {
this.api.getAuthServerHealth((error, data) => {
if (error) {
reject(error)
} else {
resolve(data)
}
handleResponse(error, reject, resolve, data)
})
})
}
Expand Down
18 changes: 6 additions & 12 deletions admin-ui/app/redux/api/InitApi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class InitApi {
constructor(api) {
this.api = api
Expand All @@ -6,40 +8,32 @@ export default class InitApi {
getScopes = (options) => {
return new Promise((resolve, reject) => {
this.api.getOauthScopes(options, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}

getScripts = () => {
return new Promise((resolve, reject) => {
this.api.getConfigScripts((error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}

getAttributes = (options) => {
return new Promise((resolve, reject) => {
this.api.getAttributes(options, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}

getClients = (options) => {
return new Promise((resolve, reject) => {
this.api.getOauthOpenidClients(options, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}

handleResponse(error, reject, resolve, data) {
if (error) {
reject(error)
} else {
resolve(data)
}
}
}
22 changes: 8 additions & 14 deletions admin-ui/app/redux/api/LicenseApi.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class LicenseApi {
constructor(api) {
this.api = api
}
getIsActive = () => {
return new Promise((resolve, reject) => {
this.api.isLicenseActive((error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -15,7 +17,7 @@ export default class LicenseApi {
options['licenseSpringCredentials'] = data.payload
return new Promise((resolve, reject) => {
this.api.saveLicenseApiCredentials(options, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -24,7 +26,7 @@ export default class LicenseApi {
options['licenseApiRequest'] = data.payload
return new Promise((resolve, reject) => {
this.api.activateAdminuiLicense(options, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -34,7 +36,7 @@ export default class LicenseApi {
options['adminPermission'] = data
return new Promise((resolve, reject) => {
this.api.addAdminuiPermission(options, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -44,7 +46,7 @@ export default class LicenseApi {
options['adminPermission'] = data
return new Promise((resolve, reject) => {
this.api.editAdminuiPermission(options, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -54,16 +56,8 @@ export default class LicenseApi {
options['adminPermission'] = data
return new Promise((resolve, reject) => {
this.api.deleteAdminuiPermission(options, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}

handleResponse(error, reject, resolve, data) {
if (error) {
reject(error)
} else {
resolve(data)
}
}
}
14 changes: 4 additions & 10 deletions admin-ui/app/redux/api/LicenseDetailsApi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class LicenseDetailsApi {
constructor(api) {
this.api = api
Expand All @@ -6,7 +8,7 @@ export default class LicenseDetailsApi {
getLicenseDetails = () => {
return new Promise((resolve, reject) => {
this.api.getAdminuiLicense((error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -16,16 +18,8 @@ export default class LicenseDetailsApi {
options['licenseRequest'] = data
return new Promise((resolve, reject) => {
this.api.editAdminuiLicense(options, (error, options) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}

handleResponse(error, reject, resolve, data) {
if (error) {
reject(error)
} else {
resolve(data)
}
}
}
8 changes: 3 additions & 5 deletions admin-ui/app/redux/api/MauApi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class MauApi {
constructor(api) {
this.api = api
Expand All @@ -6,11 +8,7 @@ export default class MauApi {
opts['format'] = 'json'
return new Promise((resolve, reject) => {
this.api.getStat('', opts, (error, data) => {
if (error) {
reject(error)
} else {
resolve(data)
}
handleResponse(error, reject, resolve, data)
})
})
}
Expand Down
8 changes: 3 additions & 5 deletions admin-ui/app/redux/api/OidcDiscoveryApi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class OidcDiscoveryApi {
constructor(api) {
this.api = api
Expand All @@ -7,11 +9,7 @@ export default class OidcDiscoveryApi {
getOidcDiscovery = () => {
return new Promise((resolve, reject) => {
this.api.getProperties((error, data) => {
if (error) {
reject(error)
} else {
resolve(data)
}
handleResponse(error, reject, resolve, data)
})
})
}
Expand Down
12 changes: 3 additions & 9 deletions admin-ui/app/redux/api/UserApi.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class UserApi {
constructor(api) {
this.api = api
Expand All @@ -6,16 +8,8 @@ export default class UserApi {
getUsers = (opts) => {
return new Promise((resolve, reject) => {
this.api.getUser(opts, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}

handleResponse(error, reject, resolve, data) {
if (error) {
reject(error)
} else {
resolve(data)
}
}
}
7 changes: 7 additions & 0 deletions admin-ui/app/utils/ApiUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function handleResponse(error, reject, resolve, data) {
if (error) {
reject(error)
} else {
resolve(data)
}
}
18 changes: 6 additions & 12 deletions admin-ui/plugins/admin/redux/api/MappingApi.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class MappingApi {
constructor(api) {
this.api = api
}
getMappings = () => {
return new Promise((resolve, reject) => {
this.api.getAdminuiRolePermissions((error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -15,7 +17,7 @@ export default class MappingApi {
options['rolePermissionMapping'] = data
return new Promise((resolve, reject) => {
this.api.mapPermissionsToRole(options, (error, options) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -25,7 +27,7 @@ export default class MappingApi {
options['rolePermissionMapping'] = data
return new Promise((resolve, reject) => {
this.api.mapPermissionsToRole(options, (error, options) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -34,16 +36,8 @@ export default class MappingApi {
options['rolePermissionMapping'] = data
return new Promise((resolve, reject) => {
this.api.removeRolePermissionsPermission(options, (error, options) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}

handleResponse(error, reject, resolve, data) {
if (error) {
reject(error)
} else {
resolve(data)
}
}
}
18 changes: 6 additions & 12 deletions admin-ui/plugins/admin/redux/api/PermissionApi.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { handleResponse } from 'Utils/ApiUtils'

export default class PermissionApi {
constructor(api) {
this.api = api
}
getPermissions = () => {
return new Promise((resolve, reject) => {
this.api.getAdminuiPermissions((error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -15,7 +17,7 @@ export default class PermissionApi {
options['adminPermission'] = data
return new Promise((resolve, reject) => {
this.api.addAdminuiPermission(options, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -25,7 +27,7 @@ export default class PermissionApi {
options['adminPermission'] = data
return new Promise((resolve, reject) => {
this.api.editAdminuiPermission(options, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}
Expand All @@ -35,16 +37,8 @@ export default class PermissionApi {
options['adminPermission'] = data
return new Promise((resolve, reject) => {
this.api.deleteAdminuiPermission(options, (error, data) => {
this.handleResponse(error, reject, resolve, data)
handleResponse(error, reject, resolve, data)
})
})
}

handleResponse(error, reject, resolve, data) {
if (error) {
reject(error)
} else {
resolve(data)
}
}
}
Loading

0 comments on commit 0176f02

Please sign in to comment.