telegram updated

This commit is contained in:
Devesh S
2026-07-22 14:41:42 +05:30
parent 163e9f93f2
commit b8b62bed66

View File

@@ -5,10 +5,6 @@ import com.rit.portal.entity.CommunityQuestion;
import com.rit.portal.repository.CommunityAnswerRepository;
import com.rit.portal.repository.CommunityQuestionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
@@ -30,25 +26,11 @@ public class CommunityQuestionController {
private final RestTemplate restTemplate = new RestTemplate();
private static final String TELEGRAM_BOT_URL = "http://localhost:8082/send_question";
/** Legacy returns all questions (kept for backwards compatibility) */
@GetMapping
public List<CommunityQuestion> getAllQuestions() {
return questionRepository.findAll();
}
/**
* Paginated returns a Spring Page of questions ordered newest-first.
* Usage: GET /api/questions/paged?page=0&size=5
* Response includes: content[], totalElements, totalPages, number (current page), last (boolean)
*/
@GetMapping("/paged")
public Page<CommunityQuestion> getQuestionsPaged(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "5") int size) {
Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdAt"));
return questionRepository.findAll(pageable);
}
@PostMapping
public CommunityQuestion createQuestion(@RequestBody CommunityQuestion question) {
if (question.getUpvotes() == null) question.setUpvotes(0);