A basic structure of DB (WIP)

This commit is contained in:
2025-04-01 15:55:49 +02:00
parent fdee6ecc84
commit f65b10b302
12 changed files with 229 additions and 66 deletions

4
sql/data.sql Normal file
View File

@@ -0,0 +1,4 @@
INSERT INTO Clients (email, first_name, image, last_name, password, role)
VALUES(
'dignissim.tempor.arcu@aol.ca', 'Diana', 'null', 'Harrison', 'password', 'USER'
)

View File

@@ -1,7 +1,6 @@
package _11.asktpk.artisanconnectbackend.Controller;
import _11.asktpk.artisanconnectbackend.Model.Notice;
import _11.asktpk.artisanconnectbackend.Repository.NoticeRepository;
import _11.asktpk.artisanconnectbackend.Service.PostgresDatabase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;

View File

@@ -0,0 +1,19 @@
package _11.asktpk.artisanconnectbackend.Model;
import jakarta.persistence.*;
@Entity
@Table(name = "attribute_values")
public class AttributeValues {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "id_attribute")
private Attributes attribute;
private String value;
// Getters, setters, and constructors
}

View File

@@ -0,0 +1,19 @@
package _11.asktpk.artisanconnectbackend.Model;
import jakarta.persistence.*;
import java.util.List;
@Entity
@Table(name = "attributes")
public class Attributes {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idAttribute;
private String name;
@OneToMany(mappedBy = "attribute", cascade = CascadeType.ALL)
private List<AttributeValues> attributeValues;
// Getters, setters, and constructors
}

View File

@@ -0,0 +1,21 @@
package _11.asktpk.artisanconnectbackend.Model;
import jakarta.persistence.*;
@Entity
@Table(name = "attributes_notice")
public class AttributesNotice {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "id_notice")
private Notice notice;
@ManyToOne
@JoinColumn(name = "id_value")
private AttributeValues attributeValue;
// Getters, setters, and constructors
}

View File

@@ -0,0 +1,30 @@
package _11.asktpk.artisanconnectbackend.Model;
import _11.asktpk.artisanconnectbackend.Utils.Enums.Role;
import jakarta.persistence.*;
import java.util.List;
@Entity
@Table(name = "clients")
public class Client {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idUser;
private String email;
private String password;
private String firstName;
private String lastName;
private String image; // Optional field
@Enumerated(EnumType.STRING)
private Role role;
@OneToMany(mappedBy = "client", cascade = CascadeType.ALL)
private List<Notice> notices;
@OneToMany(mappedBy = "client", cascade = CascadeType.ALL)
private List<Orders> orders;
// Getters, setters, and constructors
}

View File

@@ -0,0 +1,16 @@
package _11.asktpk.artisanconnectbackend.Model;
import jakarta.persistence.*;
@Entity
@Table(name = "global_variables")
public class GlobalVariables {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String value;
// Getters, setters, and constructors
}

View File

@@ -1,63 +1,47 @@
package _11.asktpk.artisanconnectbackend.Model;
import jakarta.persistence.*;
import java.sql.Blob;
import java.time.LocalDate;
import java.util.List;
import _11.asktpk.artisanconnectbackend.Utils.Enums.*;
@Entity
@Table(name = "notice")
public class Notice {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idNotice;
@Column
private String title;
@Column
private String username;
@ManyToOne
@JoinColumn(name = "client_id")
private Client client;
@Column
private String description;
private Double price;
public Notice() {
this.title = "";
this.username = "";
this.description = "";
}
@Enumerated(EnumType.STRING)
private Category category;
public Notice(String nTitle, String nUsername, String nDescription) {
this.title = nTitle;
this.username = nUsername;
this.description = nDescription;
}
@ElementCollection
private List<String> images;
public void setId(Long id) {
this.id = id;
}
@Enumerated(EnumType.STRING)
private Status status;
public Long getId() {
return id;
}
private LocalDate publishDate;
public String getUsername() {
return username;
}
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
private List<AttributesNotice> attributesNotices;
public void setUsername(String user) {
this.username = user;
}
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
private List<Orders> orders;
public String getTitle() {
return title;
}
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
private List<Payments> payments;
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
// Getters, setters, and constructors
}

View File

@@ -0,0 +1,26 @@
package _11.asktpk.artisanconnectbackend.Model;
import _11.asktpk.artisanconnectbackend.Utils.Enums.Status;
import jakarta.persistence.*;
@Entity
@Table(name = "orders")
public class Orders {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idOrder;
@ManyToOne
@JoinColumn(name = "id_user")
private Client client;
@ManyToOne
@JoinColumn(name = "id_notice")
private Notice notice;
@Enumerated(EnumType.STRING)
private Status status;
// Getters, setters, and constructors
}

View File

@@ -0,0 +1,30 @@
package _11.asktpk.artisanconnectbackend.Model;
import _11.asktpk.artisanconnectbackend.Utils.Enums.Status;
import jakarta.persistence.*;
@Entity
@Table(name = "payments")
public class Payments {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idPayment;
@ManyToOne
@JoinColumn(name = "id_order")
private Orders order;
@ManyToOne
@JoinColumn(name = "id_notice")
private Notice notice;
private Double noticePublishPrice;
@Enumerated(EnumType.STRING)
private Status status;
private String sessionId;
// Getters, setters, and constructors
}

View File

@@ -0,0 +1,15 @@
package _11.asktpk.artisanconnectbackend.Utils;
public class Enums {
public enum Role {
ADMIN, USER
}
public enum Category {
Electronics, Artwork, Kitchen, Buildings, Home, Fashion // Replace with actual categories
}
public enum Status {
ACTIVE, INACTIVE // Replace with actual statuses
}
}

View File

@@ -18,26 +18,26 @@ class ArtisanConnectBackendApplicationTests {
@Autowired
PostgresDatabase postgresDatabase;
@Test
void testPostgresDatabase() {
postgresDatabase.add(new Notice("Test Notice", "Username", "Test Description"));
Boolean isRecordAvailable = postgresDatabase.get().size() > 0;
if(isRecordAvailable) {
logger.info("The record is available in the database");
} else {
logger.error("The record is not available in the database");
}
assert isRecordAvailable;
}
@Test
void getAllNotices() throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
Request request = new Request.Builder()
.url("http://localhost:8080/api/v1/notices/all")
.build();
Response response = client.newCall(request).execute();
}
// @Test
// void testPostgresDatabase() {
// postgresDatabase.add(new Notice("Test Notice", "Username", "Test Description"));
// Boolean isRecordAvailable = postgresDatabase.get().size() > 0;
// if(isRecordAvailable) {
// logger.info("The record is available in the database");
// } else {
// logger.error("The record is not available in the database");
// }
// assert isRecordAvailable;
// }
//
// @Test
// void getAllNotices() throws IOException {
// OkHttpClient client = new OkHttpClient().newBuilder()
// .build();
// MediaType mediaType = MediaType.parse("text/plain");
// Request request = new Request.Builder()
// .url("http://localhost:8080/api/v1/notices/all")
// .build();
// Response response = client.newCall(request).execute();
// }
}