Add user content endpoints

This commit is contained in:
Tim
2025-07-01 13:23:04 +08:00
parent 4f34d6926e
commit 0031b825e2
8 changed files with 155 additions and 0 deletions

View File

@@ -10,6 +10,8 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@Service
@RequiredArgsConstructor
@@ -54,4 +56,11 @@ public class CommentService {
.orElseThrow(() -> new IllegalArgumentException("Comment not found"));
return commentRepository.findByParentOrderByCreatedAtAsc(parent);
}
public List<Comment> getRecentCommentsByUser(String username, int limit) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new IllegalArgumentException("User not found"));
Pageable pageable = PageRequest.of(0, limit);
return commentRepository.findByAuthorOrderByCreatedAtDesc(user, pageable);
}
}