Compare commits
2 Commits
initWishli
...
71fdf1640a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71fdf1640a | ||
|
|
1d55f40753 |
@@ -106,4 +106,15 @@ public class NoticeController {
|
|||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/boost/{id}")
|
||||||
|
public ResponseEntity boostNotice(@PathVariable("id") long id) {
|
||||||
|
long clientId = 1L;
|
||||||
|
if (!noticeService.isNoticeOwnedByClient(id, clientId)) {
|
||||||
|
throw new EntityNotFoundException("Ogłoszenie nie istnieje lub nie należy do zalogowanego klienta.");
|
||||||
|
}
|
||||||
|
noticeService.boostNotice(id);
|
||||||
|
|
||||||
|
return ResponseEntity.ok("Ogłoszenie zostało pomyślnie wypromowane.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,25 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.entities;
|
package _11.asktpk.artisanconnectbackend.entities;
|
||||||
|
|
||||||
|
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||||
import _11.asktpk.artisanconnectbackend.utils.Enums.Status;
|
import _11.asktpk.artisanconnectbackend.utils.Enums.Status;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "orders")
|
@Table(name = "orders")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
public class Orders {
|
public class Orders {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long idOrder;
|
private Long id;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "id_user")
|
@JoinColumn(name = "id_client")
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@@ -20,7 +27,18 @@ public class Orders {
|
|||||||
private Notice notice;
|
private Notice notice;
|
||||||
|
|
||||||
@Enumerated(EnumType.STRING)
|
@Enumerated(EnumType.STRING)
|
||||||
private Status status;
|
@Column(nullable = false)
|
||||||
|
private Enums.OrderType orderType;
|
||||||
|
|
||||||
// Getters, setters, and constructors
|
@Enumerated(EnumType.STRING)
|
||||||
|
@Column(nullable = false)
|
||||||
|
private Enums.OrderStatus status;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private Double amount;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,4 +5,7 @@ import _11.asktpk.artisanconnectbackend.entities.Notice;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface NoticeRepository extends JpaRepository<Notice, Long> {
|
public interface NoticeRepository extends JpaRepository<Notice, Long> {
|
||||||
|
|
||||||
|
boolean existsByIdNoticeAndClientId(long noticeId, long clientId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
|||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -119,4 +120,20 @@ public class NoticeService {
|
|||||||
throw new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id);
|
throw new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isNoticeOwnedByClient(long noticeId, long clientId) {
|
||||||
|
return noticeRepository.existsByIdNoticeAndClientId(noticeId, clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void boostNotice(long noticeId) {
|
||||||
|
Notice notice = noticeRepository.findById(noticeId)
|
||||||
|
.orElseThrow(() -> new EntityNotFoundException("Ogłoszenie o ID " + noticeId + " nie istnieje."));
|
||||||
|
|
||||||
|
notice.setPublishDate(LocalDateTime.now());
|
||||||
|
|
||||||
|
noticeRepository.save(notice);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,4 +43,20 @@ public class Enums {
|
|||||||
public enum Status {
|
public enum Status {
|
||||||
ACTIVE, INACTIVE
|
ACTIVE, INACTIVE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum OrderType {
|
||||||
|
ACTIVATION,
|
||||||
|
BOOST
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public enum OrderStatus {
|
||||||
|
PENDING, COMPLETED, CANCELLED
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum PaymentStatus{
|
||||||
|
PENDING, CORRECT, INCORRECT
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,3 +17,6 @@ spring.jpa.hibernate.ddl-auto=create-drop
|
|||||||
file.upload-dir=/Users/andsol/Desktop/uploads
|
file.upload-dir=/Users/andsol/Desktop/uploads
|
||||||
spring.servlet.multipart.max-file-size=10MB
|
spring.servlet.multipart.max-file-size=10MB
|
||||||
spring.servlet.multipart.max-request-size=10MB
|
spring.servlet.multipart.max-request-size=10MB
|
||||||
|
|
||||||
|
tpay.clientId = 01JQKC048X62ST9V59HNRSXD92-01JQKC2CQHPYXQFSFX8BKC24BX
|
||||||
|
tpay.secret = e701f2feee2b9c967bf3e67a4e71c76377701f4b1e9d92f6af2e75c97e7df210
|
||||||
|
|||||||
Reference in New Issue
Block a user