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:
SlimusMinus
2026-10-20 11:50:05 +03:00
parent ba6935bb1f
commit ee5fb4e0e0
9 changed files with 197 additions and 26 deletions

View File

@@ -54,6 +54,7 @@ public class SecurityConfig {
.requestMatchers(HttpMethod.GET, "/api/v1/files/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/v1/ads-media/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/v1/posts/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/v1/users/*/posts").permitAll()
.requestMatchers(HttpMethod.GET, "/api/v1/reviews/**").permitAll()
.requestMatchers("/ws/**").permitAll() // авторизация чата — на уровне STOMP CONNECT interceptor, см. заметку ниже
@@ -115,6 +116,10 @@ public class SecurityConfig {
config.setAllowedOrigins(origins);
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
config.setAllowedHeaders(List.of("*"));
// Без expose браузер прячет эти заголовки от кросс-доменного фронта:
// Retry-After нужен для сообщения «повторите через N мин» на 429,
// Location — ссылка на созданный ресурс (201 у POST /api/v1/posts)
config.setExposedHeaders(List.of("Retry-After", "Location"));
config.setAllowCredentials(true);
config.setMaxAge(3600L);