Add id's to space urls
This commit is contained in:
parent
e056451737
commit
fcb31bdd10
3 changed files with 73 additions and 38 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gofrs/uuid"
|
||||
"gopkg.in/mgo.v2"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
"log"
|
||||
|
|
@ -95,10 +96,22 @@ func readSpaceurl() []SpaceUrl {
|
|||
result := []SpaceUrl{}
|
||||
c.Find(bson.M{}).Iter().All(&result)
|
||||
|
||||
for _, spaceUrl := range result {
|
||||
if spaceUrl.Id == "" {
|
||||
generatedUuid, err := uuid.NewV4()
|
||||
|
||||
if err != nil {
|
||||
log.Printf("%v", err)
|
||||
}
|
||||
spaceUrl.Id = generatedUuid.String()
|
||||
updateSpaceurl(spaceUrl)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func deleteSpaceurl(url string) {
|
||||
func deleteSpaceurl(id string) error {
|
||||
session, err := mgo.Dial(config.MongoDbServer)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -108,7 +121,13 @@ func deleteSpaceurl(url string) {
|
|||
session.SetMode(mgo.Monotonic, true)
|
||||
|
||||
c := session.DB(config.MongoDbDatabase).C("spaceurl")
|
||||
c.Remove(bson.M{"url": url})
|
||||
err = c.Remove(bson.M{"id": id})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func readCalendar() []Calendar {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/robfig/cron"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
|
|
@ -64,7 +65,15 @@ func SpaceUrlAdd(w http.ResponseWriter, r *http.Request) {
|
|||
spaceUrl := SpaceUrl{}
|
||||
createEntry(&spaceUrl, w, r)
|
||||
spaceUrl.Validated = false
|
||||
|
||||
generatedUuid, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
log.Printf("%v", err)
|
||||
w.WriteHeader(500)
|
||||
} else {
|
||||
spaceUrl.Id = generatedUuid.String()
|
||||
writeSpaceurl(spaceUrl)
|
||||
}
|
||||
}
|
||||
|
||||
func SpaceUrlUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -80,9 +89,16 @@ func SpaceUrlUpdate(w http.ResponseWriter, r *http.Request) {
|
|||
func SpaceUrlDelete(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
SharedSecret := vars["SharedSecret"]
|
||||
Url := vars["url"]
|
||||
Id := vars["id"]
|
||||
if SharedSecret == config.SharedSecret {
|
||||
deleteSpaceurl(Url)
|
||||
err := deleteSpaceurl(Id)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
} else {
|
||||
w.WriteHeader(204)
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(401)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ var IndexRoutes = Routes{
|
|||
Route{
|
||||
"SpaceUrlDelete",
|
||||
"DELETE",
|
||||
"/urls/{url}/{SharedSecret}",
|
||||
"/urls/{id}/{SharedSecret}",
|
||||
SpaceUrlDelete,
|
||||
},
|
||||
Route{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue