WIP
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
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.Service.PostgresDatabase;
|
import _11.asktpk.artisanconnectbackend.Service.NoticeService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -12,16 +12,18 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
public class ArtisanConnectController {
|
public class ArtisanConnectController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private PostgresDatabase postgresDatabase;
|
private NoticeService noticeService;
|
||||||
|
|
||||||
@GetMapping("/notices/all")
|
@GetMapping("/notices/all")
|
||||||
public List<Notice> getAllNotices() {
|
public List<Notice> getAllNotices() {
|
||||||
return postgresDatabase.get();
|
return noticeService.getAllNotices();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ResponseStatus(HttpStatus.CREATED)
|
@ResponseStatus(HttpStatus.CREATED)
|
||||||
@PostMapping("/notices/add")
|
@PostMapping("/notices/add")
|
||||||
public void addNotice(@RequestBody Notice notice) {
|
public void addNotice(@RequestBody List<Notice> notices_list) {
|
||||||
postgresDatabase.add(notice);
|
for (Notice notice : notices_list) {
|
||||||
|
noticeService.addNotice(notice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,5 +43,101 @@ public class Notice {
|
|||||||
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||||
private List<Payments> payments;
|
private List<Payments> payments;
|
||||||
|
|
||||||
|
public Long getIdNotice() {
|
||||||
|
return idNotice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdNotice(Long idNotice) {
|
||||||
|
this.idNotice = idNotice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Client getClient() {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient(Client client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrice(Double price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Category getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategory(Category category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getImages() {
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImages(List<String> images) {
|
||||||
|
this.images = images;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Status getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Status status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getPublishDate() {
|
||||||
|
return publishDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublishDate(LocalDate publishDate) {
|
||||||
|
this.publishDate = publishDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AttributesNotice> getAttributesNotices() {
|
||||||
|
return attributesNotices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttributesNotices(List<AttributesNotice> attributesNotices) {
|
||||||
|
this.attributesNotices = attributesNotices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Orders> getOrders() {
|
||||||
|
return orders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrders(List<Orders> orders) {
|
||||||
|
this.orders = orders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Payments> getPayments() {
|
||||||
|
return payments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPayments(List<Payments> payments) {
|
||||||
|
this.payments = payments;
|
||||||
|
}
|
||||||
|
|
||||||
// Getters, setters, and constructors
|
// Getters, setters, and constructors
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package _11.asktpk.artisanconnectbackend.Service;
|
||||||
|
|
||||||
|
import _11.asktpk.artisanconnectbackend.Model.Notice;
|
||||||
|
import _11.asktpk.artisanconnectbackend.Repository.NoticeRepository;
|
||||||
|
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class NoticeService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NoticeRepository noticeRepository;
|
||||||
|
|
||||||
|
// private NoticeDTO mapToDTO(Notice notice) {
|
||||||
|
// return new NoticeDTO(
|
||||||
|
//
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private Notice mapToEntity(NoticeDTO productDTO) {
|
||||||
|
// return new Notice(
|
||||||
|
//
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
public List<Notice> getAllNotices() {
|
||||||
|
return noticeRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addNotice(Notice notice) {
|
||||||
|
noticeRepository.save(notice);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
package _11.asktpk.artisanconnectbackend.dto;
|
||||||
|
|
||||||
|
import _11.asktpk.artisanconnectbackend.Model.AttributesNotice;
|
||||||
|
import _11.asktpk.artisanconnectbackend.Model.Client;
|
||||||
|
import _11.asktpk.artisanconnectbackend.Model.Orders;
|
||||||
|
import _11.asktpk.artisanconnectbackend.Model.Payments;
|
||||||
|
import _11.asktpk.artisanconnectbackend.Utils.Enums;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class NoticeDTO {
|
||||||
|
private String title;
|
||||||
|
private Client client;
|
||||||
|
private String description;
|
||||||
|
private Double price;
|
||||||
|
private Enums.Category category;
|
||||||
|
private List<String> images;
|
||||||
|
private Enums.Status status;
|
||||||
|
private LocalDate publishDate;
|
||||||
|
private List<AttributesNotice> attributesNotices;
|
||||||
|
private List<Orders> orders;
|
||||||
|
private List<Payments> payments;
|
||||||
|
|
||||||
|
public NoticeDTO(String title, Client client, String description, Double price,
|
||||||
|
Enums.Category category, List<String> images, Enums.Status status,
|
||||||
|
LocalDate publishDate, List<AttributesNotice> attributesNotices,
|
||||||
|
List<Orders> orders, List<Payments> payments) {
|
||||||
|
this.title = title;
|
||||||
|
this.client = client;
|
||||||
|
this.description = description;
|
||||||
|
this.price = price;
|
||||||
|
this.category = category;
|
||||||
|
this.images = images;
|
||||||
|
this.status = status;
|
||||||
|
this.publishDate = publishDate;
|
||||||
|
this.attributesNotices = attributesNotices;
|
||||||
|
this.orders = orders;
|
||||||
|
this.payments = payments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Client getClient() {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient(Client client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrice(Double price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Enums.Category getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategory(Enums.Category category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getImages() {
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImages(List<String> images) {
|
||||||
|
this.images = images;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Enums.Status getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Enums.Status status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getPublishDate() {
|
||||||
|
return publishDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublishDate(LocalDate publishDate) {
|
||||||
|
this.publishDate = publishDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AttributesNotice> getAttributesNotices() {
|
||||||
|
return attributesNotices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttributesNotices(List<AttributesNotice> attributesNotices) {
|
||||||
|
this.attributesNotices = attributesNotices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Orders> getOrders() {
|
||||||
|
return orders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrders(List<Orders> orders) {
|
||||||
|
this.orders = orders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Payments> getPayments() {
|
||||||
|
return payments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPayments(List<Payments> payments) {
|
||||||
|
this.payments = payments;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user