(uri string)
| 251 | } |
| 252 | |
| 253 | // MaybePinned returns a query that only includes pinned statuses if the request contains |
| 254 | // the pinned parameter. |
| 255 | func MaybePinned(r *http.Request) func(db *gorm.DB) *gorm.DB { |
| 256 | return func(db *gorm.DB) *gorm.DB { |
| 257 | if pinned := parseBool(r, "pinned"); pinned { |
| 258 | db = db.Joins("JOIN reactions ON reactions.status_id = statuses.id AND reactions.pinned = true AND reactions.actor_id = statuses.actor_id") |
| 259 | } |
| 260 | return db |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | // PreloadActor preloads all of an Actor's relations and associations. |
| 265 | func PreloadActor(query *gorm.DB) *gorm.DB { |
| 266 | return query.Preload("Attributes") |
| 267 | } |
| 268 | |
| 269 | // parseBool parses a boolean value from a request parameter. |
| 270 | // If the parameter is not present, it returns false. |
| 271 | // If the parameter is present but cannot be parsed, it returns false |
| 272 | func parseBool(r *http.Request, key string) bool { |
| 273 | switch r.URL.Query().Get(key) { |
| 274 | case "true", "1": |
| 275 | return true |
| 276 | default: |
| 277 | return false |
| 278 | } |
no test coverage detected