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

@@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@Service
public class PostService {
@@ -59,6 +61,13 @@ public class PostService {
return postRepository.findByStatus(PostStatus.PUBLISHED);
}
public List<Post> getRecentPostsByUser(String username, int limit) {
User user = userRepository.findByUsername(username)
.orElseThrow(() -> new IllegalArgumentException("User not found"));
Pageable pageable = PageRequest.of(0, limit);
return postRepository.findByAuthorAndStatusOrderByCreatedAtDesc(user, PostStatus.PUBLISHED, pageable);
}
public List<Post> listPendingPosts() {
return postRepository.findByStatus(PostStatus.PENDING);
}