Implement deletion of users

This commit is contained in:
eikendev 2020-07-27 00:53:32 +02:00
parent 18d11677ac
commit f6ca287d0b
No known key found for this signature in database
GPG key ID: A1BDB1B28C8EF694
10 changed files with 112 additions and 35 deletions

View file

@ -21,7 +21,7 @@ type ApplicationDatabase interface {
// The ApplicationDispatcher interface for relaying notifications.
type ApplicationDispatcher interface {
RegisterApplication(name, user string) (string, error)
DeregisterApplication(matrixID string) error
DeregisterApplication(a *model.Application) error
}
// ApplicationHandler holds information for processing requests about applications.
@ -35,7 +35,7 @@ func (h *ApplicationHandler) applicationExists(token string) bool {
return application != nil
}
// CreateApplication creates a user.
// CreateApplication creates an application.
func (h *ApplicationHandler) CreateApplication(ctx *gin.Context) {
var createApplication model.CreateApplication
@ -66,7 +66,7 @@ func (h *ApplicationHandler) CreateApplication(ctx *gin.Context) {
ctx.JSON(http.StatusOK, &application)
}
// DeleteApplication deletes a user with a certain ID.
// DeleteApplication deletes an application with a certain ID.
func (h *ApplicationHandler) DeleteApplication(ctx *gin.Context) {
var deleteApplication model.DeleteApplication
@ -76,13 +76,13 @@ func (h *ApplicationHandler) DeleteApplication(ctx *gin.Context) {
application, err := h.DB.GetApplicationByID(deleteApplication.ID)
log.Printf("Deleting application %s.\n", application.Name)
if success := successOrAbort(ctx, http.StatusBadRequest, err); !success {
return
}
if success := successOrAbort(ctx, http.StatusInternalServerError, h.Dispatcher.DeregisterApplication(application.MatrixID)); !success {
log.Printf("Deleting application %s.\n", application.Name)
if success := successOrAbort(ctx, http.StatusInternalServerError, h.Dispatcher.DeregisterApplication(application)); !success {
return
}