forked from mtusi2026/mtusi2026lab3
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;
|
package com.vnp.demo.controllers;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.CharacterCodingException;
|
import java.nio.charset.CharacterCodingException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -18,6 +19,8 @@ import com.vnp.demo.BusinessException;
|
|||||||
import com.vnp.demo.dto.SessionResponse;
|
import com.vnp.demo.dto.SessionResponse;
|
||||||
import com.vnp.demo.service.AuthService;
|
import com.vnp.demo.service.AuthService;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/auth/sessions")
|
@RequestMapping("/api/v1/auth/sessions")
|
||||||
public class AuthController {
|
public class AuthController {
|
||||||
@@ -32,8 +35,12 @@ public class AuthController {
|
|||||||
@ResponseStatus(HttpStatus.CREATED)
|
@ResponseStatus(HttpStatus.CREATED)
|
||||||
public SessionResponse login(
|
public SessionResponse login(
|
||||||
@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false)
|
@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
|
if (authorization == null
|
||||||
|| !authorization.startsWith("Basic ")) {
|
|| !authorization.startsWith("Basic ")) {
|
||||||
throw BusinessException.unauthorized();
|
throw BusinessException.unauthorized();
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class ChatService {
|
|||||||
List<User> users = userRepository.findAllById(memberIds);
|
List<User> users = userRepository.findAllById(memberIds);
|
||||||
|
|
||||||
if (users.size() != memberIds.size()) {
|
if (users.size() != memberIds.size()) {
|
||||||
throw BusinessException.notFound();
|
throw BusinessException.invalid("Один или несколько участников не найдены");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создаём чат через конструктор существующей модели.
|
// Создаём чат через конструктор существующей модели.
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ spring:
|
|||||||
default-property-inclusion: always
|
default-property-inclusion: always
|
||||||
deserialization:
|
deserialization:
|
||||||
fail-on-unknown-properties: true
|
fail-on-unknown-properties: true
|
||||||
|
fail-on-trailing-tokens: true
|
||||||
|
mapper:
|
||||||
|
allow-coercion-of-scalars: false
|
||||||
datasource:
|
datasource:
|
||||||
url: ${DB_URL:jdbc:postgresql://localhost:5432/messenger}
|
url: ${DB_URL:jdbc:postgresql://localhost:5432/messenger}
|
||||||
username: ${DB_USERNAME:messenger}
|
username: ${DB_USERNAME:messenger}
|
||||||
|
|||||||
+1
-3
@@ -1,14 +1,12 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
# Переходим в корень проекта.
|
|
||||||
cd "$(dirname "$0")/.."
|
cd "$(dirname "$0")/.."
|
||||||
|
|
||||||
# Переменную передаёт тест failover.
|
|
||||||
: "${TARGET_INSTANCE_ID:?Не задан TARGET_INSTANCE_ID}"
|
: "${TARGET_INSTANCE_ID:?Не задан TARGET_INSTANCE_ID}"
|
||||||
|
|
||||||
compose() {
|
compose() {
|
||||||
docker compose --env-file .env -f compose.yaml "$@"
|
docker compose --env-file .env -f compose.yml "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
containers=$(compose ps --status running -q api)
|
containers=$(compose ps --status running -q api)
|
||||||
|
|||||||
Reference in New Issue
Block a user