Compare commits
2 Commits
initWishli
...
71fdf1640a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71fdf1640a | ||
|
|
1d55f40753 |
@@ -106,4 +106,15 @@ public class NoticeController {
|
||||
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;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums.Status;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "orders")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Orders {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long idOrder;
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "id_user")
|
||||
@JoinColumn(name = "id_client")
|
||||
private Client client;
|
||||
|
||||
@ManyToOne
|
||||
@@ -20,7 +27,18 @@ public class Orders {
|
||||
private Notice notice;
|
||||
|
||||
@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;
|
||||
|
||||
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 org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -119,4 +120,20 @@ public class NoticeService {
|
||||
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 {
|
||||
ACTIVE, INACTIVE
|
||||
}
|
||||
|
||||
public enum OrderType {
|
||||
ACTIVATION,
|
||||
BOOST
|
||||
}
|
||||
|
||||
|
||||
public enum OrderStatus {
|
||||
PENDING, COMPLETED, CANCELLED
|
||||
}
|
||||
|
||||
public enum PaymentStatus{
|
||||
PENDING, CORRECT, INCORRECT
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,4 +16,7 @@ spring.jpa.hibernate.ddl-auto=create-drop
|
||||
|
||||
file.upload-dir=/Users/andsol/Desktop/uploads
|
||||
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