Files
nahodka-back/src/main/java/com/krylov/refound/controller/UserPostController.java
SlimusMinus ee5fb4e0e0 Posts API: user posts page, 201 on create, userLogin, deprecate old routes
- GET /api/v1/users/{userId}/posts returns Page<PostResponse> (owner sees unpublished)
- POST /api/v1/posts returns 201 with the created PostResponse and Location
- PostResponse.userLogin; userEmail kept with the same value as deprecated
- GET /api/v1/posts/{userId} and /search?city= marked deprecated; search is paged
- CORS exposes Retry-After and Location to the frontend

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 11:50:05 +03:00

33 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.krylov.refound.controller;
import com.krylov.refound.dto.PostResponse;
import com.krylov.refound.service.PostService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
/**
* Объявления пользователя: GET /api/v1/users/{userId}/posts. Публичный —
* владельцу (с токеном) отдаются и неопубликованные (MODERATION, REJECTED).
*/
@Slf4j
@RestController
@RequiredArgsConstructor
public class UserPostController {
private final PostService postService;
@GetMapping("/api/v1/users/{userId:\\d+}/posts")
public Page<PostResponse> getUserPosts(@PathVariable Long userId,
@PageableDefault(size = 20, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) {
log.info("get posts of user {}", userId);
return postService.getPostsByUser(userId, pageable);
}
}