mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-05-05 12:22:35 +02:00
Add get followers
This commit is contained in:
parent
b89296c249
commit
e8047c77a0
10 changed files with 162 additions and 17 deletions
42
service/api/helpers/api-helpers.go
Normal file
42
service/api/helpers/api-helpers.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/notherealmarco/WASAPhoto/service/database"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func DecodeJsonOrBadRequest(r io.Reader, w http.ResponseWriter, v interface{}, l logrus.FieldLogger) bool {
|
||||
|
||||
err := json.NewDecoder(r).Decode(v)
|
||||
if err != nil {
|
||||
SendInternalError(err, "Error decoding json", w, l)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func VerifyUserOrNotFound(db database.AppDatabase, uid string, w http.ResponseWriter) bool {
|
||||
|
||||
user_exists, err := db.UserExists(uid)
|
||||
|
||||
if err != nil {
|
||||
SendInternalError(err, "Error verifying user existence", w, nil)
|
||||
return false
|
||||
}
|
||||
|
||||
if !user_exists {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func SendInternalError(err error, description string, w http.ResponseWriter, l logrus.FieldLogger) {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
l.WithError(err).Error(description)
|
||||
w.Write([]byte(description)) // todo: maybe in json. But it's not important to send the full error to the client
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue