A basic structure of DB (WIP)
This commit is contained in:
4
sql/data.sql
Normal file
4
sql/data.sql
Normal 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'
|
||||||
|
)
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.Controller;
|
package _11.asktpk.artisanconnectbackend.Controller;
|
||||||
|
|
||||||
import _11.asktpk.artisanconnectbackend.Model.Notice;
|
import _11.asktpk.artisanconnectbackend.Model.Notice;
|
||||||
import _11.asktpk.artisanconnectbackend.Repository.NoticeRepository;
|
|
||||||
import _11.asktpk.artisanconnectbackend.Service.PostgresDatabase;
|
import _11.asktpk.artisanconnectbackend.Service.PostgresDatabase;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -1,63 +1,47 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.Model;
|
package _11.asktpk.artisanconnectbackend.Model;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import java.sql.Blob;
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import _11.asktpk.artisanconnectbackend.Utils.Enums.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@Table(name = "notice")
|
||||||
public class Notice {
|
public class Notice {
|
||||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
@Id
|
||||||
private Long id;
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long idNotice;
|
||||||
|
|
||||||
@Column
|
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@Column
|
@ManyToOne
|
||||||
private String username;
|
@JoinColumn(name = "client_id")
|
||||||
|
private Client client;
|
||||||
|
|
||||||
@Column
|
|
||||||
private String description;
|
private String description;
|
||||||
|
private Double price;
|
||||||
|
|
||||||
public Notice() {
|
@Enumerated(EnumType.STRING)
|
||||||
this.title = "";
|
private Category category;
|
||||||
this.username = "";
|
|
||||||
this.description = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Notice(String nTitle, String nUsername, String nDescription) {
|
@ElementCollection
|
||||||
this.title = nTitle;
|
private List<String> images;
|
||||||
this.username = nUsername;
|
|
||||||
this.description = nDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
@Enumerated(EnumType.STRING)
|
||||||
this.id = id;
|
private Status status;
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
private LocalDate publishDate;
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||||
return username;
|
private List<AttributesNotice> attributesNotices;
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String user) {
|
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||||
this.username = user;
|
private List<Orders> orders;
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||||
return title;
|
private List<Payments> payments;
|
||||||
}
|
|
||||||
|
|
||||||
public void setTitle(String title) {
|
// Getters, setters, and constructors
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,26 +18,26 @@ class ArtisanConnectBackendApplicationTests {
|
|||||||
@Autowired
|
@Autowired
|
||||||
PostgresDatabase postgresDatabase;
|
PostgresDatabase postgresDatabase;
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
void testPostgresDatabase() {
|
// void testPostgresDatabase() {
|
||||||
postgresDatabase.add(new Notice("Test Notice", "Username", "Test Description"));
|
// postgresDatabase.add(new Notice("Test Notice", "Username", "Test Description"));
|
||||||
Boolean isRecordAvailable = postgresDatabase.get().size() > 0;
|
// Boolean isRecordAvailable = postgresDatabase.get().size() > 0;
|
||||||
if(isRecordAvailable) {
|
// if(isRecordAvailable) {
|
||||||
logger.info("The record is available in the database");
|
// logger.info("The record is available in the database");
|
||||||
} else {
|
// } else {
|
||||||
logger.error("The record is not available in the database");
|
// logger.error("The record is not available in the database");
|
||||||
}
|
// }
|
||||||
assert isRecordAvailable;
|
// assert isRecordAvailable;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
void getAllNotices() throws IOException {
|
// void getAllNotices() throws IOException {
|
||||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
// OkHttpClient client = new OkHttpClient().newBuilder()
|
||||||
.build();
|
// .build();
|
||||||
MediaType mediaType = MediaType.parse("text/plain");
|
// MediaType mediaType = MediaType.parse("text/plain");
|
||||||
Request request = new Request.Builder()
|
// Request request = new Request.Builder()
|
||||||
.url("http://localhost:8080/api/v1/notices/all")
|
// .url("http://localhost:8080/api/v1/notices/all")
|
||||||
.build();
|
// .build();
|
||||||
Response response = client.newCall(request).execute();
|
// Response response = client.newCall(request).execute();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user