feat: add comments

This commit is contained in:
Krispire Admin
2026-06-13 01:29:55 +05:30
parent 1edee92865
commit 6ebaa36158
11 changed files with 968 additions and 10 deletions
+10 -3
View File
@@ -545,10 +545,11 @@ type ProfileHandler struct {
graph *service.SocialGraphService
likes *repository.LikeRepo
mentions *repository.MentionRepo
comments *repository.CommentRepo
}
func NewProfileHandler(users *repository.UserRepo, posts *repository.PostRepo, collections *repository.CollectionRepo, graph *service.SocialGraphService, likes *repository.LikeRepo, mentions *repository.MentionRepo) *ProfileHandler {
return &ProfileHandler{users: users, posts: posts, collections: collections, graph: graph, likes: likes, mentions: mentions}
func NewProfileHandler(users *repository.UserRepo, posts *repository.PostRepo, collections *repository.CollectionRepo, graph *service.SocialGraphService, likes *repository.LikeRepo, mentions *repository.MentionRepo, comments *repository.CommentRepo) *ProfileHandler {
return &ProfileHandler{users: users, posts: posts, collections: collections, graph: graph, likes: likes, mentions: mentions, comments: comments}
}
func (h *ProfileHandler) Get(w http.ResponseWriter, r *http.Request) {
@@ -700,7 +701,10 @@ func (h *ProfileHandler) hydrateFeed(r *http.Request, posts []model.Post) error
if err := h.likes.Hydrate(r.Context(), viewerID, ptrs); err != nil {
return err
}
return h.mentions.HydrateCounts(r.Context(), ptrs)
if err := h.mentions.HydrateCounts(r.Context(), ptrs); err != nil {
return err
}
return h.comments.HydratePinned(r.Context(), viewerID, ptrs)
}
// followListResp is the payload for the followers / following list endpoints:
@@ -755,10 +759,13 @@ func mapSocialErr(w http.ResponseWriter, err error) {
switch {
case errors.Is(err, repository.ErrUserNotFound),
errors.Is(err, repository.ErrPostNotFound),
errors.Is(err, repository.ErrCommentNotFound),
errors.Is(err, repository.ErrBookmarkNotFound),
errors.Is(err, repository.ErrCollectionNotFound),
errors.Is(err, service.ErrNotFound):
response.Error(w, http.StatusNotFound, "not found")
case errors.Is(err, repository.ErrDuplicateComment):
response.Error(w, http.StatusConflict, "you've already posted this comment")
case errors.Is(err, service.ErrForbidden):
response.Error(w, http.StatusForbidden, "not allowed")
case errors.Is(err, service.ErrBlocked):