From 98be364680853f7940c693404e08cb4d1084c2df Mon Sep 17 00:00:00 2001 From: toshski <104477758+toshski@users.noreply.github.com> Date: Mon, 17 Jul 2023 04:43:54 +1200 Subject: [PATCH] feat: Option to Delete Actors without any scenes (#1335) --- pkg/api/actors.go | 23 +++++++++++++++++++++++ ui/src/views/actors/EditActor.vue | 19 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/pkg/api/actors.go b/pkg/api/actors.go index 58ae5f204..e57385bdd 100644 --- a/pkg/api/actors.go +++ b/pkg/api/actors.go @@ -53,6 +53,10 @@ func (i ActorResource) WebService() *restful.WebService { Metadata(restfulspec.KeyOpenAPITags, tags). Writes(models.Actor{})) + ws.Route(ws.DELETE("/delete/{id}").To(i.deleteActor). + Metadata(restfulspec.KeyOpenAPITags, tags). + Writes(models.Actor{})) + ws.Route(ws.POST("/setimage").To(i.setActorImage). Metadata(restfulspec.KeyOpenAPITags, tags). Writes(models.Actor{})) @@ -411,6 +415,25 @@ func (i ActorResource) editActor(req *restful.Request, resp *restful.Response) { resp.WriteHeaderAndEntity(http.StatusOK, actor) } +func (i ActorResource) deleteActor(req *restful.Request, resp *restful.Response) { + id, err := strconv.Atoi(req.PathParameter("id")) + if err != nil { + log.Error(err) + return + } + + var actor models.Actor + db, _ := models.GetDB() + defer db.Close() + + db.Exec(`delete from actor_akas where actor_id=?`, id) + db.Where("actor_id = ?", uint(id)).Delete(&models.ActionActor{}) + db.Where("internal_table = 'actors' and internal_db_id = ?", uint(id)).Delete(&models.ExternalReferenceLink{}) + db.Where("id = ?", uint(id)).Delete(&models.Actor{}) + + resp.WriteHeaderAndEntity(http.StatusOK, actor) +} + func checkStringFieldChanged(field_name string, newValue *string, actorField *string, actorId uint) { if *actorField != *newValue { *actorField = *newValue diff --git a/ui/src/views/actors/EditActor.vue b/ui/src/views/actors/EditActor.vue index c5af27ccf..f30cddfd3 100644 --- a/ui/src/views/actors/EditActor.vue +++ b/ui/src/views/actors/EditActor.vue @@ -110,7 +110,8 @@ @@ -292,6 +293,22 @@ export default { this.$store.state.actorList.isLoading = false this.close() }, + deleteactor () { + this.$buefy.dialog.confirm({ + title: 'Delete actor', + message: `Do you really want to delete ${this.actor.name}`, + type: 'is-info is-wide', + hasIcon: true, + id: 'heh', + onConfirm: () => { + ky.delete(`/api/actor/delete/${this.actor.id}`).json().then(data => { + this.$store.dispatch('actorList/load', { offset: this.$store.state.actorList.offset - this.$store.state.actorList.limit }) + this.$store.commit('overlay/hideActorEditDetails') + this.$store.commit('overlay/hideActorDetails') + }) + } + }) + }, blur (field) { if (this.changesMade) return // Changes have already been made. No point to check any further if (['image_arr', 'tattoos', 'piercings', 'aliases', 'urls'].includes(field)) {