(app *App, w http.ResponseWriter, r *http.Request)
| 1013 | } |
| 1014 | |
| 1015 | func dispersePost(app *App, w http.ResponseWriter, r *http.Request) error { |
| 1016 | var ownerID int64 |
| 1017 | |
| 1018 | // Authenticate user |
| 1019 | at := r.Header.Get("Authorization") |
| 1020 | if at != "" { |
| 1021 | ownerID = app.db.GetUserID(at) |
| 1022 | if ownerID == -1 { |
| 1023 | return ErrBadAccessToken |
| 1024 | } |
| 1025 | } else { |
| 1026 | u := getUserSession(app, r) |
| 1027 | if u == nil { |
| 1028 | return ErrNotLoggedIn |
| 1029 | } |
| 1030 | ownerID = u.ID |
| 1031 | } |
| 1032 | |
| 1033 | // Parse posts in format: |
| 1034 | // ["..."] |
| 1035 | var postIDs []string |
| 1036 | decoder := json.NewDecoder(r.Body) |
| 1037 | err := decoder.Decode(&postIDs) |
| 1038 | if err != nil { |
| 1039 | return ErrBadJSONArray |
| 1040 | } |
| 1041 | |
| 1042 | // Update all given posts |
| 1043 | res, err := app.db.DispersePosts(ownerID, postIDs) |
| 1044 | if err != nil { |
| 1045 | return err |
| 1046 | } |
| 1047 | return impart.WriteSuccess(w, res, http.StatusOK) |
| 1048 | } |
| 1049 | |
| 1050 | type ( |
| 1051 | PinPostResult struct { |
nothing calls this directly
no test coverage detected