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

on:
push:
branches: [ "*" ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

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

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Cache Maven dependencies
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Run tests
run: ./mvnw clean test
build:
needs: test
runs-on: ubuntu-latest

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

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Cache Maven dependencies
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build application
run: ./mvnw clean package -DskipTests
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,26 @@ public class ClientController {

@PostMapping("/person")
public ResponseEntity<Client> createPerson(@RequestBody @Valid PersonCreateDTO dto) {
Client created = clientService.savePerson(dto);
return ResponseEntity.status(HttpStatus.CREATED).body(created);
try {
Client created = clientService.savePerson(dto);
return ResponseEntity.status(HttpStatus.CREATED).body(created);
} catch (IllegalArgumentException ex) {
return ResponseEntity.status(HttpStatus.CONFLICT).body(null);
} catch (RuntimeException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

@PostMapping("/company")
public ResponseEntity<Client> createCompany(@RequestBody @Valid CompanyCreateDTO dto) {
Client created = clientService.saveCompany(dto);
return ResponseEntity.status(HttpStatus.CREATED).body(created);
try {
Client created = clientService.saveCompany(dto);
return ResponseEntity.status(HttpStatus.CREATED).body(created);
} catch (IllegalArgumentException ex) {
return ResponseEntity.status(HttpStatus.CONFLICT).body(null);
} catch (RuntimeException ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

@GetMapping("/{id}")
Expand All @@ -57,11 +69,13 @@ public ResponseEntity<Client> updatePerson(@PathVariable Long clientId,
try {
Client updated = clientService.updatePerson(clientId, dto);
return ResponseEntity.ok(updated);
} catch (IllegalArgumentException ex) {
return ResponseEntity.status(HttpStatus.CONFLICT).body(null);
} catch (RuntimeException ex) {
if (ex.getMessage().contains("not found")) {
return ResponseEntity.notFound().build();
}
throw ex;
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

Expand All @@ -71,11 +85,13 @@ public ResponseEntity<Client> updateCompany(@PathVariable Long clientId,
try {
Client updated = clientService.updateCompany(clientId, dto);
return ResponseEntity.ok(updated);
} catch (IllegalArgumentException ex) {
return ResponseEntity.status(HttpStatus.CONFLICT).body(null);
} catch (RuntimeException ex) {
if (ex.getMessage().contains("not found")) {
return ResponseEntity.notFound().build();
}
throw ex;
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ContractResponseDTO createContract(ContractCreateDTO contract) {
contract.setStartDate(LocalDateTime.now());
}

if (contract.getCostAmount() == null || contract.getCostAmount().compareTo(BigDecimal.ZERO) < 0) {
if (contract.getCostAmount() == null || contract.getCostAmount().compareTo(BigDecimal.ZERO) <= 0) {
throw new IllegalArgumentException("Cost amount must be non-negative");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest
@ActiveProfiles("test")
class ApiFactoryApplicationTests {

@Test
Expand Down
Loading