[ADD] Add abandon import api

This commit is contained in:
zhoujunhao 2018-09-12 11:42:10 +08:00
parent aef25533e4
commit 8462f33ece
2 changed files with 24 additions and 0 deletions

View File

@ -243,6 +243,7 @@ func (v2 *V2) appRouter() chi.Router {
r.Post("/import", controller.GetManager().ImportApp)
r.Get("/import/{eventId}", controller.GetManager().ImportApp)
r.Delete("/import/{eventId}", controller.GetManager().ImportApp)
return r
}

View File

@ -219,6 +219,29 @@ func (a *AppStruct) ImportApp(w http.ResponseWriter, r *http.Request) {
}
httputil.ReturnSuccess(r, w, res)
case "DELETE":
eventId := strings.TrimSpace(chi.URLParam(r, "eventId"))
if eventId == "" {
httputil.ReturnError(r, w, 501, fmt.Sprintf("Arguments eventId is must defined."))
return
}
res, err := db.GetManager().AppDao().GetByEventId(eventId)
if err != nil {
httputil.ReturnError(r, w, 502, fmt.Sprintf("Failed to query status of export app by event id %s: %v", eventId, err))
return
}
if err := db.GetManager().AppDao().DeleteModelByEventId(res.EventID);err!=nil{
httputil.ReturnError(r, w, 503, fmt.Sprintf("Deleting database records by event ID failed %s: %v", eventId, err))
return
}
if _, err := os.Stat(res.SourceDir); err == nil {
if err := os.RemoveAll(res.SourceDir);err != nil{
httputil.ReturnError(r, w, 504, fmt.Sprintf("Deleting uploading application directory failed %s : %v", res.SourceDir, err))
return
}
}
httputil.ReturnSuccess(r, w, "successfully deleted")
}
}