From 126866e5fa4db4034e9bf35e5cba0a2ac442b8fd Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Sun, 30 Oct 2022 23:28:46 -0700 Subject: [PATCH] adding reporting endpoints required by android --- net/server/internal/api_addFlag.go | 29 +++++++++++++++++++++++++++++ net/server/internal/routers.go | 7 +++++++ net/server/internal/store/schema.go | 8 ++++++++ 3 files changed, 44 insertions(+) create mode 100644 net/server/internal/api_addFlag.go diff --git a/net/server/internal/api_addFlag.go b/net/server/internal/api_addFlag.go new file mode 100644 index 00000000..008b36a2 --- /dev/null +++ b/net/server/internal/api_addFlag.go @@ -0,0 +1,29 @@ +package databag + +import ( + "databag/internal/store" + "github.com/gorilla/mux" + "net/http" +) + +//AddFlag adds a UGC alert for specified account and or content +func AddFlag(w http.ResponseWriter, r *http.Request) { + + params := mux.Vars(r) + guid := params["guid"] + + channel := r.FormValue("channel") + topic := r.FormValue("topic") + + flag := &store.Flag{ + GUID: guid, + ChannelSlotID: channel, + TopicSlotID: topic, + } + if res := store.DB.Save(flag).Error; res != nil { + ErrResponse(w, http.StatusInternalServerError, res) + return + } + + WriteResponse(w, nil) +} diff --git a/net/server/internal/routers.go b/net/server/internal/routers.go index d846a3d2..bfd6a1f6 100644 --- a/net/server/internal/routers.go +++ b/net/server/internal/routers.go @@ -265,6 +265,13 @@ var endpoints = routes{ SetNodeStatus, }, + route{ + "AddFlag", + strings.ToUpper("Post"), + "/account/flag/{guid}", + AddFlag, + }, + route{ "AddGroup", strings.ToUpper("Post"), diff --git a/net/server/internal/store/schema.go b/net/server/internal/store/schema.go index a3ae9dab..2b7ddcec 100644 --- a/net/server/internal/store/schema.go +++ b/net/server/internal/store/schema.go @@ -22,6 +22,7 @@ func AutoMigrate(db *gorm.DB) { db.AutoMigrate(&Asset{}); db.AutoMigrate(&TagSlot{}); db.AutoMigrate(&Tag{}); + db.AutoMigrate(&Flag{}); } type Notification struct { @@ -52,6 +53,13 @@ type AccountToken struct { Account *Account } +type Flag struct { + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + GUID string `gorm:"not null;"` + ChannelSlotID string + TopicSlotID string +} + type Account struct { ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` AccountDetailID uint `gorm:"not null"`