From 41c317584aee8ac7be93d3e24400dd0503f78ffd Mon Sep 17 00:00:00 2001 From: Alsaev Dmitry <dima101203@gmail.com> Date: Wed, 12 Mar 2025 19:28:48 +0700 Subject: [PATCH 1/4] fix: postgresql port changed --- docker-compose.yaml | 24 +++++++++++------------ src/main/resources/application.properties | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 1f3d414..b272e7a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,15 +1,15 @@ services: - app: - image: 'docker-spring-boot-postgres:latest' - build: - context: . - container_name: app - depends_on: - - db - ports: - - '8080:8080' - environment: - - 'DB_HOST=db' +# app: +# image: 'docker-spring-boot-postgres:latest' +# build: +# context: . +# container_name: app +# depends_on: +# - db +# ports: +# - '8080:8080' +# environment: +# - 'DB_HOST=db' db: image: 'postgres:latest' environment: @@ -17,4 +17,4 @@ services: - 'POSTGRES_PASSWORD=secret' - 'POSTGRES_USER=myuser' ports: - - '5432:5432' \ No newline at end of file + - '5433:5432' \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f7d721b..41e1d42 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,7 +5,7 @@ spring.flyway.baseline-on-migrate=true spring.flyway.out-of-order=true -spring.datasource.url=jdbc:postgresql://localhost:5432/mydatabase +spring.datasource.url=jdbc:postgresql://localhost:5433/mydatabase spring.datasource.username=myuser spring.datasource.password=secret spring.datasource.driver-class-name=org.postgresql.Driver -- GitLab From 64446eb6f7d78080c355a50512e5f9885f989c75 Mon Sep 17 00:00:00 2001 From: Alsaev Dmitry <dima101203@gmail.com> Date: Wed, 12 Mar 2025 20:09:38 +0700 Subject: [PATCH 2/4] feat: create application structure --- .../geekzone/api/controller/Controller.java | 4 ++++ .../example/geekzone/api/dto/DtoSimple.java | 4 ++++ .../example/geekzone/api/mapper/Mapper.java | 4 ++++ .../example/geekzone/core/model/Model.java | 22 +++++++++++++++++++ .../geekzone/core/repository/Repository.java | 4 ++++ .../geekzone/core/service/Service.java | 4 ++++ .../{V001__init.sql => V1__init.sql} | 0 .../resources/db/migration/V2__testModel.sql | 6 +++++ 8 files changed, 48 insertions(+) create mode 100644 src/main/java/com/example/geekzone/api/controller/Controller.java create mode 100644 src/main/java/com/example/geekzone/api/dto/DtoSimple.java create mode 100644 src/main/java/com/example/geekzone/api/mapper/Mapper.java create mode 100644 src/main/java/com/example/geekzone/core/model/Model.java create mode 100644 src/main/java/com/example/geekzone/core/repository/Repository.java create mode 100644 src/main/java/com/example/geekzone/core/service/Service.java rename src/main/resources/db/migration/{V001__init.sql => V1__init.sql} (100%) create mode 100644 src/main/resources/db/migration/V2__testModel.sql diff --git a/src/main/java/com/example/geekzone/api/controller/Controller.java b/src/main/java/com/example/geekzone/api/controller/Controller.java new file mode 100644 index 0000000..3f7d38b --- /dev/null +++ b/src/main/java/com/example/geekzone/api/controller/Controller.java @@ -0,0 +1,4 @@ +package com.example.geekzone.api.controller; + +public class Controller { +} diff --git a/src/main/java/com/example/geekzone/api/dto/DtoSimple.java b/src/main/java/com/example/geekzone/api/dto/DtoSimple.java new file mode 100644 index 0000000..0e81954 --- /dev/null +++ b/src/main/java/com/example/geekzone/api/dto/DtoSimple.java @@ -0,0 +1,4 @@ +package com.example.geekzone.api.dto; + +public class DtoSimple { +} diff --git a/src/main/java/com/example/geekzone/api/mapper/Mapper.java b/src/main/java/com/example/geekzone/api/mapper/Mapper.java new file mode 100644 index 0000000..900efb9 --- /dev/null +++ b/src/main/java/com/example/geekzone/api/mapper/Mapper.java @@ -0,0 +1,4 @@ +package com.example.geekzone.api.mapper; + +public class Mapper { +} diff --git a/src/main/java/com/example/geekzone/core/model/Model.java b/src/main/java/com/example/geekzone/core/model/Model.java new file mode 100644 index 0000000..ef7b945 --- /dev/null +++ b/src/main/java/com/example/geekzone/core/model/Model.java @@ -0,0 +1,22 @@ +package com.example.geekzone.core.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.*; + +@Entity +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class Model { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + private String lastName; + +} diff --git a/src/main/java/com/example/geekzone/core/repository/Repository.java b/src/main/java/com/example/geekzone/core/repository/Repository.java new file mode 100644 index 0000000..8a8edf5 --- /dev/null +++ b/src/main/java/com/example/geekzone/core/repository/Repository.java @@ -0,0 +1,4 @@ +package com.example.geekzone.core.repository; + +public class Repository { +} diff --git a/src/main/java/com/example/geekzone/core/service/Service.java b/src/main/java/com/example/geekzone/core/service/Service.java new file mode 100644 index 0000000..d4bc7b9 --- /dev/null +++ b/src/main/java/com/example/geekzone/core/service/Service.java @@ -0,0 +1,4 @@ +package com.example.geekzone.core.service; + +public class Service { +} diff --git a/src/main/resources/db/migration/V001__init.sql b/src/main/resources/db/migration/V1__init.sql similarity index 100% rename from src/main/resources/db/migration/V001__init.sql rename to src/main/resources/db/migration/V1__init.sql diff --git a/src/main/resources/db/migration/V2__testModel.sql b/src/main/resources/db/migration/V2__testModel.sql new file mode 100644 index 0000000..717b77f --- /dev/null +++ b/src/main/resources/db/migration/V2__testModel.sql @@ -0,0 +1,6 @@ +CREATE TABLE model ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, + name VARCHAR(255), + last_name VARCHAR(255), + CONSTRAINT pk_model PRIMARY KEY (id) +); \ No newline at end of file -- GitLab From b4d33c32e16bc860f094de0bc49e3c91b1230808 Mon Sep 17 00:00:00 2001 From: Alsaev Dmitry <dima101203@gmail.com> Date: Wed, 12 Mar 2025 20:15:24 +0700 Subject: [PATCH 3/4] feat: add controller --- .../java/com/example/geekzone/api/controller/Controller.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/example/geekzone/api/controller/Controller.java b/src/main/java/com/example/geekzone/api/controller/Controller.java index 3f7d38b..2a04275 100644 --- a/src/main/java/com/example/geekzone/api/controller/Controller.java +++ b/src/main/java/com/example/geekzone/api/controller/Controller.java @@ -1,4 +1,7 @@ package com.example.geekzone.api.controller; +import org.springframework.web.bind.annotation.RestController; + +@RestController public class Controller { } -- GitLab From b393019c4845b05d71f644a6b778f80b46abb350 Mon Sep 17 00:00:00 2001 From: Alsaev Dmitry <dima101203@gmail.com> Date: Sat, 15 Mar 2025 15:38:51 +0700 Subject: [PATCH 4/4] doc: swagger --- .gitignore | 2 + api/api.yaml | 637 ++++++++++++++++++ .../resources/db/migration/V2__testModel.sql | 6 - 3 files changed, 639 insertions(+), 6 deletions(-) create mode 100644 api/api.yaml delete mode 100644 src/main/resources/db/migration/V2__testModel.sql diff --git a/.gitignore b/.gitignore index c2065bc..e04e1d5 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ build/ !**/src/main/**/build/ !**/src/test/**/build/ +amplicode.xml + ### STS ### .apt_generated .classpath diff --git a/api/api.yaml b/api/api.yaml new file mode 100644 index 0000000..330a0ff --- /dev/null +++ b/api/api.yaml @@ -0,0 +1,637 @@ +openapi: 3.0.0 +info: + title: Проект "Hive" + version: "0.1" +servers: + - url: http://localhost:8080 + description: Локальный сервер +paths: + + /api/users/signUp: + post: + summary: Зарегистрироваться + tags: + - Пользователи + operationId: signUp + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/User" + responses: + "200": + description: Успешный ответ СЃ идентификатором пользователя + content: + application/json: + schema: + type: object + properties: + token: + type: string + example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.a4AaLWElNeHKGRFoe--t9ovMvdu5KLyxLBoAAdCtQUU + "400": + description: Ошибки + content: + application/json: + schema: + type: object + properties: + error: + type: string + example: "BAD_REQUEST" + + + /api/users/signIn: + post: + summary: Авторизоваться + tags: + - Пользователи + operationId: signIn + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + login: + type: string + example: Bogdan + password: + type: string + example: "somePassword123" + responses: + "200": + description: Успешный ответ СЃ идентификатором пользователя + content: + application/json: + schema: + type: object + properties: + token: + type: string + example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.a4AaLWElNeHKGRFoe--t9ovMvdu5KLyxLBoAAdCtQUU + "400": + description: Ошибки + content: + application/json: + schema: + type: object + properties: + error: + type: string + example: "BAD_REQUEST" + + /api/users/logout: + post: + summary: Выйти РёР· аккаунта + tags: + - Пользователи + operationId: logout + requestBody: + required: true + content: + application/json: + schema: + type: object + # properties: + # login: + # type: string + # example: Bogdan + # password: + # type: string + # example: "somePassword123" + responses: + "200": + description: Успешный ответ СЃ идентификатором пользователя + content: + application/json: + schema: + type: object + properties: + token: + type: string + example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.a4AaLWElNeHKGRFoe--t9ovMvdu5KLyxLBoAAdCtQUU + "400": + description: Ошибки + content: + application/json: + schema: + type: object + properties: + error: + type: string + example: "BAD_REQUEST" + + + /users/{userId}: + get: + summary: Получить пользователя РїРѕ идентификатору + tags: + - Пользователи + operationId: getUserById + parameters: + - name: userId + in: path + required: true + description: Рдентификатор пользователя + schema: + type: string + example: 111 + - name: Authorization + in: header + required: true + description: Рдентификатор сессии + schema: + type: string + example: 2527d786-d0d7-47d9-872b-af295552103b + responses: + "200": + description: Успешный ответ СЃ пользователем + content: + application/json: + schema: + $ref: "#/components/schemas/UserInfo" + "default": + description: Ошибки + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + patch: + summary: Обновить пользователя + tags: + - Пользователи + operationId: updateUser + parameters: + - name: userId + in: path + required: true + description: Рдентификатор пользователя + schema: + type: string + example: 111 + - name: Authorization + in: header + required: true + description: Рдентификатор сессии + schema: + type: string + example: 2527d786-d0d7-47d9-872b-af295552103b + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + lastName: + type: string + example: Богданов + description: Только Р±СѓРєРІС‹ СЂСѓСЃСЃРєРѕРіРѕ алфавита. Первая Р±СѓРєРІР° - заглавная. РќРµ более 50 символов. + firstName: + type: string + example: Богдан + description: Только Р±СѓРєРІС‹ СЂСѓСЃСЃРєРѕРіРѕ алфавита. Первая Р±СѓРєРІР° - заглавная. РќРµ более 50 символов. + middleName: + type: string + example: Богданович + description: Только Р±СѓРєРІС‹ СЂСѓСЃСЃРєРѕРіРѕ алфавита. Первая Р±СѓРєРІР° - заглавная. РќРµ более 50 символов. + birthdate: + type: string + format: date + example: "2000-01-01" + description: Дата рождения РІ формате ISO 8601 (YYYY-MM-DD) + responses: + "200": + description: Успешный ответ + "default": + description: Ошибки + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + + /wallets/{userId}: + get: + summary: Получить информацию Рѕ кошельке + tags: + - Кошелёк + operationId: getWalletByUserId + parameters: + - name: userId + in: path + required: true + description: Рдентификатор пользователя + schema: + type: string + example: 123 + - name: Authorization + in: header + required: true + description: Рдентификатор сессии + schema: + type: string + example: 2527d786-d0d7-47d9-872b-af295552103b + responses: + "200": + description: Успешный ответ СЃ кошельком + content: + application/json: + schema: + $ref: "#/components/schemas/Wallet" + "default": + description: Ошибки + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /wallets/{userId}/HESOYAM: + post: + summary: HESOYAM (25% шанс РЅР° деньги) + tags: + - Кошелёк + operationId: HESOYAM + parameters: + - name: userId + in: path + required: true + description: Рдентификатор пользователя + schema: + type: string + example: 123 + - name: Authorization + in: header + required: true + description: Рдентификатор сессии + schema: + type: string + example: 2527d786-d0d7-47d9-872b-af295552103b + responses: + "200": + description: Успешный ответ + "default": + description: Ошибки + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /transfers: + post: + summary: Создать Рё выполнить перевод + tags: + - Денежные переводы + operationId: createTransfer + parameters: + - name: Authorization + in: header + required: true + description: Рдентификатор сессии + schema: + type: string + example: 2527d786-d0d7-47d9-872b-af295552103b + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + walletId: + type: integer + example: 123 + description: Номер кошелька + amount: + type: integer + example: 1000 + description: РЎСѓРјРјР° денежных единиц операции + responses: + "200": + description: Успешный ответ СЃ информацией Рѕ переводе + content: + application/json: + schema: + $ref: "#/components/schemas/Transfer" + "default": + description: Ошибки + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + get: + summary: Получить информацию Рѕ всех переводах РїРѕ фильтрам + tags: + - Денежные переводы + operationId: getTransfers + parameters: + - name: Authorization + in: header + required: true + description: Рдентификатор сессии + schema: + type: string + example: 2527d786-d0d7-47d9-872b-af295552103b + - name: transferType + in: query + required: true + description: РўРёРї перевода (входящие/исходящие) + schema: + type: string + enum: + - in + - out + - name: active + in: query + required: true + description: Статус перевода (оплачен/РЅРµ оплачен) + schema: + type: string + enum: + - paid + - unpaid + - name: userId + in: query + required: true + description: Рдентификатор пользователя-получателя + schema: + type: string + example: 123 + responses: + "200": + description: Успешный ответ СЃ информацией Рѕ переводе + content: + application/json: + schema: + $ref: "#/components/schemas/Transfers" + "default": + description: Ошибки + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /transfers/{transferId}: + get: + summary: Получить информацию Рѕ переводе + tags: + - Денежные переводы + operationId: getTransferById + parameters: + - name: transferId + in: path + required: true + description: Рдентификатор транзакции + schema: + type: string + example: 12345 + - name: Authorization + in: header + required: true + description: Рдентификатор сессии + schema: + type: string + example: 2527d786-d0d7-47d9-872b-af295552103b + responses: + "200": + description: Успешный ответ СЃ информацией Рѕ переводе + content: + application/json: + schema: + $ref: "#/components/schemas/Transfer" + "default": + description: Ошибки + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + /sessions: + post: + summary: Создать сессию + tags: + - Сессии + operationId: createSession + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + userId: + type: string + example: 123 + description: идентификатор пользователя + password: + type: string + example: pwd + description: пароль + responses: + "200": + description: Успешный ответ СЃ сессией + content: + application/json: + schema: + $ref: "#/components/schemas/Session" + "default": + description: Ошибки + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + + /sessions/{sessionId}: + get: + summary: Получить информацию Рѕ сессии + tags: + - Сессии + operationId: getSessionById + parameters: + - name: sessionId + in: path + required: true + description: Рдентификатор сессии + schema: + type: string + example: 2527d786-d0d7-47d9-872b-af295552103b + responses: + "200": + description: Успешный ответ СЃ сессией + content: + application/json: + schema: + $ref: "#/components/schemas/Session" + "default": + description: Ошибки + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + delete: + summary: Выйти РёР· сессии + tags: + - Сессии + operationId: closeSession + parameters: + - name: sessionId + in: path + required: true + description: Рдентификатор сессии + schema: + type: string + example: 2527d786-d0d7-47d9-872b-af295552103b + responses: + "200": + description: Успешный ответ + "default": + description: Ошибки + content: + application/json: + schema: + $ref: "#/components/schemas/Error" + +components: + schemas: + User: + type: object + required: + - username + - password + - email + properties: + username: + type: string + example: Bogdan + description: Любые Р±СѓРєРІС‹. РќРµ более 20 символов. + email: + type: string + format: email + example: potato@mail.ru + description: Стандартный адрес электронной почты. Рљ электронной почте может быть привязан только РѕРґРёРЅ пользователь. + password: + type: string + format: password + example: pass123 + description: РѕС‚ 8 РґРѕ 64 символов. Только латинские символы, цифры, знаки только !?. Обязательно наличие РјРёРЅРёРјСѓРј 1 Р±СѓРєРІС‹ верхнего Рё нижнего регистра, цифры Рё знака. + + UserInfo: + type: object + required: + - lastName + - firstName + - phone + - email + - birthdate + properties: + lastName: + type: string + example: Богданов + description: Только Р±СѓРєРІС‹ СЂСѓСЃСЃРєРѕРіРѕ алфавита. Первая Р±СѓРєРІР° - заглавная. РќРµ более 50 символов. + firstName: + type: string + example: Богдан + description: Только Р±СѓРєРІС‹ СЂСѓСЃСЃРєРѕРіРѕ алфавита. Первая Р±СѓРєРІР° - заглавная. РќРµ более 50 символов. + middleName: + type: string + example: Богданович + description: Только Р±СѓРєРІС‹ СЂСѓСЃСЃРєРѕРіРѕ алфавита. Первая Р±СѓРєРІР° - заглавная. РќРµ более 50 символов. + phone: + type: string + example: 78005553535 + description: 11 цифр, начинается СЃ '7' Рљ номеру телефона может быть привязан только РѕРґРёРЅ пользователь. + email: + type: string + format: email + example: potato@mail.ru + description: Стандартный адрес электронной почты. Рљ электронной почте может быть привязан только РѕРґРёРЅ пользователь. + birthdate: + type: string + format: date + example: "2000-01-01" + description: Дата рождения РІ формате ISO 8601 (YYYY-MM-DD) + + Wallet: + type: object + required: + - number + - balance + properties: + number: + type: integer + example: 123 + description: Номер кошелька + balance: + type: integer + example: 123 + description: Баланс кошелька + + Transfer: + type: object + required: + - creationTime + - amount + - transferType + properties: + transferId: + type: string + example: 12345 + description: Рдентификатор перевода + creationTime: + type: string + format: date-time + example: "2023-07-02T14:48:00Z" + description: Дата Рё время операции РІ ISO 8601 формате (ГГГГ-РњРњ-ДДTР§Р§:РњРњ:РЎРЎZ) + amount: + type: integer + example: 1000 + description: РЎСѓРјРјР° денежных единиц операции + transferType: + type: string + enum: + - transfer + description: РўРёРї операции + status: + type: string + enum: + - paid + - unpaid + description: Статус операции + + Transfers: + type: array + items: + $ref: "#/components/schemas/Transfer" + + Session: + type: object + required: + - expirationTime + - sessionId + - active + properties: + expirationTime: + type: string + format: date-time + example: "2023-07-02T14:48:00Z" + description: Дата Рё время РІ формате ISO 8601 (ГГГГ-РњРњ-ДДTР§Р§:РњРњ:РЎРЎZ) + sessionId: + type: string + example: 2527d786-d0d7-47d9-872b-af295552103b + description: идентификатор сессии + active: + type: boolean + description: Статус сессии + + Error: + type: object + required: + - code + - message + properties: + code: + type: integer + example: 1 + description: Внутренний РєРѕРґ ошибки + message: + type: string + example: "Internal error" + description: Пояснение Рє ошибке \ No newline at end of file diff --git a/src/main/resources/db/migration/V2__testModel.sql b/src/main/resources/db/migration/V2__testModel.sql deleted file mode 100644 index 717b77f..0000000 --- a/src/main/resources/db/migration/V2__testModel.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE TABLE model ( - id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, - name VARCHAR(255), - last_name VARCHAR(255), - CONSTRAINT pk_model PRIMARY KEY (id) -); \ No newline at end of file -- GitLab