Finished: tag

This commit is contained in:
2021-12-12 15:41:33 +08:00
parent 5a68cea2f3
commit dfc0b43bdd
7 changed files with 66 additions and 9 deletions

View File

@@ -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)

View File

@@ -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
}