Initial commit with basic CRUD functionality:

* GET all properties
* GET one property by id
* CREATE one property
* DELETE one property by id
This commit is contained in:
2025-08-25 14:06:29 +02:00
commit 7be4c611b3
19 changed files with 867 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package de.iwomm.propify_api;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class PropifyApiApplication {
public static void main(String[] args) {
SpringApplication.run(PropifyApiApplication.class, args);
}
}

View File

@@ -0,0 +1,47 @@
package de.iwomm.propify_api.controller;
import de.iwomm.propify_api.entity.Property;
import de.iwomm.propify_api.service.PropertyService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@RestController
@RequestMapping("/api/v1/properties")
public class PropertyController {
private final PropertyService propertyService;
public PropertyController(PropertyService propertyService) {
this.propertyService = propertyService;
}
@GetMapping
public List<Property> getAllProperties() {
return propertyService.findAll();
}
@GetMapping("/{id}")
public Property getPropertyById(@PathVariable UUID id) {
return propertyService.findById(id).orElse(null);
}
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Property createProperty(@RequestBody Property property) {
return propertyService.save(property);
}
@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteProperty(@PathVariable UUID id) {
Optional<Property> property = propertyService.findById(id);
if (property.isEmpty()) {
return;
}
propertyService.delete(property.get());
}
}

View File

@@ -0,0 +1,88 @@
package de.iwomm.propify_api.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import java.util.UUID;
@Entity
public class Property {
@Id
@GeneratedValue
private UUID id;
private String name;
private String street;
private String houseNumber;
private String zipCode;
private String city;
private String country;
private String notes;
public Property() {}
public void setId(UUID id) {
this.id = id;
}
public UUID getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getHouseNumber() {
return houseNumber;
}
public void setHouseNumber(String houseNumber) {
this.houseNumber = houseNumber;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getNotes() {
return this.notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
}

View File

@@ -0,0 +1,11 @@
package de.iwomm.propify_api.repository;
import de.iwomm.propify_api.entity.Property;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional;
import java.util.UUID;
public interface PropertyRepository extends JpaRepository<Property, UUID> {
public Optional<Property> findByName(String name);
}

View File

@@ -0,0 +1,28 @@
package de.iwomm.propify_api.security;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable()) // CSRF deaktivieren für APIs
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/**").permitAll() // API ist offen
.anyRequest().permitAll() // Alles andere auch offen
)
.httpBasic(httpBasic -> httpBasic.disable()) // Kein Basic Auth
.formLogin(form -> form.disable()); // Kein Login-Formular
return http.build();
}
}

View File

@@ -0,0 +1,38 @@
package de.iwomm.propify_api.service;
import de.iwomm.propify_api.entity.Property;
import de.iwomm.propify_api.repository.PropertyRepository;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Service
public class PropertyService {
private final PropertyRepository propertyRepository;
public PropertyService(PropertyRepository propertyRepository) {
this.propertyRepository = propertyRepository;
}
public List<Property> findAll() {
return propertyRepository.findAll();
}
public Optional<Property>findById(UUID id) {
return propertyRepository.findById(id);
}
public Optional<Property> findByName(String name) {
return this.propertyRepository.findByName(name);
}
public Property save(Property property) {
return propertyRepository.save(property);
}
public void delete(Property property) {
propertyRepository.delete(property);
}
}

View File

@@ -0,0 +1,15 @@
spring:
application:
name: propify-api
datasource:
url: jdbc:h2:mem:demo;DB_CLOSE_DELAY=-1
driver-class-name: org.h2.Driver
username: sa
password:
jpa:
hibernate:
ddl-auto: update
show-sql: true
h2:
console:
enabled: true

View File

@@ -0,0 +1,13 @@
package de.iwomm.propify_api;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class PropifyApiApplicationTests {
@Test
void contextLoads() {
}
}