fixed show phone number
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package com.krylov.refound.controller;
|
||||
|
||||
import com.krylov.refound.dto.PhoneRevealRequest;
|
||||
import com.krylov.refound.dto.PhoneRevealResponse;
|
||||
import com.krylov.refound.entity.User;
|
||||
import com.krylov.refound.exception.ApiException;
|
||||
import com.krylov.refound.service.UserService;
|
||||
import com.krylov.refound.service.phone.PhoneRevealService;
|
||||
import com.krylov.refound.service.phone.ProofOfWorkService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.CacheControl;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
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.RestController;
|
||||
|
||||
/**
|
||||
* Показ номера автора: сначала задача proof-of-work, затем номер в обмен на
|
||||
* решение. Оба эндпоинта публичные — позвонить можно без регистрации.
|
||||
* IP — {@code request.getRemoteAddr()}, за прокси восстанавливается из
|
||||
* X-Forwarded-For (server.forward-headers-strategy).
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/posts/{id:\\d+}/phone")
|
||||
@RequiredArgsConstructor
|
||||
public class PhoneRevealController {
|
||||
|
||||
private final PhoneRevealService phoneRevealService;
|
||||
private final UserService userService;
|
||||
|
||||
@GetMapping("/challenge")
|
||||
public ResponseEntity<ProofOfWorkService.Challenge> challenge(@PathVariable Long id, HttpServletRequest request) {
|
||||
return ResponseEntity.ok()
|
||||
.cacheControl(CacheControl.noStore())
|
||||
.body(phoneRevealService.challenge(id, request.getRemoteAddr()));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<PhoneRevealResponse> reveal(@PathVariable Long id, @RequestBody PhoneRevealRequest body,
|
||||
HttpServletRequest request) {
|
||||
String phone = phoneRevealService.reveal(id, body.salt(), body.number(), body.signature(),
|
||||
request.getRemoteAddr(), currentUserId());
|
||||
return ResponseEntity.ok()
|
||||
.cacheControl(CacheControl.noStore())
|
||||
.body(new PhoneRevealResponse(phone));
|
||||
}
|
||||
|
||||
/** id пользователя с токеном или null для анонимного запроса. */
|
||||
private Long currentUserId() {
|
||||
try {
|
||||
User user = userService.getCurrentUser();
|
||||
return user == null ? null : user.getId();
|
||||
} catch (ApiException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,11 +90,13 @@ public class PostController {
|
||||
@PutMapping(value = "/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public PostResponse update(@PathVariable Long id, @RequestParam String type, @RequestParam String title, @RequestParam(required = false) String address,
|
||||
@RequestParam(required = false) Double latitude, @RequestParam(required = false) Double longitude, @RequestParam(required = false) String description,
|
||||
@RequestParam(required = false) String category, @RequestParam(required = false) String phone, @RequestParam(required = false) Boolean reward,
|
||||
@RequestParam(required = false) String category, @RequestParam(required = false) String phone,
|
||||
@RequestParam(required = false) Boolean phoneVisible, @RequestParam(required = false) Boolean reward,
|
||||
@RequestParam(required = false) String rewardText,
|
||||
@RequestParam(value = "images", required = false) List<MultipartFile> images, @RequestParam(value = "existingImages", required = false) String existingImagesJson) {
|
||||
log.info("update post {}", id);
|
||||
return service.update(id, type, title, address, latitude, longitude, description, category, phone, reward, rewardText, images, existingImagesJson);
|
||||
return service.update(id, type, title, address, latitude, longitude, description, category, phone, phoneVisible, reward, rewardText, images,
|
||||
existingImagesJson);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
|
||||
Reference in New Issue
Block a user