Compare commits
6 Commits
9d8f0a0d83
...
0e6e465fc7
Author | SHA1 | Date | |
---|---|---|---|
0e6e465fc7 | |||
e91208a7d0 | |||
2f4231b5c8 | |||
6aa4fe2f70 | |||
a333537313 | |||
5b8d0ad8d7 |
8
pom.xml
8
pom.xml
@ -2,10 +2,11 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<version>3.3.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
@ -17,7 +18,7 @@
|
||||
<description>Demo project for Swagger</description>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -30,10 +31,11 @@
|
||||
<artifactId>spring-boot-starter-oauth2-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui -->
|
||||
<dependency>
|
||||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<version>2.6.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -2,15 +2,19 @@ package org.sadtech.example.swagger.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import org.sadtech.example.swagger.dto.TypeOperation;
|
||||
import org.sadtech.example.swagger.dto.UserDto;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -33,11 +37,12 @@ public class PointController {
|
||||
}
|
||||
|
||||
@PostMapping("{key}")
|
||||
@ApiResponse(responseCode = "400", description = "Неверный запрос — количество баллов должно быть неотрицательным")
|
||||
@Operation(summary = "Управление баллами", description = "Позволяет удалить или добавить баллы пользователю")
|
||||
public HttpStatus changePoints(
|
||||
@PathVariable @NotBlank @Parameter(description = "Идентификатор пользователя", example = "key1") String key,
|
||||
@RequestParam("point") @Min(0) @Parameter(description = "Количество баллов", required = true, example = "10") Long point,
|
||||
@RequestParam("type") @Parameter(description = "Тип операции", required = true) TypeOperation type
|
||||
@PathVariable @NotBlank @Parameter(description = "Идентификатор пользователя") String key,
|
||||
@RequestParam("point") @Min(0) @Parameter(description = "Количество баллов", required = true, example = "100") Long point,
|
||||
@RequestParam("type") @Parameter(description = "Тип операции", required = true, example = "PLUS") TypeOperation type
|
||||
) {
|
||||
final UserDto userDto = repository.get(key);
|
||||
userDto.setPoints(
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.sadtech.example.swagger.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.ExternalDocumentation;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -23,7 +24,14 @@ import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/user")
|
||||
@Tag(name = "Пользователи", description = "Взаимодействие с пользователями")
|
||||
@Tag(
|
||||
name = "User Controller",
|
||||
description = "Контроллер для управления пользователями",
|
||||
externalDocs = @ExternalDocumentation(
|
||||
description = "Ссылка на общую документацию",
|
||||
url = "https://example.com/docs/user-controller"
|
||||
)
|
||||
)
|
||||
public class UserController {
|
||||
|
||||
private final Map<String, UserDto> repository;
|
||||
@ -49,6 +57,7 @@ public class UserController {
|
||||
return HttpStatus.OK;
|
||||
}
|
||||
|
||||
// http://localhost:8080/api/user/1
|
||||
@SecurityRequirement(name = "jsessionid")
|
||||
@GetMapping(value = "{key}", produces = APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "Получить пользователя")
|
||||
|
@ -10,7 +10,7 @@ spring:
|
||||
registration:
|
||||
mocklab:
|
||||
provider: mocklab
|
||||
client-authentication-method: basic
|
||||
client-authentication-method: client_secret_basic
|
||||
authorization-grant-type: authorization_code
|
||||
scope: profile, email
|
||||
redirect-uri: http://localhost:8080/login/oauth2/code/
|
||||
@ -18,8 +18,8 @@ spring:
|
||||
clientSecret: whatever
|
||||
provider:
|
||||
mocklab:
|
||||
authorization-uri: https://oauth.mocklab.io/oauth/authorize
|
||||
token-uri: https://oauth.mocklab.io/oauth/token
|
||||
user-info-uri: https://oauth.mocklab.io/userinfo
|
||||
authorization-uri: https://oauth.wiremockapi.cloud/oauth/authorize
|
||||
token-uri: https://oauth.wiremockapi.cloud/oauth/token
|
||||
user-info-uri: https://oauth.wiremockapi.cloud/userinfo
|
||||
user-name-attribute: sub
|
||||
jwk-set-uri: https://oauth.mocklab.io/.well-known/jwks.json
|
||||
jwk-set-uri: https://oauth.wiremockapi.cloud/.well-known/jwks.json
|
Loading…
Reference in New Issue
Block a user