Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions payment-service-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Используем минимальный runtime-образ с JDK 21
FROM eclipse-temurin:21-jre-alpine
RUN echo "Current PWD:" && pwd
RUN echo "Listing files in current directory:" && ls -lR
# Задаем переменную окружения с названием jar-файла, можно переопределить при сборке
RUN echo "Current PWD:" && pwd
ARG JAR_FILE=target/payment-service-app-0.0.1-SNAPSHOT.jar
# Создаём рабочую директорию приложения
WORKDIR /app
# Копируем jar-файл в контейнер
COPY ${JAR_FILE} app.jar
RUN echo "Listing files in current directory:" && ls -lR
# Запускаем приложение
ENTRYPOINT ["java", "-jar", "app.jar"]
# Открываем порт для доступа к приложению
EXPOSE 8080
EXPOSE 8082
2 changes: 1 addition & 1 deletion payment-service-app/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:

payment-service-app:
#image: payment-service-app
image: payment-service-app
build:
context: .
dockerfile: Dockerfile
Expand Down
3 changes: 3 additions & 0 deletions payment-service-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.iprody.service.PaymentService;
import com.iprody.specification.PaymentFilter;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand All @@ -24,6 +26,9 @@
@RequestMapping("/payments")
public class PaymentController {

private static final Logger log =
LoggerFactory.getLogger(PaymentController.class);

private final PaymentService paymentService;

@GetMapping("/search")
Expand All @@ -35,6 +40,7 @@ public Page<PaymentDto> searchPayments(
@RequestParam(defaultValue = "amount") String sortBy,
@RequestParam(defaultValue = "desc") String direction
) {
log.info("GET: search payments");
final Sort sort = direction.equalsIgnoreCase("desc")
? Sort.by(sortBy).descending()
: Sort.by(sortBy).ascending();
Expand All @@ -46,42 +52,51 @@ public Page<PaymentDto> searchPayments(
@GetMapping
@PreAuthorize("hasAnyRole('ADMIN','READER')")
public ResponseEntity<List<PaymentDto>> fetchAll() {
log.info("GET: get all payments");
return ResponseEntity.ok().body(this.paymentService.getPayments());
}

@PostMapping(path = "/add")
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<PaymentDto> addPayment(@RequestBody PaymentDto paymentDto) {
log.info("POST: save one payment {}", paymentDto);
final PaymentDto savedPayment = this.paymentService.create(paymentDto);
final URI location = ServletUriComponentsBuilder.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(savedPayment.getGuid())
.toUri();
log.debug("Payment saved: {}", savedPayment);
return ResponseEntity.created(location).body(savedPayment);
}

@GetMapping(path = "/{id}")
@PreAuthorize("hasAnyRole('ADMIN','USER','READER')")
public ResponseEntity<PaymentDto> getPayment(@PathVariable UUID id) {
return ResponseEntity.ok().body(this.paymentService.get(id));
log.info("GET: get payment by id {}", id);
final PaymentDto dto = this.paymentService.get(id);
log.debug("Sending response PaymentDto: {}", dto);
return ResponseEntity.ok().body(dto);
}

@PutMapping(path = "/update/{id}")
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<PaymentDto> updatePayment(@PathVariable UUID id, @RequestBody PaymentDto paymentDto) {
log.info("PUT: update payment by id {} and dto {}", id, paymentDto);
return ResponseEntity.ok().body(this.paymentService.update(id, paymentDto));
}

@PutMapping(path = "/update/{id}/{note}")
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<PaymentDto> updatePaymentNote(@PathVariable UUID id, @PathVariable String note) {
log.info("PUT: update payment note by id {} and new note {}", id, note);
return ResponseEntity.ok().body(this.paymentService.updateNote(id, note));
}

@DeleteMapping(path = "/delete/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@PreAuthorize("hasRole('ADMIN')")
public void deletePayment(@PathVariable UUID id) {
log.info("DELETE: delete payment by id {}", id);
this.paymentService.delete(id);
}

Expand Down
8 changes: 5 additions & 3 deletions payment-service-app/src/main/resources/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

1. cd C:\Projects\iPrody\PaymentService\payment-service-app

2. docker build --build-arg JAR_FILE=payment-service-app-0.0.1-SNAPSHOT.jar -t payment-service-app .
2. docker build --build-arg JAR_FILE=target\payment-service-app-0.0.1-SNAPSHOT.jar -t payment-service-app .

3. docker-compose up -d

Expand All @@ -11,8 +11,10 @@

http://localhost:8081/browser/ "admin@email.com / admin"

In servers connect to payment-db with creds "user / secret"

Right click Servers -> Register -> Connection:
hostname "postgres-db"
username "user"
password "secret"

#### Security

Expand Down
17 changes: 15 additions & 2 deletions payment-service-app/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ spring:
application:
name: payment-service-app
datasource: # объединяет в себе параметры подключения к БД
#url: jdbc:postgresql://postgres-db:5432/payment-db # URL подключения к БД
url: jdbc:postgresql://localhost:5432/payment-db
url: jdbc:postgresql://postgres-db:5432/payment-db # URL подключения к БД
#url: jdbc:postgresql://localhost:5432/payment-db
username: user # Имя пользователя
password: secret # Пароль
driver-class-name: org.postgresql.Driver # класс jdbc драйвера
Expand All @@ -27,6 +27,19 @@ spring:
jwt:
issuer-uri: http://localhost:8085/realms/iprody-lms

management:
endpoints:
web:
exposure:
include: health,info,metrics,env,loggers

logging:
level:
com.iprody: DEBUG
org.springframework.web: INFO
org.springframework.data: INFO
org.springframework.security: INFO

#logging:
# level:
# liquibase: DEBUG
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
databaseChangeLog:
- changeSet:
id: 1.0-create-payment-table
author: me
author: mentor
changes:
- createTable:
tableName: payments
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
databaseChangeLog:
- changeSet:
id: 1.1-insert-demo-payment
author: me
author: mentor
comment: "Insert demo payment row for development/testing"
changes:
- insert:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
databaseChangeLog:
- changeSet:
id: 1.2-insert-demo-payment-sql
author: me
author: mentor
comment: "Insert 3 demo payments for manual testing"
changes:
- sql:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
databaseChangeLog:
- changeSet:
id: 1.3-insert-demo-payments-sql-file
author: Dmitry Chaykin
author: mentor
changes:
- sqlFile:
path: db/changelog/sql/data.sql
Expand Down
32 changes: 32 additions & 0 deletions payment-service-app/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level ${PID} --- [%thread] %-40.40logger{50} : %msg%n" />
<!-- STDOUT (консольный апендер) -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<!-- FILE с ежедневной ротацией -->
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/app.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Архив с указанием даты -->
<fileNamePattern>logs/app-%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- Сколько файлов хранить -->
<maxHistory>7</maxHistory>
<!-- Максимальный размер хранилища всех логов (необязательно) -->
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<!-- Корневой логгер (root) -->
<root level="${LOG_LEVEL}">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
Loading