Setup
This commit is contained in:
commit
46f9ef70d1
18 changed files with 281 additions and 0 deletions
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
.gradle/
|
||||
gradle/
|
||||
gradlew
|
||||
gradlew.bat
|
||||
build/
|
||||
|
||||
.idea/**/*
|
||||
!.idea/.gitignore
|
2
.idea/.gitignore
vendored
Normal file
2
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
!.gitignore
|
||||
!.name
|
1
.idea/.name
Normal file
1
.idea/.name
Normal file
|
@ -0,0 +1 @@
|
|||
Webshop
|
11
.run/Postgres.run.xml
Normal file
11
.run/Postgres.run.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Postgres" type="docker-deploy" factoryName="docker-compose.yml" server-name="Podman">
|
||||
<deployment type="docker-compose.yml">
|
||||
<settings>
|
||||
<option name="envFilePath" value="" />
|
||||
<option name="sourceFilePath" value="compose.yml" />
|
||||
</settings>
|
||||
</deployment>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
10
.run/WebshopApplication.run.xml
Normal file
10
.run/WebshopApplication.run.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="WebshopApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true">
|
||||
<module name="Webshop.main" />
|
||||
<option name="SPRING_BOOT_MAIN_CLASS" value="de.szut.store.WebshopApplication" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Postgres" run_configuration_type="docker-deploy" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
39
build.gradle.kts
Normal file
39
build.gradle.kts
Normal file
|
@ -0,0 +1,39 @@
|
|||
plugins {
|
||||
java
|
||||
id("org.springframework.boot") version "3.3.2"
|
||||
id("io.spring.dependency-management") version "1.1.6"
|
||||
}
|
||||
|
||||
group = "de.szut"
|
||||
version = "0.0.1-SNAPSHOT"
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(22)
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
compileOnly {
|
||||
extendsFrom(configurations.annotationProcessor.get())
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
implementation("org.springframework.boot:spring-boot-starter-validation")
|
||||
compileOnly("org.projectlombok:lombok")
|
||||
runtimeOnly("org.postgresql:postgresql")
|
||||
annotationProcessor("org.projectlombok:lombok")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
useJUnitPlatform()
|
||||
}
|
16
compose.yml
Normal file
16
compose.yml
Normal file
|
@ -0,0 +1,16 @@
|
|||
services:
|
||||
postgres:
|
||||
container_name: store_postgres
|
||||
image: postgres:16
|
||||
environment:
|
||||
- POSTGRES_DB=store
|
||||
- POSTGRES_USER=store
|
||||
- POSTGRES_PASSWORD=store123
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- "store_data:/var/lib/postgresql/data"
|
||||
|
||||
volumes:
|
||||
store_data:
|
||||
name: store_data
|
1
settings.gradle.kts
Normal file
1
settings.gradle.kts
Normal file
|
@ -0,0 +1 @@
|
|||
rootProject.name = "Webshop"
|
13
src/main/java/de/szut/store/WebshopApplication.java
Normal file
13
src/main/java/de/szut/store/WebshopApplication.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package de.szut.store;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class WebshopApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WebshopApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
37
src/main/java/de/szut/store/article/Article.java
Normal file
37
src/main/java/de/szut/store/article/Article.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
package de.szut.store.article;
|
||||
|
||||
import de.szut.store.supplier.Supplier;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@Table(name="article")
|
||||
public class Article {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@NotBlank
|
||||
private String destination;
|
||||
|
||||
@NotBlank
|
||||
private Double price;
|
||||
|
||||
@NotNull
|
||||
private LocalDateTime createDate;
|
||||
|
||||
@NotNull
|
||||
private LocalDateTime lastChangeDate;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||
private Supplier supplier;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package de.szut.store.article;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface ArticleRepository extends JpaRepository<Article, Long> {
|
||||
}
|
31
src/main/java/de/szut/store/contact/Contact.java
Normal file
31
src/main/java/de/szut/store/contact/Contact.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package de.szut.store.contact;
|
||||
|
||||
import de.szut.store.supplier.Supplier;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="contact")
|
||||
public class Contact {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@NotBlank
|
||||
private String street;
|
||||
|
||||
@NotBlank
|
||||
@Size(min = 3, max = 7)
|
||||
private String zipcode;
|
||||
|
||||
@NotBlank
|
||||
private String city;
|
||||
|
||||
@OneToOne(mappedBy = "contact", cascade = CascadeType.ALL)
|
||||
private Supplier supplier;
|
||||
|
||||
private String phone;
|
||||
}
|
29
src/main/java/de/szut/store/supplier/Supplier.java
Normal file
29
src/main/java/de/szut/store/supplier/Supplier.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package de.szut.store.supplier;
|
||||
|
||||
import de.szut.store.article.Article;
|
||||
import de.szut.store.contact.Contact;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name="supplier")
|
||||
public class Supplier {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@NotBlank
|
||||
@Size(min = 3, max = 50)
|
||||
private String name;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
||||
private Contact contact;
|
||||
|
||||
@OneToMany(mappedBy = "supplier", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||
private Set<Article> articles;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package de.szut.store.supplier;
|
||||
|
||||
public class SupplierController {
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package de.szut.store.supplier;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface SupplierRepository extends JpaRepository<Supplier, Long> {
|
||||
}
|
45
src/main/java/de/szut/store/supplier/SupplierService.java
Normal file
45
src/main/java/de/szut/store/supplier/SupplierService.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package de.szut.store.supplier;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SupplierService {
|
||||
@Autowired
|
||||
private final SupplierRepository repository;
|
||||
|
||||
public SupplierService(SupplierRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public Supplier create(Supplier newSupplier) {
|
||||
return repository.save(newSupplier);
|
||||
}
|
||||
|
||||
public Supplier update(Supplier newSupplier) {
|
||||
return repository.findById(newSupplier.getId())
|
||||
.map(supplier -> {
|
||||
supplier.setName(newSupplier.getName());
|
||||
supplier.getContact().setCity(newSupplier.getContact().getCity());
|
||||
supplier.getContact().setZipcode(newSupplier.getContact().getZipcode());
|
||||
supplier.getContact().setStreet(newSupplier.getContact().getStreet());
|
||||
supplier.getContact().setPhone(newSupplier.getContact().getPhone());
|
||||
supplier.setArticles(newSupplier.getArticles());
|
||||
return repository.save(supplier);
|
||||
}).orElse(null);
|
||||
}
|
||||
|
||||
public List<Supplier> readAll() {
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
public Supplier readById(Long id) {
|
||||
return repository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public void delete(Long id) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
9
src/main/resources/application.properties
Normal file
9
src/main/resources/application.properties
Normal file
|
@ -0,0 +1,9 @@
|
|||
# General
|
||||
spring.application.name=Webshop
|
||||
server.port=8080
|
||||
|
||||
# DB
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/store
|
||||
spring.datasource.username=store
|
||||
spring.datasource.password=store123
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
13
src/test/java/de/szut/webshop/WebshopApplicationTests.java
Normal file
13
src/test/java/de/szut/webshop/WebshopApplicationTests.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package de.szut.webshop;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class WebshopApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue