admin: add clear routes
This commit is contained in:
parent
c6e64d64a3
commit
729a4e3fa0
|
@ -52,7 +52,9 @@ func init() {
|
|||
|
||||
router.GET("/api/users/:userid/domains/:domain", api.ApiHandler(userHandler(domainHandler(getUserDomain))))
|
||||
router.PUT("/api/users/:userid/domains/:domain", api.ApiHandler(userHandler(domainHandler(updateUserDomain))))
|
||||
router.DELETE("/api/users/:userid/domains/:domain", api.ApiHandler(userHandler(domainHandler(deleteUserDomain))))
|
||||
router.DELETE("/api/users/:userid/domains/:domain", api.ApiHandler(userHandler(deleteUserDomain)))
|
||||
|
||||
router.DELETE("/api/domains", api.ApiHandler(clearDomains))
|
||||
}
|
||||
|
||||
func getUserDomains(_ *config.Options, user *happydns.User, _ httprouter.Params, _ io.Reader) api.Response {
|
||||
|
@ -113,6 +115,19 @@ func updateUserDomain(_ *config.Options, domain *happydns.Domain, _ httprouter.P
|
|||
return api.NewAPIResponse(ud, storage.MainStore.UpdateDomain(ud))
|
||||
}
|
||||
|
||||
func deleteUserDomain(_ *config.Options, domain *happydns.Domain, _ httprouter.Params, _ io.Reader) api.Response {
|
||||
return api.NewAPIResponse(true, storage.MainStore.DeleteDomain(domain))
|
||||
func deleteUserDomain(_ *config.Options, user *happydns.User, ps httprouter.Params, _ io.Reader) api.Response {
|
||||
domainid, err := strconv.ParseInt(ps.ByName("domain"), 10, 64)
|
||||
if err != nil {
|
||||
domain, err := storage.MainStore.GetDomainByDN(user, ps.ByName("domain"))
|
||||
if err != nil {
|
||||
return api.NewAPIErrorResponse(http.StatusNotFound, err)
|
||||
} else {
|
||||
domainid = domain.Id
|
||||
}
|
||||
}
|
||||
return api.NewAPIResponse(true, storage.MainStore.DeleteDomain(&happydns.Domain{Id: domainid}))
|
||||
}
|
||||
|
||||
func clearDomains(_ *config.Options, _ httprouter.Params, _ io.Reader) api.Response {
|
||||
return api.NewAPIResponse(true, storage.MainStore.ClearDomains())
|
||||
}
|
||||
|
|
|
@ -52,6 +52,8 @@ func init() {
|
|||
router.GET("/api/users/:userid/sources/:source", api.ApiHandler(userHandler(sourceHandler(getUserSource))))
|
||||
router.PUT("/api/users/:userid/sources/:source", api.ApiHandler(userHandler(sourceHandler(updateUserSource))))
|
||||
router.DELETE("/api/users/:userid/sources/:source", api.ApiHandler(userHandler(sourceHandler(deleteUserSource))))
|
||||
|
||||
router.DELETE("/api/sources", api.ApiHandler(clearSources))
|
||||
}
|
||||
|
||||
func getUserSources(_ *config.Options, user *happydns.User, _ httprouter.Params, _ io.Reader) api.Response {
|
||||
|
@ -101,3 +103,7 @@ func updateUserSource(_ *config.Options, source *happydns.SourceCombined, _ http
|
|||
func deleteUserSource(_ *config.Options, source *happydns.SourceCombined, _ httprouter.Params, _ io.Reader) api.Response {
|
||||
return api.NewAPIResponse(true, storage.MainStore.DeleteSource(&source.SourceType))
|
||||
}
|
||||
|
||||
func clearSources(_ *config.Options, _ httprouter.Params, _ io.Reader) api.Response {
|
||||
return api.NewAPIResponse(true, storage.MainStore.ClearSources())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue