Posts API stage 2: /posts/{id} is one post, drop userEmail and /posts/search
- GET /api/v1/posts/{id} returns a single post (owner-only for unpublished);
/detail/{id} stays as an alias; user posts live at /api/v1/users/{userId}/posts
- POST /api/v1/posts Location points to /api/v1/posts/{id}
- PostResponse.userEmail removed (use userLogin); unused DialogResponse removed
- GET /api/v1/posts/search?city= removed (same filter: GET /api/v1/posts?city=)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -48,9 +48,8 @@ public class PostController {
|
||||
public ResponseEntity<PostResponse> create(@Valid @ModelAttribute PostRequest request, @RequestParam(value = "images", required = false) List<MultipartFile> images) {
|
||||
log.info("create post type={}, title='{}'", request.getType(), request.getTitle());
|
||||
PostResponse created = service.create(request, images);
|
||||
// Одно объявление пока отдаёт /detail/{id}; /posts/{id} поменяет смысл вторым этапом
|
||||
URI location = ServletUriComponentsBuilder.fromCurrentRequest()
|
||||
.path("/detail/{id}").buildAndExpand(created.getId()).toUri();
|
||||
.path("/{id}").buildAndExpand(created.getId()).toUri();
|
||||
return ResponseEntity.created(location).body(created);
|
||||
}
|
||||
|
||||
@@ -78,15 +77,14 @@ public class PostController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Объявления ПОЛЬЗОВАТЕЛЯ с id {@code id} (историческое имя маршрута).
|
||||
* Новый маршрут — GET /api/v1/users/{userId}/posts (постранично). Этот
|
||||
* останется до деплоя фронта, затем /posts/{id} станет одним объявлением.
|
||||
* Одно объявление. Неопубликованное (MODERATION, REJECTED) видит только
|
||||
* владелец, остальным — 404. Объявления пользователя —
|
||||
* GET /api/v1/users/{userId}/posts.
|
||||
*/
|
||||
@Deprecated
|
||||
@GetMapping("/{id:\\d+}")
|
||||
public List<PostResponse> getById(@PathVariable Long id) {
|
||||
log.info("get feed by id {}", id);
|
||||
return service.getPostsByUserId(id);
|
||||
public PostResponse getById(@PathVariable Long id) {
|
||||
log.info("get post by id {}", id);
|
||||
return service.getPostById(id);
|
||||
}
|
||||
|
||||
@PutMapping(value = "/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@@ -111,25 +109,17 @@ public class PostController {
|
||||
return service.updateStatus(id, request.getStatus());
|
||||
}
|
||||
|
||||
/** Устарело: используйте GET /api/v1/posts?city= (лента с тем же фильтром). */
|
||||
@Deprecated
|
||||
@GetMapping("/search")
|
||||
public Page<PostResponse> search(@RequestParam(required = false) String city,
|
||||
@PageableDefault(size = 20, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) {
|
||||
log.info("search posts by city {}", city);
|
||||
return service.searchByCity(city, pageable);
|
||||
}
|
||||
|
||||
@GetMapping("/cities")
|
||||
public List<String> getCities() {
|
||||
log.info("get distinct cities");
|
||||
return service.getCities();
|
||||
}
|
||||
|
||||
/** Прежний адрес одного объявления — алиас GET /api/v1/posts/{id}. */
|
||||
@GetMapping("/detail/{postId}")
|
||||
public PostResponse getPostOnMapById(@PathVariable Long postId) {
|
||||
log.info("get post on map by id {}", postId);
|
||||
return service.getPostOnMapById(postId);
|
||||
public PostResponse getPostDetail(@PathVariable Long postId) {
|
||||
log.info("get post detail {}", postId);
|
||||
return service.getPostById(postId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user