Finished: tag
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type getTagsResponse struct {
|
||||
Tags []database.Tag `json:"tags"`
|
||||
Tags []*database.Tag `json:"tags"`
|
||||
}
|
||||
|
||||
func (api *API) HandleGetTags(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -48,6 +48,12 @@ func (api *API) HandleInsertTag(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
req.CreatedByUserId, err = api.GetUserID(w, r)
|
||||
if err != nil {
|
||||
api.HandleError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
tag, err := api.Db.InsertTag(req)
|
||||
if err != nil {
|
||||
api.HandleError(w, r, err)
|
||||
|
||||
@@ -163,3 +163,13 @@ func (api *API) CheckAdmin(w http.ResponseWriter, r *http.Request) error {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *API) GetUserID(w http.ResponseWriter, r *http.Request) (int64, error) {
|
||||
session, _ := api.store.Get(r, api.defaultSessionName)
|
||||
userId, ok := session.Values["userId"]
|
||||
if !ok {
|
||||
return 0, ErrNotLoggedIn
|
||||
}
|
||||
|
||||
return userId.(int64), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user