Skip to content

Commit

Permalink
✨ : delete credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
juwit committed Jul 12, 2020
1 parent 5b2ef99 commit ddcb7ce
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/main/client/app/pages/credentials/credentials-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,24 @@
>
<font-awesome-icon icon="edit" />
</b-button>
<b-button
title="Delete this credentials"
variant="danger"
@click="deleteCredentials(credentials)"
>
<font-awesome-icon :icon="['far', 'trash-alt']" />
</b-button>
</template>
</b-card>
</b-card-group>
</div>
</template>

<script>
import { getCredentialsList } from '@/shared/api/credentials-api';
import { getCredentialsList, deleteCredentials } from '@/shared/api/credentials-api';
import { AppProviderHeader } from '@/shared/components';
import { displayConfirmDialog, displayNotification } from '@/shared/services/modal-service';
export default {
name: 'Credentials',
Expand All @@ -55,6 +63,24 @@
async created() {
this.credentialsList = await getCredentialsList();
},
methods: {
async deleteCredentials(credentials) {
const message = 'This will delete the credentials. Continue?';
const confirm = await displayConfirmDialog(this, { title: 'Delete Request', message });
if (confirm) {
try {
await deleteCredentials(credentials);
displayNotification(this, { message: 'Credentials deleted.', variant: 'info' });
const index = this.credentialsList.findIndex((cred) => cred.id === credentials.id);
this.credentialsList.splice(index, 1);
} catch (e) {
displayNotification(this, { message: 'Unable to delete credentials.', variant: 'danger' });
}
}
},
},
};
</script>

Expand All @@ -66,4 +92,10 @@
.card-title {
margin: 0;
}
.card-footer {
display: flex;
justify-content: space-between;
}
</style>
2 changes: 2 additions & 0 deletions src/main/client/app/shared/api/credentials-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const getCredentials = async (credentialsId) => axios.get(`/api/credentia
export const updateCredentials = async (credentials) => axios.put(`/api/credentials/${credentials.id}`, credentials);

export const createCredentials = async (credentials) => axios.post('/api/credentials', credentials);

export const deleteCredentials = async (credentials) => axios.delete(`/api/credentials/${credentials.id}`);
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ public Credentials createCredentials(@RequestBody Credentials credentials){
public Credentials updateCredentials(@RequestBody Credentials credentials, @PathVariable String id){
return this.credentialsRepository.save(credentials);
}

@DeleteMapping("/{id}")
public void deleteCredentials(@PathVariable String id){
this.credentialsRepository.deleteById(id);
}
}

0 comments on commit ddcb7ce

Please sign in to comment.