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>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user