| 53 | var following []*models.Relationship |
| 54 | query := env.DB.Joins("JOIN actors ON actors.id = relationships.actor_id and actors.name = ? and actors.domain = ?", chi.URLParam(r, "name"), r.Host) |
| 55 | if err := query.Model(&models.Relationship{}).Preload("Target").Find(&following, "following = true").Error; err != nil { |
| 56 | return err |
| 57 | } |
| 58 | return to.JSON(w, map[string]any{ |
| 59 | "@context": "https://www.w3.org/ns/activitystreams", |
| 60 | "id": fmt.Sprintf("https://%s%s", r.Host, r.URL.Path), |
| 61 | "type": "OrderedCollection", |
| 62 | "totalItems": len(following), |
| 63 | "orderedItems": algorithms.Map( |
| 64 | following, |
| 65 | func(r *models.Relationship) string { |
| 66 | return r.Target.URI |
| 67 | }, |
| 68 | ), |
| 69 | }) |
| 70 | } |
| 71 | |
| 72 | func CollectionsShow(env *Env, w http.ResponseWriter, r *http.Request) error { |
| 73 | var actor models.Actor |
| 74 | if err := env.DB.Take(&actor, "name = ? and domain = ?", chi.URLParam(r, "name"), r.Host).Error; err != nil { |
| 75 | if errors.Is(err, gorm.ErrRecordNotFound) { |
| 76 | return httpx.Error(http.StatusNotFound, err) |