add userapp delete operation

This commit is contained in:
Yuli
2020-05-08 11:20:44 +03:00
parent 14c975a787
commit 4eb06097f5
3 changed files with 31 additions and 0 deletions

View File

@@ -211,6 +211,7 @@ func (e mainEnv) setupRouter() *httprouter.Router {
router.POST("/v1/userapp/token/:token/:appname", e.userappNew)
router.GET("/v1/userapp/token/:token/:appname", e.userappGet)
router.PUT("/v1/userapp/token/:token/:appname", e.userappChange)
router.DELETE("/v1/userapp/token/:token/:appname", e.userappDelete)
router.GET("/v1/userapp/token/:token", e.userappList)
router.GET("/v1/userapps", e.appList)

View File

@@ -179,6 +179,31 @@ func (e mainEnv) userappGet(w http.ResponseWriter, r *http.Request, ps httproute
w.Write([]byte(finalJSON))
}
func (e mainEnv) userappDelete(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
userTOKEN := ps.ByName("token")
appName := strings.ToLower(ps.ByName("appname"))
event := auditApp("delete user app record", userTOKEN, appName, "token", userTOKEN)
defer func() { event.submit(e.db) }()
if enforceUUID(w, userTOKEN, event) == false {
return
}
if e.enforceAuth(w, r, event) == "" {
return
}
if isValidApp(appName) == false {
returnError(w, r, "bad appname", 405, nil, event)
return
}
e.db.deleteUserApp(userTOKEN, appName)
finalJSON := fmt.Sprintf(`{"status":"ok","token":"%s"}`, userTOKEN)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)
w.Write([]byte(finalJSON))
}
func (e mainEnv) appList(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Printf("/APPLIST\n")
if e.enforceAuth(w, r, nil) == "" {

View File

@@ -25,6 +25,11 @@ func (dbobj dbcon) getUserApp(userTOKEN string, appName string) ([]byte, error)
return dbobj.userDecrypt(userTOKEN, encData0)
}
func (dbobj dbcon) deleteUserApp(userTOKEN string, appName string) {
appNameFull := "app_" + appName
dbobj.store.DeleteRecordInTable(appNameFull, "token", userTOKEN)
}
func (dbobj dbcon) createAppRecord(jsonData []byte, userTOKEN string, appName string, event *auditEvent) (string, error) {
fmt.Printf("createAppRecord app is : %s\n", appName)
encodedStr, err := dbobj.userEncrypt(userTOKEN, jsonData)