Files
nahodka-back/src/main/java/com/krylov/refound/controller/PostClaimController.java
SlimusMinus e02f8cdb6b Add anti-fraud verification questions and scam warnings
- posts can carry up to 3 verification questions (post_verification_questions,
  changelog 026); to contact the author one answers them first
- POST /api/v1/posts/{id}/claim creates a PENDING chat with the answers as a
  CLAIM message; the claimant cannot write or see the phone until the author
  approves via POST /api/v1/chats/{chatId}/verification
- plain first message to such a post and phone reveal return 403
  VERIFICATION_REQUIRED; GET /api/v1/chats/{chatId} exposes the status
- FraudSignals flags prepayment, card data (Luhn) and SMS-code requests in
  messages (MessageDto.fraudSignal); ChatDto.otherUserCreatedAt for new accounts
- claim limits: 5 per day per account, 2 per post per 30 days, 10/h per IP
- docs/anti-fraud.md, tests

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-11 01:04:31 +03:00

40 lines
1.7 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.ChatDto;
import com.krylov.refound.dto.ClaimRequest;
import com.krylov.refound.service.ChatClaimService;
import com.krylov.refound.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
/**
* Ответы на контрольные вопросы объявления: «нашёл вашу вещь» к потере,
* «это моё» к находке. Создаёт чат-заявку с ответами первым сообщением;
* писать дальше и увидеть номер заявитель сможет,
* когда автор объявления подтвердит ответы (POST /api/v1/chats/{chatId}/verification).
*/
@Slf4j
@RestController
@RequestMapping("/api/v1/posts/{id:\\d+}/claim")
@RequiredArgsConstructor
public class PostClaimController {
private final ChatClaimService chatClaimService;
private final UserService userService;
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public ChatDto claim(@PathVariable Long id, @RequestBody ClaimRequest request) {
Long userId = userService.getCurrentUser().getId();
log.info("claim post {} by user {}", id, userId);
return chatClaimService.claim(userId, id, request.answers());
}
}