Compare commits
17 Commits
initWishli
...
MailSender
| Author | SHA1 | Date | |
|---|---|---|---|
| 62a5ad1bc6 | |||
| 8ea5d84779 | |||
| a09603f8cb | |||
| 45c607060a | |||
| 0b85fed4b8 | |||
| d2163e1601 | |||
| f4c8177270 | |||
|
|
9b64dc8da8 | ||
|
|
12cb37127b | ||
|
|
281cc627de | ||
|
|
6363f966f6 | ||
|
|
c642f6f87b | ||
|
|
65524d0f25 | ||
|
|
71fdf1640a | ||
| 8fae9f1e55 | |||
| d869a18901 | |||
|
|
1d55f40753 |
39
pom.xml
39
pom.xml
@@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<groupId>_11.asktpk</groupId>
|
||||
<artifactId>ArtisanConnectBackend</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>1.0.0</version>
|
||||
<name>ArtisanConnectBackend</name>
|
||||
<description>ArtisanConnectBackend</description>
|
||||
<url/>
|
||||
@@ -34,31 +34,16 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-oauth2-client</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-docker-compose</artifactId>-->
|
||||
<!-- <scope>runtime</scope>-->
|
||||
<!-- <optional>true</optional>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
@@ -73,15 +58,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.security</groupId>-->
|
||||
<!-- <artifactId>spring-security-test</artifactId>-->
|
||||
<!-- <scope>test</scope>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.9.3</version>
|
||||
<version>4.12.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
@@ -93,11 +73,16 @@
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springdoc</groupId>-->
|
||||
<!-- <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>-->
|
||||
<!-- <version>2.8.5</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
<version>3.3.4</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package _11.asktpk.artisanconnectbackend.controller;
|
||||
import _11.asktpk.artisanconnectbackend.dto.EmailDTO;
|
||||
import _11.asktpk.artisanconnectbackend.service.EmailService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/email")
|
||||
public class EmailController {
|
||||
private final EmailService emailService;
|
||||
|
||||
public EmailController(EmailService emailService) {
|
||||
this.emailService = emailService;
|
||||
}
|
||||
|
||||
@PostMapping("/send")
|
||||
public ResponseEntity<String> sendEmail(@RequestBody EmailDTO email) {
|
||||
try {
|
||||
emailService.sendEmail(email);
|
||||
return ResponseEntity.ok("Email wysłany pomyślnie");
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(500).body("Błąd podczas wysyłania emaila");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package _11.asktpk.artisanconnectbackend.controller;
|
||||
import _11.asktpk.artisanconnectbackend.dto.RequestResponseDTO;
|
||||
import _11.asktpk.artisanconnectbackend.service.ImageService;
|
||||
import _11.asktpk.artisanconnectbackend.service.NoticeService;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -63,18 +64,17 @@ public class ImageController {
|
||||
}
|
||||
|
||||
@GetMapping("/list/{id}")
|
||||
public ResponseEntity<List<String>> getImagesNamesList(@PathVariable("id") Long noticeId) {
|
||||
if(noticeId == null) {
|
||||
return ResponseEntity.badRequest().body(Collections.singletonList("Notice ID is invalid or does not exist."));
|
||||
}
|
||||
|
||||
public ResponseEntity<?> getImagesNamesList(@PathVariable("id") Long noticeId) {
|
||||
List<String> result;
|
||||
try {
|
||||
noticeService.getNoticeById(noticeId);
|
||||
result = imageService.getImagesList(noticeId);
|
||||
return ResponseEntity.ok(result);
|
||||
} catch (EntityNotFoundException e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RequestResponseDTO(e.getMessage()));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(Collections.singletonList(e.getMessage()));
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new RequestResponseDTO(e.getMessage()));
|
||||
}
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{filename}")
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package _11.asktpk.artisanconnectbackend.controller;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeAdditionDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeBoostDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.RequestResponseDTO;
|
||||
import _11.asktpk.artisanconnectbackend.service.ClientService;
|
||||
import _11.asktpk.artisanconnectbackend.service.NoticeService;
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||
@@ -29,7 +31,7 @@ public class NoticeController {
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public ResponseEntity getNoticeById(@PathVariable long id) {
|
||||
public ResponseEntity<?> getNoticeById(@PathVariable long id) {
|
||||
if (noticeService.noticeExists(id)) {
|
||||
return ResponseEntity.ok(noticeService.getNoticeById(id));
|
||||
} else {
|
||||
@@ -98,12 +100,22 @@ public class NoticeController {
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ResponseEntity deleteNotice(@PathVariable("id") long id) {
|
||||
public ResponseEntity<RequestResponseDTO> deleteNotice(@PathVariable("id") long id) {
|
||||
if (noticeService.noticeExists(id)) {
|
||||
noticeService.deleteNotice(id);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new RequestResponseDTO("Pomyślnie usunięto ogłoszenie o ID: " + id));
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new RequestResponseDTO("Nie znaleziono ogłoszenia o ID: " + id));
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/boost/{id}")
|
||||
public ResponseEntity<RequestResponseDTO> boostNotice(@PathVariable("id") long clientId, @RequestBody NoticeBoostDTO dto) {
|
||||
if (!noticeService.isNoticeOwnedByClient(dto.getNoticeId(), clientId)) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new RequestResponseDTO("Ogłoszenie nie istnieje lub nie należy do zalogowanego klienta."));
|
||||
}
|
||||
noticeService.boostNotice(dto.getNoticeId());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new RequestResponseDTO("Ogłoszenie zostało pomyślnie wypromowane."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package _11.asktpk.artisanconnectbackend.controller;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.dto.*;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Order;
|
||||
import _11.asktpk.artisanconnectbackend.service.ClientService;
|
||||
import _11.asktpk.artisanconnectbackend.service.OrderService;
|
||||
import _11.asktpk.artisanconnectbackend.service.PaymentService;
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/orders")
|
||||
public class OrderController {
|
||||
|
||||
private final OrderService orderService;
|
||||
private final PaymentService paymentService;
|
||||
|
||||
public OrderController(OrderService orderService, PaymentService paymentService) {
|
||||
this.orderService = orderService;
|
||||
this.paymentService = paymentService;
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity addClient(@RequestBody OrderDTO orderDTO) {
|
||||
return new ResponseEntity<>(orderService.addOrder(orderDTO), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping("/changeStatus")
|
||||
public ResponseEntity changeStatus(@RequestBody OrderStatusDTO orderStatusDTO) {
|
||||
return new ResponseEntity<>(orderService.changeOrderStatus(orderStatusDTO.getId(),orderStatusDTO.getStatus()), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/token")
|
||||
public ResponseEntity<?> fetchToken() {
|
||||
Order order = orderService.getOrderById(1L);
|
||||
OAuthPaymentResponseDTO authPaymentDTO= paymentService.getOAuthToken();
|
||||
TransactionPaymentRequestDTO.Payer payer = new TransactionPaymentRequestDTO.Payer(
|
||||
"patryk@test.pl", "Patryk Test");
|
||||
|
||||
String paymentDescription = order.getOrderType() == Enums.OrderType.ACTIVATION ? "Aktywacja ogłoszenia" : "Podbicie ogłoszenia";
|
||||
paymentDescription += order.getNotice().getTitle();
|
||||
TransactionPaymentRequestDTO request = new TransactionPaymentRequestDTO(
|
||||
order.getAmount(), paymentDescription, payer);
|
||||
|
||||
String response = paymentService.createTransaction(order,authPaymentDTO.getAccess_token(), request);
|
||||
System.out.println(response);
|
||||
System.out.println(request);
|
||||
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package _11.asktpk.artisanconnectbackend.controller;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.entities.Notice;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Order;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Payment;
|
||||
import _11.asktpk.artisanconnectbackend.repository.PaymentRepository;
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.DigestUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/payments")
|
||||
public class PaymentController {
|
||||
|
||||
@Value("${tpay.securityCode}")
|
||||
private String sellerSecurityCode;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(PaymentController.class);
|
||||
|
||||
private final PaymentRepository paymentRepository;
|
||||
|
||||
public PaymentController(PaymentRepository paymentRepository) {
|
||||
this.paymentRepository = paymentRepository;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/notification", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
public ResponseEntity<String> handleTpayNotification(@RequestParam Map<String, String> params) {
|
||||
log.info("=== ODEBRANO NOTYFIKACJĘ Tpay ===");
|
||||
log.info("Parametry:\n{}", paramsToLogString(params));
|
||||
|
||||
String id = params.get("id");
|
||||
String trId = params.get("tr_id");
|
||||
String trAmount = params.get("tr_amount");
|
||||
String trCrc = params.get("tr_crc");
|
||||
String md5sum = params.get("md5sum");
|
||||
String trStatus = params.get("tr_status");
|
||||
|
||||
String expectedMd5 = DigestUtils.md5DigestAsHex(
|
||||
(id + trId + trAmount + trCrc + sellerSecurityCode).getBytes()
|
||||
);
|
||||
|
||||
if (!expectedMd5.equals(md5sum)) {
|
||||
log.warn("❌ Błędna suma kontrolna! Otrzymano: {}, Oczekiwano: {}", md5sum, expectedMd5);
|
||||
return ResponseEntity.status(400).body("INVALID CHECKSUM");
|
||||
}
|
||||
|
||||
Optional<Payment> optionalPayment = paymentRepository.findByTransactionId(trId);
|
||||
if (optionalPayment.isPresent()) {
|
||||
Payment payment = optionalPayment.get();
|
||||
|
||||
if ("true".equalsIgnoreCase(trStatus) || "PAID".equalsIgnoreCase(trStatus)) {
|
||||
log.info("✅ Transakcja opłacona: tr_id={}, kwota={}", trId, params.get("tr_paid"));
|
||||
payment.setStatus(Enums.PaymentStatus.CORRECT);
|
||||
|
||||
if (payment.getOrder() != null) {
|
||||
Order order = payment.getOrder();
|
||||
order.setStatus(Enums.OrderStatus.COMPLETED);
|
||||
Notice notice = order.getNotice();
|
||||
if (order.getOrderType() == Enums.OrderType.ACTIVATION) {
|
||||
notice.setStatus(Enums.Status.ACTIVE);
|
||||
} else if (order.getOrderType() == Enums.OrderType.BOOST) {
|
||||
notice.setPublishDate(LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
|
||||
} else if ("false".equalsIgnoreCase(trStatus)) {
|
||||
log.warn("❌ Transakcja nieudana: {}", trId);
|
||||
payment.setStatus(Enums.PaymentStatus.INCORRECT);
|
||||
|
||||
if (payment.getOrder() != null) {
|
||||
payment.getOrder().setStatus(Enums.OrderStatus.CANCELLED);
|
||||
}
|
||||
}
|
||||
|
||||
paymentRepository.save(payment);
|
||||
} else {
|
||||
log.warn("⚠️ Brak płatności o tr_id={}", trId);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok("TRUE");
|
||||
}
|
||||
|
||||
private String paramsToLogString(Map<String, String> params) {
|
||||
return params.entrySet().stream()
|
||||
.map(e -> e.getKey() + " = " + e.getValue())
|
||||
.collect(Collectors.joining("\n"));
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,10 @@ public class WishlistController {
|
||||
this.noticeService = noticeService;
|
||||
}
|
||||
|
||||
@PostMapping("/toggle")
|
||||
public ResponseEntity<RequestResponseDTO> toggleWishlist(@RequestBody WishlistDTO wishlistDTO) {
|
||||
Long noticeId = wishlistDTO.getNoticeId();
|
||||
Long clientId = wishlistDTO.getClientId();
|
||||
@PostMapping("/toggle/{noticeId}")
|
||||
public ResponseEntity<RequestResponseDTO> toggleWishlist(@PathVariable Long noticeId) {
|
||||
|
||||
Long clientId = 1L;
|
||||
NoticeDTO noticeDTO = noticeService.getNoticeById(noticeId);
|
||||
if (noticeDTO == null) {
|
||||
return ResponseEntity.badRequest().body(new RequestResponseDTO("Notice not found"));
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class EmailDTO {
|
||||
@Email(message = "Podaj poprawny adres email")
|
||||
@NotBlank(message = "Adres email nie może być pusty")
|
||||
private String to;
|
||||
|
||||
@NotBlank(message = "Temat nie może być pusty")
|
||||
private String subject;
|
||||
|
||||
@NotBlank(message = "Treść nie może być pusta")
|
||||
private String body;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter
|
||||
public class NoticeBoostDTO {
|
||||
private Long noticeId;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class OAuthPaymentResponseDTO {
|
||||
private long issued_at;
|
||||
private String scope;
|
||||
private String token_type;
|
||||
private int expires_in;
|
||||
private String client_id;
|
||||
private String access_token;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class OrderDTO {
|
||||
private Long clientId;
|
||||
private Long noticeId;
|
||||
private Enums.OrderType orderType;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter
|
||||
public class OrderStatusDTO {
|
||||
public long id;
|
||||
public Enums.OrderStatus status;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
public class TransactionPaymentRequestDTO {
|
||||
private double amount;
|
||||
private String description;
|
||||
private Payer payer;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class Payer {
|
||||
private String email;
|
||||
private String name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class TransactionPaymentResponseDTO {
|
||||
private String result;
|
||||
private String requestId;
|
||||
private String transactionId;
|
||||
private String title;
|
||||
private String posId;
|
||||
private String status;
|
||||
private DateInfo date;
|
||||
private double amount;
|
||||
private String currency;
|
||||
private String description;
|
||||
private String hiddenDescription;
|
||||
private Payer payer;
|
||||
private Payments payments;
|
||||
private String transactionPaymentUrl;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class DateInfo {
|
||||
private String creation;
|
||||
private String realization;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Payer {
|
||||
private String payerId;
|
||||
private String email;
|
||||
private String name;
|
||||
private String phone;
|
||||
private String address;
|
||||
private String city;
|
||||
private String country;
|
||||
private String postalCode;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Payments {
|
||||
private String status;
|
||||
private String method;
|
||||
private double amountPaid;
|
||||
private DateInfo date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "YourClassName{" +
|
||||
"result='" + result + '\'' +
|
||||
", requestId='" + requestId + '\'' +
|
||||
", transactionId='" + transactionId + '\'' +
|
||||
", title='" + title + '\'' +
|
||||
", posId='" + posId + '\'' +
|
||||
", status='" + status + '\'' +
|
||||
", date=" + date +
|
||||
", amount=" + amount +
|
||||
", currency='" + currency + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", hiddenDescription='" + hiddenDescription + '\'' +
|
||||
", payer=" + payer +
|
||||
", payments=" + payments +
|
||||
", transactionPaymentUrl='" + transactionPaymentUrl + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -33,5 +33,5 @@ public class Client {
|
||||
// private List<Notice> notices;
|
||||
|
||||
@OneToMany(mappedBy = "client", cascade = CascadeType.ALL)
|
||||
private List<Orders> orders;
|
||||
private List<Order> orders;
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ public class Notice {
|
||||
private List<AttributesNotice> attributesNotices;
|
||||
|
||||
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||
private List<Orders> orders;
|
||||
private List<Order> orders;
|
||||
|
||||
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||
private List<Payments> payments;
|
||||
// @OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||
// private List<Payment> payment;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package _11.asktpk.artisanconnectbackend.entities;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "orders")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Order {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "id_client")
|
||||
private Client client;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "id_notice")
|
||||
private Notice notice;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(nullable = false)
|
||||
private Enums.OrderType orderType;
|
||||
|
||||
@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;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package _11.asktpk.artisanconnectbackend.entities;
|
||||
|
||||
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.entities;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "payment")
|
||||
@Getter @Setter
|
||||
public class Payment {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long idPayment;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "id_order")
|
||||
private Order order;
|
||||
|
||||
private Double amount;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(nullable = false)
|
||||
private Enums.PaymentStatus status;
|
||||
|
||||
private String transactionPaymentUrl;
|
||||
|
||||
private String transactionId;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package _11.asktpk.artisanconnectbackend.entities;
|
||||
|
||||
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
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package _11.asktpk.artisanconnectbackend.repository;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.entities.Order;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface OrderRepository extends JpaRepository<Order, Long> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package _11.asktpk.artisanconnectbackend.repository;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.entities.Payment;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
||||
Optional<Payment> findByTransactionId(String transactionId);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package _11.asktpk.artisanconnectbackend.service;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.dto.EmailDTO;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class EmailService {
|
||||
private final JavaMailSender mailSender;
|
||||
|
||||
public EmailService(JavaMailSender mailSender) {
|
||||
this.mailSender = mailSender;
|
||||
}
|
||||
|
||||
public void sendEmail(EmailDTO email) {
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
message.setTo(email.getTo());
|
||||
message.setSubject(email.getSubject());
|
||||
message.setText(email.getBody());
|
||||
message.setFrom("patryk.kania001@gmail.com");
|
||||
mailSender.send(message);
|
||||
}
|
||||
}
|
||||
@@ -5,25 +5,34 @@ import _11.asktpk.artisanconnectbackend.entities.Notice;
|
||||
import _11.asktpk.artisanconnectbackend.repository.ClientRepository;
|
||||
import _11.asktpk.artisanconnectbackend.repository.NoticeRepository;
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||
//import _11.asktpk.artisanconnectbackend.service.WishlistService;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class NoticeService {
|
||||
private static final Logger logger = LogManager.getLogger(NoticeService.class);
|
||||
|
||||
@Value("${file.upload-dir}")
|
||||
private String uploadDir;
|
||||
|
||||
private final NoticeRepository noticeRepository;
|
||||
private final ClientRepository clientRepository;
|
||||
private final WishlistService wishlistService;
|
||||
private final ImageService imageService;
|
||||
|
||||
public NoticeService(NoticeRepository noticeRepository, ClientRepository clientRepository, WishlistService wishlistService) {
|
||||
public NoticeService(NoticeRepository noticeRepository, ClientRepository clientRepository, WishlistService wishlistService, ImageService imageService) {
|
||||
this.noticeRepository = noticeRepository;
|
||||
this.clientRepository = clientRepository;
|
||||
this.wishlistService = wishlistService;
|
||||
this.imageService = imageService;
|
||||
}
|
||||
|
||||
public Notice fromDTO(NoticeDTO dto) {
|
||||
@@ -115,8 +124,40 @@ public class NoticeService {
|
||||
public void deleteNotice(Long id) {
|
||||
if (noticeExists(id)) {
|
||||
noticeRepository.deleteById(id);
|
||||
|
||||
List<String> imagesList = new ArrayList<>();
|
||||
|
||||
try {
|
||||
imagesList = imageService.getImagesList(id);
|
||||
} catch (Exception e) {
|
||||
logger.info("There weren't any images for notice with ID: " + id + ". Skipping deletion of images. Message: " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
for (String imageName : imagesList) {
|
||||
imageService.deleteImage(uploadDir, imageName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("There were some issues while deleting images for notice with ID: " + id + ". Message: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package _11.asktpk.artisanconnectbackend.service;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.dto.OrderDTO;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Client;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Notice;
|
||||
import _11.asktpk.artisanconnectbackend.repository.ClientRepository;
|
||||
import _11.asktpk.artisanconnectbackend.repository.NoticeRepository;
|
||||
import _11.asktpk.artisanconnectbackend.repository.OrderRepository;
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Order;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
public class OrderService {
|
||||
|
||||
private final OrderRepository orderRepository;
|
||||
private final ClientRepository clientRepository;
|
||||
private final NoticeRepository noticeRepository;
|
||||
|
||||
@Autowired
|
||||
public OrderService(OrderRepository orderRepository, ClientRepository clientRepository, NoticeRepository noticeRepository) {
|
||||
this.orderRepository = orderRepository;
|
||||
this.clientRepository = clientRepository;
|
||||
this.noticeRepository = noticeRepository;
|
||||
}
|
||||
|
||||
public Order fromDTO(OrderDTO orderDTO) {
|
||||
Order order = new Order();
|
||||
order.setOrderType(orderDTO.getOrderType());
|
||||
order.setStatus(Enums.OrderStatus.PENDING);
|
||||
if(orderDTO.getOrderType() == Enums.OrderType.ACTIVATION){
|
||||
order.setAmount(10.00);
|
||||
}else{
|
||||
order.setAmount(8.00);
|
||||
}
|
||||
|
||||
order.setCreatedAt(LocalDateTime.now()
|
||||
);
|
||||
order.setUpdatedAt(LocalDateTime.now()
|
||||
);
|
||||
|
||||
Client client = clientRepository.findById(orderDTO.getClientId())
|
||||
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono klienta o ID: " + orderDTO.getClientId()));
|
||||
order.setClient(client);
|
||||
|
||||
Notice notice = noticeRepository.findById(orderDTO.getNoticeId())
|
||||
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + orderDTO.getNoticeId()));
|
||||
order.setNotice(notice);
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
|
||||
public Long addOrder(OrderDTO orderDTO) {
|
||||
Order order = fromDTO(orderDTO);
|
||||
return orderRepository.save(order).getId();
|
||||
}
|
||||
|
||||
public Long changeOrderStatus(Long id, Enums.OrderStatus status) {
|
||||
Order order = orderRepository.findById(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Nie znaleziono zamówienia o ID: " + id));
|
||||
|
||||
order.setStatus(status);
|
||||
|
||||
order = orderRepository.save(order);
|
||||
|
||||
return order.getId();
|
||||
|
||||
}
|
||||
|
||||
public Order getOrderById(Long id) {
|
||||
return orderRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Nie znaleziono zamówienia o ID: " + id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package _11.asktpk.artisanconnectbackend.service;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.dto.OAuthPaymentResponseDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.TransactionPaymentRequestDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.TransactionPaymentResponseDTO;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Order;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Payment;
|
||||
import _11.asktpk.artisanconnectbackend.repository.PaymentRepository;
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Service
|
||||
public class PaymentService {
|
||||
private final WebClient webClient;
|
||||
private final String clientId;
|
||||
private final String clientSecret;
|
||||
private final String authUrl;
|
||||
private final String transactionUrl;
|
||||
private final PaymentRepository paymentRepository;
|
||||
|
||||
public PaymentService(
|
||||
WebClient.Builder webClientBuilder,
|
||||
@Value("${tpay.clientId}") String clientId,
|
||||
@Value("${tpay.clientSecret}") String clientSecret,
|
||||
@Value("${tpay.authUrl}") String authUrl,
|
||||
@Value("${tpay.transactionUrl}") String transactionUrl,
|
||||
PaymentRepository paymentRepository
|
||||
) {
|
||||
this.webClient = webClientBuilder.baseUrl(authUrl).build();
|
||||
this.clientId = clientId;
|
||||
this.clientSecret = clientSecret;
|
||||
this.authUrl = authUrl;
|
||||
this.transactionUrl = transactionUrl;
|
||||
this.paymentRepository = paymentRepository;
|
||||
}
|
||||
|
||||
public OAuthPaymentResponseDTO getOAuthToken() {
|
||||
return webClient.post()
|
||||
.uri("")
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||
.header("accept", "application/json")
|
||||
.body(BodyInserters.fromMultipartData("client_id", clientId)
|
||||
.with("client_secret", clientSecret))
|
||||
.retrieve()
|
||||
.bodyToMono(OAuthPaymentResponseDTO.class)
|
||||
.block();
|
||||
}
|
||||
|
||||
public String createTransaction(Order order, String accessToken, TransactionPaymentRequestDTO transactionPaymentRequestDTO) {
|
||||
TransactionPaymentResponseDTO response = webClient.post()
|
||||
.uri(transactionUrl)
|
||||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.bodyValue(transactionPaymentRequestDTO)
|
||||
.retrieve()
|
||||
.bodyToMono(TransactionPaymentResponseDTO.class)
|
||||
.block();
|
||||
|
||||
if (response != null && "success".equalsIgnoreCase(response.getResult())) {
|
||||
Payment payment = new Payment();
|
||||
payment.setOrder(order);
|
||||
payment.setAmount(response.getAmount());
|
||||
|
||||
payment.setStatus(Enums.PaymentStatus.PENDING);
|
||||
|
||||
payment.setTransactionId(response.getTitle());
|
||||
payment.setTransactionPaymentUrl(response.getTransactionPaymentUrl());
|
||||
paymentRepository.save(payment);
|
||||
|
||||
System.out.println(response);
|
||||
|
||||
return response.getTransactionPaymentUrl();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -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,20 @@ 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
|
||||
|
||||
spring.mail.host=smtp.gmail.com
|
||||
spring.mail.port=587
|
||||
spring.mail.username=patryk.kania001@gmail.com
|
||||
spring.mail.password=pmyd ylwg mbsn hcpp
|
||||
spring.mail.properties.mail.smtp.auth=true
|
||||
spring.mail.properties.mail.smtp.starttls.enable=true
|
||||
|
||||
tpay.clientId = 01JQKC048X62ST9V59HNRSXD92-01JQKC2CQHPYXQFSFX8BKC24BX
|
||||
tpay.clientSecret = 44898642be53381cdcc47f3e44bf5a15e592f5d270fc3a6cf6fb81a8b8ebffb9
|
||||
tpay.authUrl = https://openapi.sandbox.tpay.com/oauth/auth
|
||||
tpay.transactionUrl = https://openapi.sandbox.tpay.com/transactions
|
||||
tpay.securityCode = )IY7E)YSM!A)Q6O-GN#U7U_33s9qObk8
|
||||
|
||||
logging.file.name=logs/payment-notifications.log
|
||||
logging.level.TpayLogger=INFO
|
||||
|
||||
Reference in New Issue
Block a user