-
Notifications
You must be signed in to change notification settings - Fork 0
Torsten #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Torsten #1
Changes from all commits
f3c8a7a
f1fe925
975eb23
62cf397
6b256b9
996064f
49b5c0f
f671841
d1e233a
18078b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,57 @@ | ||
| package org.example; | ||
|
|
||
| import jakarta.persistence.EntityManager; | ||
| import jakarta.persistence.EntityManagerFactory; | ||
| import jakarta.persistence.Persistence; | ||
|
|
||
| public class App { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello There!"); | ||
| EntityManagerFactory emf = Persistence.createEntityManagerFactory("carRentalPU"); | ||
| EntityManager em = emf.createEntityManager(); | ||
|
|
||
| em.getTransaction().begin(); | ||
|
|
||
| // Rensa tabellen innan vi lägger in nya bilar | ||
| em.createQuery("DELETE FROM Car").executeUpdate(); | ||
|
|
||
| // Skapa och persist 20 bilar med rimliga dagspriser | ||
| em.persist(createCar("Volvo", "XC90", 2025, "Lyxbil", 800_000)); | ||
| em.persist(createCar("BMW", "7 Series", 2024, "Lyxbil", 1_000_000)); | ||
| em.persist(createCar("Audi", "A8", 2023, "Lyxbil", 900_000)); | ||
| em.persist(createCar("Toyota", "Corolla", 2022, "Personbil", 200_000)); | ||
| em.persist(createCar("Honda", "Civic", 2021, "Personbil", 190_000)); | ||
| em.persist(createCar("Ford", "Focus", 2022, "Personbil", 210_000)); | ||
| em.persist(createCar("Mercedes", "Sprinter", 2023, "Minibuss", 350_000)); | ||
| em.persist(createCar("Volkswagen", "Transporter", 2023, "Minibuss", 330_000)); | ||
| em.persist(createCar("Renault", "Kangoo", 2022, "Minibuss", 300_000)); | ||
| em.persist(createCar("Fiat", "500", 2023, "Småbil", 120_000)); | ||
| em.persist(createCar("Mini", "Cooper", 2022, "Småbil", 150_000)); | ||
| em.persist(createCar("Volkswagen", "Up!", 2022, "Småbil", 110_000)); | ||
| em.persist(createCar("Porsche", "911", 2025, "Sportbil", 1_500_000)); | ||
| em.persist(createCar("Ferrari", "Roma", 2024, "Sportbil", 2_000_000)); | ||
| em.persist(createCar("Lamborghini", "Huracan", 2025, "Sportbil", 2_500_000)); | ||
| em.persist(createCar("Tesla", "Model S", 2023, "Lyxbil", 900_000)); | ||
| em.persist(createCar("Kia", "Rio", 2022, "Småbil", 130_000)); | ||
| em.persist(createCar("Hyundai", "i30", 2023, "Personbil", 195_000)); | ||
| em.persist(createCar("Opel", "Vivaro", 2022, "Minibuss", 320_000)); | ||
| em.persist(createCar("Jaguar", "F-Type", 2024, "Sportbil", 1_600_000)); | ||
|
|
||
| em.getTransaction().commit(); | ||
| em.close(); | ||
| emf.close(); | ||
|
|
||
| System.out.println("20 cars saved successfully!"); | ||
| } | ||
|
|
||
| // Skapar bil och sätter dagspris till 0,5% av priset | ||
| private static Car createCar(String brand, String model, int year, String type, double price) { | ||
| Car car = new Car; | ||
| car.setBrand(brand); | ||
| car.setModel(model); | ||
| car.setYear(year); | ||
| car.setType(type); | ||
| car.setPrice(price); | ||
| car.setDailyPrice(price * 0.005); // 0,5% av totalpris | ||
| return car; | ||
| } | ||
|
Comment on lines
+47
to
56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check if Car import exists in App.java
echo "=== Checking for Car import in App.java ==="
if [ -f "src/main/java/org/example/App.java" ]; then
rg -n "^import.*Car" src/main/java/org/example/App.java || echo "No Car import found"
else
echo "App.java not found at src/main/java/org/example/App.java"
fi
# Check Car.java package
echo -e "\n=== Checking Car.java package ==="
if [ -f "src/main/java/org/example/model/Car.java" ]; then
rg -n "^package" src/main/java/org/example/model/Car.java
elif [ -f "src/main/java/org/example/Car.java" ]; then
rg -n "^package" src/main/java/org/example/Car.java
else
# Try to find Car.java anywhere
find src -name "Car.java" -type f -exec echo "Found: {}" \; -exec head -1 {} \;
fiRepository: ithsjava25/project-jpa-grupp-7-g Length of output: 197 Fix missing parentheses in constructor call. Line 48: 🧰 Tools🪛 GitHub Actions: Java Maven Build[error] 48-48: Compilation error: '(' or '[' expected. 🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package org.example.config; | ||
|
|
||
| import jakarta.persistence.EntityManager; | ||
| import jakarta.persistence.EntityManagerFactory; | ||
| import jakarta.persistence.Persistence; | ||
|
|
||
| public class JPAConfig { | ||
|
|
||
| private static final EntityManagerFactory emf = | ||
| Persistence.createEntityManagerFactory("carRentalPU"); | ||
|
|
||
| public static EntityManager getEntityManager() { | ||
| return emf.createEntityManager(); | ||
| } | ||
|
|
||
| public static void close() { | ||
| if (emf.isOpen()) { | ||
| emf.close(); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package org.example.controller; | ||
|
|
||
| public class BookingController { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.example.controller; | ||
|
|
||
| public class CarController { | ||
| boolean CarDamage=false; | ||
|
|
||
| boolean CarRented=false; | ||
| boolean CarAvailable=true; | ||
| boolean CarBooked=false; | ||
| boolean CarBroke=false; | ||
| boolean CarReturned=false; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package org.example.controller; | ||
|
|
||
| public interface CustomerController { | ||
| int addCustomer(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package org.example.controller; | ||
|
|
||
| public class MainViewController { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package org.example.model; | ||
|
|
||
| import jakarta.persistence.*; | ||
|
|
||
|
|
||
| import javax.tools.DocumentationTool; | ||
| import javax.xml.stream.Location; | ||
| import java.time.LocalDate; | ||
|
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove incorrect imports and add missing ones. Lines 6-7 contain wrong imports:
Additionally, line 35 references 🔎 Fix imports-import javax.tools.DocumentationTool;
-import javax.xml.stream.Location;
import java.time.LocalDate;
import java.time.LocalDateTime;
+import java.util.List;You'll also need to create or import the
🤖 Prompt for AI Agents |
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Entity | ||
| public class Booking { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @ManyToOne(optional = false) | ||
| @JoinColumn(name = "customer_id") | ||
| Customer customer; | ||
|
|
||
| @ManyToOne(optional = false) | ||
| @JoinColumn(name = "car_id") | ||
| private Car car; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "pickup_location_id") | ||
| private Location pickupLocation; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "dropoff_location_id") | ||
| private Location dropoffLocation; | ||
|
|
||
| @OneToMany | ||
| @JoinColumn(name = "booking_id") | ||
| private List<Extra> extras; | ||
|
|
||
| @OneToOne | ||
| @JoinColumn(name = "payment_id") | ||
| private Payment payment; | ||
|
|
||
| private LocalDate startDate; | ||
| private LocalDate endDate; | ||
|
|
||
| protected Booking() { | ||
| // JPA requires a no-arg constructor | ||
| } | ||
|
|
||
| public Booking(Customer customer, Car car, Location pickupLocation, Location dropoffLocation, LocalDate startDate, LocalDate endDate) { | ||
| this.customer = customer; | ||
| this.car = car; | ||
| this.startDate = startDate; | ||
| this.endDate = endDate; | ||
| this.status = BookingStatus.RESERVED; | ||
| this.createdAt = LocalDateTime.now(); | ||
|
|
||
| } | ||
|
Comment on lines
+12
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add getters and setters for entity fields. The Do you want me to generate the getter and setter methods for all fields? 🤖 Prompt for AI Agents
Comment on lines
+48
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add missing field declarations. The constructor (lines 53-54) references 🔎 Add missing fields and importAdd the import: import java.time.LocalDate;
import java.time.LocalDateTime;
+import org.example.model.BookingStatus;Add the fields after line 42: private LocalDate startDate;
private LocalDate endDate;
+
+ private BookingStatus status;
+ private LocalDateTime createdAt;
🤖 Prompt for AI Agents |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package org.example.model; | ||
|
|
||
| public enum BookingStatus { | ||
| RESERVED, | ||
| ACTIVE, | ||
| COMPLETED, | ||
| CANCELLED | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,41 @@ | ||||||
| package org.example; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix package declaration to match file location. The file is located at 🔎 Correct the package-package org.example;
+package org.example.model;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| import jakarta.persistence.Entity; | ||||||
| import jakarta.persistence.Id; | ||||||
| import jakarta.persistence.GeneratedValue; | ||||||
| import jakarta.persistence.GenerationType; | ||||||
|
|
||||||
| @Entity | ||||||
| public class Car { | ||||||
| @Id | ||||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||||||
| private Long id; | ||||||
|
|
||||||
| private String brand; | ||||||
| private String model; | ||||||
| private int year; | ||||||
| private String type; | ||||||
| private double price; | ||||||
| private double dailyPrice; // ny egenskap | ||||||
|
|
||||||
| // Getters och setters | ||||||
| public Long getId() { return id; } | ||||||
|
|
||||||
| public String getBrand() { return brand; } | ||||||
| public void setBrand(String brand) { this.brand = brand; } | ||||||
|
|
||||||
| public String getModel() { return model; } | ||||||
| public void setModel(String model) { this.model = model; } | ||||||
|
|
||||||
| public int getYear() { return year; } | ||||||
| public void setYear(int year) { this.year = year; } | ||||||
|
|
||||||
| public String getType() { return type; } | ||||||
| public void setType(String type) { this.type = type; } | ||||||
|
|
||||||
| public double getPrice() { return price; } | ||||||
| public void setPrice(double price) { this.price = price; } | ||||||
|
|
||||||
| public double getDailyPrice() { return dailyPrice; } | ||||||
| public void setDailyPrice(double dailyPrice) { this.dailyPrice = dailyPrice; } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package org.example.model; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| public class Customer { | ||
|
|
||
| @Id | ||
| @GeneratedValue | ||
| private Long id; | ||
|
|
||
| private String name; | ||
| private String email; | ||
|
|
||
| @OneToMany(mappedBy = "customer") | ||
| private List<Booking> bookings = new ArrayList<>(); | ||
|
|
||
| // getters & setters | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement missing getters and setters. The comment indicates getters and setters should exist, but they are not implemented. This will cause compilation errors when other code attempts to access Customer fields (e.g., Do you want me to generate the getter and setter methods for all fields? 🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package org.example.model; | ||
|
|
||
| import jakarta.persistence.Entity; | ||
|
|
||
| @Entity | ||
| public class Payment { | ||
| } | ||
|
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing required @id field for JPA entity. A JPA entity must have a primary key field annotated with 🔎 Apply this diff to add the required primary key:+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+
@Entity
public class Payment {
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ // Getters and setters
+ public Long getId() { return id; }
}🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package org.example.repository; | ||
|
|
||
| public class BookingRepository { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package org.example.repository; | ||
|
|
||
| import org.example.model.Car; | ||
| import org.example.util.JPAUtil; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find JPAUtil class
echo "=== Searching for JPAUtil class ==="
fd "JPAUtil" -e java
echo -e "\n=== Searching for getEntityManager in util package ==="
find . -path "*/org/example/util/*" -name "*.java" -type f
echo -e "\n=== Searching for CarRepository ==="
find . -name "CarRepository.java" -type fRepository: ithsjava25/project-jpa-grupp-7-g Length of output: 262 🏁 Script executed: #!/bin/bash
# Read CarRepository.java to see the import and usage
echo "=== CarRepository.java content ==="
cat ./src/main/java/org/example/repository/CarRepository.java
# Search entire codebase for JPAUtil references
echo -e "\n=== Searching for any JPAUtil references ==="
rg "JPAUtil" --type javaRepository: ithsjava25/project-jpa-grupp-7-g Length of output: 808 JPAUtil class does not exist—import is broken. The import statement references 🤖 Prompt for AI Agents |
||
|
|
||
| import jakarta.persistence.EntityManager; | ||
| import java.util.List; | ||
|
|
||
| public class CarRepository { | ||
|
|
||
| public List<Car> findAll() { | ||
| EntityManager em = JPAUtil.getEntityManager(); | ||
|
|
||
| List<Car> cars = | ||
| em.createQuery("SELECT c FROM Car c", Car.class) | ||
| .getResultList(); | ||
|
|
||
| em.close(); | ||
| return cars; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package org.example.repository; | ||
|
|
||
| public class CustomerRepository { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package org.example.service; | ||
|
|
||
| public class BookingService { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package org.example.service; | ||
|
|
||
| public class CarService { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package org.example.service; | ||
|
|
||
| public class CustomerService { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <persistence version="2.2" | ||
| xmlns="http://xmlns.jcp.org/xml/ns/persistence"> | ||
| <persistence-unit name="carRentalPU"> | ||
|
|
||
| <properties> | ||
| <property name="jakarta.persistence.jdbc.url" | ||
| value="jdbc:mysql://localhost:3306/carrental"/> | ||
| <property name="jakarta.persistence.jdbc.user" value="root"/> | ||
| <property name="jakarta.persistence.jdbc.password" value="password"/> | ||
| <property name="jakarta.persistence.jdbc.driver" | ||
| value="com.mysql.cj.jdbc.Driver"/> | ||
|
|
||
| <property name="hibernate.hbm2ddl.auto" value="validate"/> | ||
| <property name="hibernate.show_sql" value="true"/> | ||
| </properties> | ||
| </persistence-unit> | ||
| </persistence> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,3 @@ | ||||||||||||||||||||||||||||||||||||
| tabell med bilar | ||||||||||||||||||||||||||||||||||||
| uthyrnings tabell med many2man | ||||||||||||||||||||||||||||||||||||
| kund tabell | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace placeholder notes with valid CSS or remove the file. This file contains Swedish text notes rather than valid CSS syntax, which will cause parse errors when the stylesheet is loaded. The static analysis tool correctly identified these as syntax errors. If CSS styling is not yet needed, consider removing this file until actual styles are required. Otherwise, replace the content with valid CSS rules. 🔎 Example of valid CSS structure:-tabell med bilar
-uthyrnings tabell med many2man
-kund tabell
+/* Car table styles */
+.car-table {
+ /* Add styles here */
+}
+
+/* Rental table styles */
+.rental-table {
+ /* Add styles here */
+}
+
+/* Customer table styles */
+.customer-table {
+ /* Add styles here */
+}📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (2.1.2)[error] 3-3: Expected a compound selector but instead found the end of the file. Expected a compound selector here. (parse) [error] 1-1: Unknown type selector is not allowed. See MDN web docs for more details. (lint/correctness/noUnknownTypeSelector) [error] 1-1: Unknown type selector is not allowed. See MDN web docs for more details. (lint/correctness/noUnknownTypeSelector) [error] 1-1: Unknown type selector is not allowed. See MDN web docs for more details. (lint/correctness/noUnknownTypeSelector) [error] 1-2: Unknown type selector is not allowed. See MDN web docs for more details. (lint/correctness/noUnknownTypeSelector) [error] 2-2: Unknown type selector is not allowed. See MDN web docs for more details. (lint/correctness/noUnknownTypeSelector) [error] 2-2: Unknown type selector is not allowed. See MDN web docs for more details. (lint/correctness/noUnknownTypeSelector) [error] 2-2: Unknown type selector is not allowed. See MDN web docs for more details. (lint/correctness/noUnknownTypeSelector) [error] 2-3: Unknown type selector is not allowed. See MDN web docs for more details. (lint/correctness/noUnknownTypeSelector) [error] 3-3: Unknown type selector is not allowed. See MDN web docs for more details. (lint/correctness/noUnknownTypeSelector) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <?import javafx.scene.control.*?> | ||
| <?import javafx.scene.layout.*?> | ||
|
|
||
| <BorderPane xmlns:fx="http://javafx.com/fxml"> | ||
| <center> | ||
| <Label text="Car Rental System" /> | ||
| </center> | ||
| </BorderPane> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix syntax error: missing parentheses in constructor call.
Line 48 has a syntax error that causes compilation to fail. The constructor call is missing parentheses.
🔎 Apply this fix
📝 Committable suggestion
🧰 Tools
🪛 GitHub Actions: Java Maven Build
[error] 48-48: Compilation error: '(' or '[' expected.
🤖 Prompt for AI Agents