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
74 changes: 74 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Tests

on:
push:
branches:
- main
- test-branch
- CI
pull_request:
branches:
- main
- test-branch

jobs:
build:
name: Build & Test
runs-on: ubuntu-latest
container:
image: openjdk:21-slim

services:
postgres:
image: postgres:15
env:
POSTGRES_DB: database
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install PostgreSQL client
run: |
apt-get update
apt-get install -y postgresql-client netcat-openbsd

- name: Wait for PostgreSQL to be Ready
run: |
echo "Waiting for PostgreSQL to be ready..."
for i in {1..30}; do
nc -z postgres 5432 && echo "PostgreSQL is ready!" && exit 0
echo "Waiting..."
sleep 2
done
echo "PostgreSQL did not start in time" && exit 1

- name: Set Executable Permission for Gradle Wrapper
run: chmod +x gradlew

- name: Check Database Connection
run: |
PGPASSWORD=postgres psql -h postgres -U postgres -d database -c "SELECT 'Connected to PostgreSQL!'"

- name: Build with Gradle
run: ./gradlew clean build
env:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/database
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: postgres

- name: Run Tests
run: ./gradlew test --tests "service.*" --info
env:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/database
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: postgres
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,13 @@ public void returnBook(@Valid @RequestBody BookBorrowDTO bookBorrowDTO) {
public Collection<Book> getBooksOwnedByOwner() {
User user = userService.getCurrentUser();

// Fetch owned books for the user
return bookService.getBooksOwnedByUser(user.getEmail());
}

@GetMapping("/borrowed")
public Collection<Book> getBooksBorrowedByUser() {
// Retrieve the user's authentication
User user = userService.getCurrentUser();

// Fetch borrowed books for the user
return bookService.getBooksBorrowedByUser(user.getEmail());
}

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ application.openapi.prod-url=http://localhost:8080/swagger
spring.cloud.config.uri=http://localhost:8888
spring.cloud.config.fail-fast=true
#Swagger
application.openapi.prod-url=http://localhost:8080/swagger
springdoc.api-docs.path=/v3/swagger
springdoc.swagger-ui.path=/swagger-ui
Loading