diff --git a/.gitignore b/.gitignore index 6ac465db..244268f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target/ /.idea/ +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..2213772e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM eclipse-temurin:21-jdk + +COPY src/main/java/org/example/App.java /App.java + +ENTRYPOINT ["java", "/App.java"] + diff --git a/README.md b/README.md index 5150e50f..05def9a9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/_uV8Mn8f) # 📘 Projektarbete: JPA + Hibernate med GitHub-flöde Projektet genomförs som antingen en Java CLI-applikation eller med hjälp av JavaFX om ni vill ha ett grafiskt gränssnitt. diff --git a/dfg b/dfg new file mode 100644 index 00000000..6dac856d --- /dev/null +++ b/dfg @@ -0,0 +1,42 @@ +commit 149e0caf9a2d36b0dfd9254b37c62c2bb73d2f0c (HEAD -> main, origin/main, origin/HEAD) +Author: github-classroom[bot] <66690702+github-classroom[bot]@users.noreply.github.com> +Date: Mon Dec 15 09:40:48 2025 +0000 + + add deadline + +commit 879440803daa45b536e2ea5f3ec269d1be62bf04 (upstream/main, upstream/HEAD) +Author: Martin Blomberg +Date: Sun Dec 14 16:07:37 2025 +0100 + + Setup for JPA application + +commit 539e1a559ab7607b40651315e45ef50074c51b8c +Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> +Date: Sun Dec 14 12:52:36 2025 +0000 + + Bump org.mockito:mockito-junit-jupiter in the maven-deps group (#1) + + Bumps the maven-deps group with 1 update: [org.mockito:mockito-junit-jupiter](https://github.com/mockito/mockito). + + + Updates `org.mockito:mockito-junit-jupiter` from 5.20.0 to 5.21.0 + - [Release notes](https://github.com/mockito/mockito/releases) + - [Commits](https://github.com/mockito/mockito/compare/v5.20.0...v5.21.0) + + --- + updated-dependencies: + - dependency-name: org.mockito:mockito-junit-jupiter + dependency-version: 5.21.0 + dependency-type: direct:development + update-type: version-update:semver-minor + dependency-group: maven-deps + ... + + Signed-off-by: dependabot[bot] + Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> + +commit c9a2be0c3d4286e6322bb017f66aa77bbaaa5a00 +Author: github-classroom[bot] <66690702+github-classroom[bot]@users.noreply.github.com> +Date: Sun Dec 14 12:51:33 2025 +0000 + + Initial commit diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..bfc28754 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,18 @@ +services: + mysql: + image: mysql:9.5.0 + container_name: mysql + environment: + MYSQL_ROOT_PASSWORD: rootpassword + MYSQL_ROOT_HOST: "%" + MYSQL_DATABASE: app_db + MYSQL_USER: grupp2 + MYSQL_PASSWORD: ${PASSWORD} + ports: + - "3306:3306" + volumes: + - mysql_data:/var/lib/mysql +volumes: + mysql_data: + + diff --git a/src/docker/Dockerfile b/src/docker/Dockerfile new file mode 100644 index 00000000..46a05dd0 --- /dev/null +++ b/src/docker/Dockerfile @@ -0,0 +1,4 @@ +FROM eclipse-temurin:25-jdk +COPY target/classes/org/example/App.class /app/Docker/App.class +ENTRYPOINT ["java", "-cp", "/app", "Docker.Demo"] + diff --git a/src/docker/docker-compose.yml b/src/docker/docker-compose.yml new file mode 100644 index 00000000..7b240fc2 --- /dev/null +++ b/src/docker/docker-compose.yml @@ -0,0 +1,17 @@ +services: + mysql: + image: mysql:9.5.0 + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_ROOT_HOST: "%" + MYSQL_DATABASE: test + MYSQL_USER: grupp2 + MYSQL_PASSWORD: morot7 + ports: + - "3306:3306" + volumes: + - mysql_data:/var/lib/mysql + + +volumes: + mysql_data: diff --git a/src/main/java/org/example/entities/OpeningHours.java b/src/main/java/org/example/entities/OpeningHours.java new file mode 100644 index 00000000..9427662e --- /dev/null +++ b/src/main/java/org/example/entities/OpeningHours.java @@ -0,0 +1,78 @@ +package org.example.entities; + +import jakarta.persistence.*; + +import java.time.LocalTime; + +@Entity +public class OpeningHours { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Enumerated(EnumType.STRING) + private Weekday weekday; + + private LocalTime openingTime; + private LocalTime closingTime; + + public OpeningHours(Long id, Weekday weekday, LocalTime openingTime, LocalTime closingTime) { + this.id = id; + this.weekday = weekday; + this.openingTime = openingTime; + this.closingTime = closingTime; + if(openingTime.isAfter(closingTime)) + throw new RuntimeException("Opening time cannot be after closing time"); + } + + public OpeningHours(){} + + public Long getId() { + return id; + } + + public Weekday getWeekday() { + return weekday; + } + + public void setWeekday(Weekday weekday) { + this.weekday = weekday; + } + + public LocalTime getOpeningTime() { + return openingTime; + } + + public void setOpeningTime(LocalTime opening_time) { + this.openingTime = opening_time; + } + + public LocalTime getClosingTime() { + return closingTime; + } + + public void setClosingTime(LocalTime closing_time) { + this.closingTime = closing_time; + } + + @Override + public String toString() { + return "OpeningHours{" + + "id=" + id + + ", weekday='" + weekday + '\'' + + ", openingTime=" + openingTime + + ", closingTime=" + closingTime + + '}'; + } + + enum Weekday{ + MONDAY, + TUESDAY, + WEDNESDAY, + THURSDAY, + FRIDAY, + SATURDAY, + SUNDAY + } +} diff --git a/src/main/java/org/example/entities/Restaurant.java b/src/main/java/org/example/entities/Restaurant.java new file mode 100644 index 00000000..742d8d8f --- /dev/null +++ b/src/main/java/org/example/entities/Restaurant.java @@ -0,0 +1,92 @@ +package org.example.entities; + +import jakarta.persistence.*; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +@Entity +public class Restaurant { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @OneToMany + @JoinColumn(name = "openingHoursId") + private List openingHours = new ArrayList<>(); + + private String name; + private String category; + private String address; + private BigDecimal priceRange; + private double rating; + + public Restaurant(Long id, String name, String category, String address, BigDecimal priceRange, double rating) { + this.id = id; + this.name = name; + this.category = category; + this.address = address; + this.priceRange = priceRange; + this.rating = rating; + } + + public Restaurant(){} + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public BigDecimal getPriceRange() { + return priceRange; + } + + public void setPriceRange(BigDecimal price_range) { + this.priceRange = price_range; + } + + public double getRating() { + return rating; + } + + public void setRating(double rating) { + this.rating = rating; + } + + @Override + public String toString() { + return "Restaurant{" + + "id=" + id + + ", name='" + name + '\'' + + ", category='" + category + '\'' + + ", address='" + address + '\'' + + ", priceRange=" + priceRange + + ", rating=" + rating + + '}'; + } +} diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml new file mode 100644 index 00000000..22226c06 --- /dev/null +++ b/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,22 @@ + + + + org.example.Product + + + + + + + + + + + + + + +