changes
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package main.java.com.vnp.demo.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.cfg.CoercionAction;
|
||||
import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
|
||||
import com.fasterxml.jackson.databind.type.LogicalType;
|
||||
|
||||
@Configuration
|
||||
public class JacksonConfig {
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilderCustomizer strictTextValues() {
|
||||
return builder -> builder.postConfigurer(mapper ->
|
||||
mapper.coercionConfigFor(LogicalType.Textual)
|
||||
.setCoercion(CoercionInputShape.Integer, CoercionAction.Fail)
|
||||
.setCoercion(CoercionInputShape.Float, CoercionAction.Fail)
|
||||
.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.vnp.demo.controllers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -18,6 +19,8 @@ import com.vnp.demo.BusinessException;
|
||||
import com.vnp.demo.dto.SessionResponse;
|
||||
import com.vnp.demo.service.AuthService;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/auth/sessions")
|
||||
public class AuthController {
|
||||
@@ -32,8 +35,12 @@ public class AuthController {
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public SessionResponse login(
|
||||
@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false)
|
||||
String authorization
|
||||
) {
|
||||
String authorization,
|
||||
HttpServletRequest request
|
||||
) throws IOException {
|
||||
if (request.getInputStream().read() != -1) {
|
||||
throw BusinessException.invalid("Тело запроса создания сессии должно быть пустым");
|
||||
}
|
||||
if (authorization == null
|
||||
|| !authorization.startsWith("Basic ")) {
|
||||
throw BusinessException.unauthorized();
|
||||
|
||||
@@ -74,7 +74,7 @@ public class ChatService {
|
||||
List<User> users = userRepository.findAllById(memberIds);
|
||||
|
||||
if (users.size() != memberIds.size()) {
|
||||
throw BusinessException.notFound();
|
||||
throw BusinessException.invalid("Один или несколько участников не найдены");
|
||||
}
|
||||
|
||||
// Создаём чат через конструктор существующей модели.
|
||||
|
||||
@@ -13,6 +13,9 @@ spring:
|
||||
default-property-inclusion: always
|
||||
deserialization:
|
||||
fail-on-unknown-properties: true
|
||||
fail-on-trailing-tokens: true
|
||||
mapper:
|
||||
allow-coercion-of-scalars: false
|
||||
datasource:
|
||||
url: ${DB_URL:jdbc:postgresql://localhost:5432/messenger}
|
||||
username: ${DB_USERNAME:messenger}
|
||||
|
||||
Reference in New Issue
Block a user