Compare commits
3 Commits
fix-paymen
...
3d064e0496
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d064e0496 | |||
| 3b9b0769d1 | |||
| 3e5baa34d1 |
@@ -26,7 +26,7 @@ public class SecurityConfig {
|
|||||||
.cors(cors -> cors.configure(http))
|
.cors(cors -> cors.configure(http))
|
||||||
.csrf(AbstractHttpConfigurer::disable)
|
.csrf(AbstractHttpConfigurer::disable)
|
||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
.requestMatchers("/api/v1/auth/**", "/api/v1/payments/notification").permitAll()
|
.requestMatchers("/api/v1/auth/**").permitAll()
|
||||||
.anyRequest().authenticated())
|
.anyRequest().authenticated())
|
||||||
.sessionManagement(session -> session
|
.sessionManagement(session -> session
|
||||||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
|
.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.controller;
|
package _11.asktpk.artisanconnectbackend.controller;
|
||||||
|
|
||||||
import _11.asktpk.artisanconnectbackend.dto.*;
|
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.ClientService;
|
||||||
import _11.asktpk.artisanconnectbackend.service.NoticeService;
|
import _11.asktpk.artisanconnectbackend.service.NoticeService;
|
||||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||||
import _11.asktpk.artisanconnectbackend.utils.Tools;
|
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RequestMapping("/api/v1/notices")
|
@RequestMapping("/api/v1/notices")
|
||||||
@@ -19,16 +19,14 @@ import java.util.List;
|
|||||||
public class NoticeController {
|
public class NoticeController {
|
||||||
private final NoticeService noticeService;
|
private final NoticeService noticeService;
|
||||||
private final ClientService clientService;
|
private final ClientService clientService;
|
||||||
private final Tools tools;
|
|
||||||
|
|
||||||
public NoticeController(NoticeService noticeService, ClientService clientService, Tools tools) {
|
public NoticeController(NoticeService noticeService, ClientService clientService) {
|
||||||
this.noticeService = noticeService;
|
this.noticeService = noticeService;
|
||||||
this.clientService = clientService;
|
this.clientService = clientService;
|
||||||
this.tools = tools;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/get/all")
|
@GetMapping("/get/all")
|
||||||
public List<NoticeResponseDTO> getAllNotices() {
|
public List<NoticeDTO> getAllNotices() {
|
||||||
return noticeService.getAllNotices();
|
return noticeService.getAllNotices();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,34 +40,57 @@ public class NoticeController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
public ResponseEntity<NoticeAdditionDTO> addNotice(@RequestBody NoticeRequestDTO dto, HttpServletRequest request) {
|
public ResponseEntity<NoticeAdditionDTO> addNotice(@RequestBody NoticeDTO dto) {
|
||||||
Long clientId = tools.getClientIdFromRequest(request);
|
if (!clientService.clientExists(dto.getClientId())) {
|
||||||
if (!clientService.clientExists(clientId)) {
|
|
||||||
return ResponseEntity
|
return ResponseEntity
|
||||||
.status(HttpStatus.BAD_REQUEST)
|
.status(HttpStatus.BAD_REQUEST)
|
||||||
.body(new NoticeAdditionDTO("Nie znaleziono klienta o ID: " + clientId));
|
.body(new NoticeAdditionDTO("Nie znaleziono klienta o ID: " + dto.getClientId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
dto.setClientId(clientId);
|
if (dto.getCategory() == null) {
|
||||||
|
|
||||||
if (dto.getCategory() == null || !Arrays.asList(Enums.Category.values()).contains(dto.getCategory())) {
|
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new NoticeAdditionDTO("Nie ma takiej kategorii"));
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new NoticeAdditionDTO("Nie ma takiej kategorii"));
|
||||||
}
|
}
|
||||||
|
dto.setPublishDate(java.time.LocalDateTime.now());
|
||||||
|
|
||||||
Long newNoticeId = noticeService.addNotice(dto);
|
Long newNoticeId = noticeService.addNotice(dto);
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(new NoticeAdditionDTO(newNoticeId ,"Dodano ogłoszenie."));
|
return ResponseEntity.status(HttpStatus.CREATED).body(new NoticeAdditionDTO(newNoticeId ,"Dodano ogłoszenie."));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/edit/{id}")
|
// TODO: zamiast dodawać tutaj pętlą, musi to robić NoticeService, trzeba zaimplementować odpowienią metodę
|
||||||
public ResponseEntity<Object> editNotice(@PathVariable("id") long id, @RequestBody NoticeRequestDTO dto, HttpServletRequest request) {
|
@PostMapping("/bulk_add")
|
||||||
Long clientIdFromToken = tools.getClientIdFromRequest(request);
|
public ResponseEntity<String> addNotices(@RequestBody List<NoticeDTO> notices_list) {
|
||||||
if (noticeService.noticeExists(id)) {
|
ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.CREATED);
|
||||||
if (!noticeService.isNoticeOwnedByClient(id, clientIdFromToken)) {
|
List<String> errors = new ArrayList<>();
|
||||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new RequestResponseDTO("Nie masz uprawnień do edycji tego ogłoszenia."));
|
boolean isError = false;
|
||||||
|
|
||||||
|
if (notices_list.isEmpty()) {
|
||||||
|
return response.status(HttpStatus.BAD_REQUEST).body("Lista ogłoszeń jest pusta.");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (NoticeDTO dto : notices_list) {
|
||||||
|
if (!clientService.clientExists(dto.getClientId())) {
|
||||||
|
isError = true;
|
||||||
|
errors.add(dto.getClientId().toString());
|
||||||
|
} else {
|
||||||
|
if (!isError) {
|
||||||
|
noticeService.addNotice(dto);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isError) {
|
||||||
|
return response.status(HttpStatus.BAD_REQUEST).body("Nie znaleziono klientów: " + errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/edit/{id}")
|
||||||
|
public ResponseEntity<Object> editNotice(@PathVariable("id") long id, @RequestBody NoticeDTO dto) {
|
||||||
|
if (noticeService.noticeExists(id)) {
|
||||||
try {
|
try {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(noticeService.updateNotice(id, dto));
|
return new ResponseEntity<>(noticeService.updateNotice(id, dto), HttpStatus.OK);
|
||||||
} catch (EntityNotFoundException e) {
|
} catch (EntityNotFoundException e) {
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -79,13 +100,8 @@ public class NoticeController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public ResponseEntity<RequestResponseDTO> deleteNotice(@PathVariable("id") long id, HttpServletRequest request) {
|
public ResponseEntity<RequestResponseDTO> deleteNotice(@PathVariable("id") long id) {
|
||||||
Long clientIdFromToken = tools.getClientIdFromRequest(request);
|
|
||||||
if (noticeService.noticeExists(id)) {
|
if (noticeService.noticeExists(id)) {
|
||||||
if (!noticeService.isNoticeOwnedByClient(id, clientIdFromToken)) {
|
|
||||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new RequestResponseDTO("Nie masz uprawnień do usunięcia tego ogłoszenia."));
|
|
||||||
}
|
|
||||||
|
|
||||||
noticeService.deleteNotice(id);
|
noticeService.deleteNotice(id);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new RequestResponseDTO("Pomyślnie usunięto ogłoszenie o ID: " + id));
|
return ResponseEntity.status(HttpStatus.OK).body(new RequestResponseDTO("Pomyślnie usunięto ogłoszenie o ID: " + id));
|
||||||
} else {
|
} else {
|
||||||
@@ -93,10 +109,9 @@ public class NoticeController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/boost")
|
@PostMapping("/boost/{id}")
|
||||||
public ResponseEntity<RequestResponseDTO> boostNotice(@RequestBody NoticeBoostDTO dto, HttpServletRequest request) {
|
public ResponseEntity<RequestResponseDTO> boostNotice(@PathVariable("id") long clientId, @RequestBody NoticeBoostDTO dto) {
|
||||||
Long clientId = tools.getClientIdFromRequest(request);
|
if (!noticeService.isNoticeOwnedByClient(dto.getNoticeId(), clientId)) {
|
||||||
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."));
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new RequestResponseDTO("Ogłoszenie nie istnieje lub nie należy do zalogowanego klienta."));
|
||||||
}
|
}
|
||||||
noticeService.boostNotice(dto.getNoticeId());
|
noticeService.boostNotice(dto.getNoticeId());
|
||||||
|
|||||||
@@ -1,129 +1,53 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.controller;
|
package _11.asktpk.artisanconnectbackend.controller;
|
||||||
|
|
||||||
import _11.asktpk.artisanconnectbackend.dto.*;
|
import _11.asktpk.artisanconnectbackend.dto.*;
|
||||||
import _11.asktpk.artisanconnectbackend.entities.Client;
|
|
||||||
import _11.asktpk.artisanconnectbackend.entities.Order;
|
import _11.asktpk.artisanconnectbackend.entities.Order;
|
||||||
import _11.asktpk.artisanconnectbackend.entities.Payment;
|
import _11.asktpk.artisanconnectbackend.service.ClientService;
|
||||||
import _11.asktpk.artisanconnectbackend.service.OrderService;
|
import _11.asktpk.artisanconnectbackend.service.OrderService;
|
||||||
import _11.asktpk.artisanconnectbackend.service.PaymentService;
|
import _11.asktpk.artisanconnectbackend.service.PaymentService;
|
||||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||||
import _11.asktpk.artisanconnectbackend.utils.Tools;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/orders")
|
@RequestMapping("/api/v1/orders")
|
||||||
public class OrderController {
|
public class OrderController {
|
||||||
|
|
||||||
private final OrderService orderService;
|
private final OrderService orderService;
|
||||||
private final PaymentService paymentService;
|
private final PaymentService paymentService;
|
||||||
private final Tools tools;
|
|
||||||
|
|
||||||
public OrderController(OrderService orderService, PaymentService paymentService, Tools tools) {
|
public OrderController(OrderService orderService, PaymentService paymentService) {
|
||||||
this.orderService = orderService;
|
this.orderService = orderService;
|
||||||
this.paymentService = paymentService;
|
this.paymentService = paymentService;
|
||||||
this.tools = tools;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
public ResponseEntity<?> addClient(@RequestBody OrderDTO orderDTO, HttpServletRequest request) {
|
public ResponseEntity addClient(@RequestBody OrderDTO orderDTO) {
|
||||||
orderDTO.setClientId(tools.getClientIdFromRequest(request));
|
return new ResponseEntity<>(orderService.addOrder(orderDTO), HttpStatus.CREATED);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(orderService.addOrder(orderDTO));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/changeStatus")
|
@PutMapping("/changeStatus")
|
||||||
public ResponseEntity<?> changeStatus(@RequestBody OrderStatusDTO orderStatusDTO) {
|
public ResponseEntity changeStatus(@RequestBody OrderStatusDTO orderStatusDTO) {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(orderService.changeOrderStatus(orderStatusDTO.getId(), orderStatusDTO.getStatus()));
|
return new ResponseEntity<>(orderService.changeOrderStatus(orderStatusDTO.getId(),orderStatusDTO.getStatus()), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/token")
|
@PostMapping("/token")
|
||||||
public ResponseEntity<?> fetchToken(HttpServletRequest request,@RequestParam Long orderId) {
|
public ResponseEntity<?> fetchToken() {
|
||||||
Order order = orderService.getOrderById(orderId);
|
Order order = orderService.getOrderById(1L);
|
||||||
Client client = order.getClient();
|
OAuthPaymentResponseDTO authPaymentDTO= paymentService.getOAuthToken();
|
||||||
OAuthPaymentResponseDTO authPaymentDTO = paymentService.getOAuthToken();
|
|
||||||
TransactionPaymentRequestDTO.Payer payer = new TransactionPaymentRequestDTO.Payer(
|
TransactionPaymentRequestDTO.Payer payer = new TransactionPaymentRequestDTO.Payer(
|
||||||
client.getEmail(), client.getFirstName()+' '+client.getLastName());
|
"patryk@test.pl", "Patryk Test");
|
||||||
|
|
||||||
String paymentDescription = order.getOrderType() == Enums.OrderType.ACTIVATION ? "Aktywacja ogłoszenia" : "Podbicie ogłoszenia";
|
String paymentDescription = order.getOrderType() == Enums.OrderType.ACTIVATION ? "Aktywacja ogłoszenia" : "Podbicie ogłoszenia";
|
||||||
paymentDescription += order.getNotice().getTitle();
|
paymentDescription += order.getNotice().getTitle();
|
||||||
TransactionPaymentRequestDTO paymentRequest = new TransactionPaymentRequestDTO(
|
TransactionPaymentRequestDTO request = new TransactionPaymentRequestDTO(
|
||||||
order.getAmount(), paymentDescription, payer);
|
order.getAmount(), paymentDescription, payer);
|
||||||
|
|
||||||
String response = paymentService.createTransaction(order, authPaymentDTO.getAccess_token(), paymentRequest);
|
String response = paymentService.createTransaction(order,authPaymentDTO.getAccess_token(), request);
|
||||||
|
System.out.println(response);
|
||||||
|
System.out.println(request);
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/get/all")
|
|
||||||
public ResponseEntity<List<OrderWithPaymentsDTO>> getOrders(HttpServletRequest request) {
|
|
||||||
Long clientId = tools.getClientIdFromRequest(request);
|
|
||||||
List<Order> orders = orderService.getOrdersByClientId(clientId);
|
|
||||||
|
|
||||||
List<OrderWithPaymentsDTO> dtoList = orders.stream().map(order -> {
|
|
||||||
OrderWithPaymentsDTO dto = new OrderWithPaymentsDTO();
|
|
||||||
dto.setOrderId(order.getId());
|
|
||||||
dto.setOrderType(order.getOrderType().name());
|
|
||||||
dto.setStatus(order.getStatus().name());
|
|
||||||
dto.setAmount(order.getAmount());
|
|
||||||
dto.setCreatedAt(order.getCreatedAt());
|
|
||||||
|
|
||||||
List<Payment> payments = paymentService.getPaymentsByOrderId(order.getId());
|
|
||||||
|
|
||||||
List<PaymentDTO> paymentDTOs = payments.stream().map(payment -> {
|
|
||||||
PaymentDTO pDto = new PaymentDTO();
|
|
||||||
pDto.setPaymentId(payment.getIdPayment());
|
|
||||||
pDto.setAmount(payment.getAmount());
|
|
||||||
pDto.setStatus(payment.getStatus().name());
|
|
||||||
pDto.setTransactionPaymentUrl(payment.getTransactionPaymentUrl());
|
|
||||||
pDto.setTransactionId(payment.getTransactionId());
|
|
||||||
return pDto;
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
dto.setPayments(paymentDTOs);
|
|
||||||
return dto;
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
return ResponseEntity.ok(dtoList);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/get/{orderId}")
|
|
||||||
public ResponseEntity<OrderWithPaymentsDTO> getOrderById(HttpServletRequest request,
|
|
||||||
@PathVariable Long orderId) {
|
|
||||||
Long clientId = tools.getClientIdFromRequest(request);
|
|
||||||
|
|
||||||
Order order = orderService.getOrderById(orderId);
|
|
||||||
|
|
||||||
if (!order.getClient().getId().equals(clientId)) {
|
|
||||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
OrderWithPaymentsDTO dto = new OrderWithPaymentsDTO();
|
|
||||||
dto.setOrderId(order.getId());
|
|
||||||
dto.setOrderType(order.getOrderType().name());
|
|
||||||
dto.setStatus(order.getStatus().name());
|
|
||||||
dto.setAmount(order.getAmount());
|
|
||||||
dto.setCreatedAt(order.getCreatedAt());
|
|
||||||
|
|
||||||
List<Payment> payments = paymentService.getPaymentsByOrderId(order.getId());
|
|
||||||
List<PaymentDTO> paymentDTOs = payments.stream().map(payment -> {
|
|
||||||
PaymentDTO pDto = new PaymentDTO();
|
|
||||||
pDto.setPaymentId(payment.getIdPayment());
|
|
||||||
pDto.setAmount(payment.getAmount());
|
|
||||||
pDto.setStatus(payment.getStatus().name());
|
|
||||||
pDto.setTransactionPaymentUrl(payment.getTransactionPaymentUrl());
|
|
||||||
pDto.setTransactionId(payment.getTransactionId());
|
|
||||||
return pDto;
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
dto.setPayments(paymentDTOs);
|
|
||||||
|
|
||||||
return ResponseEntity.ok(dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ public class PaymentController {
|
|||||||
|
|
||||||
@PostMapping(value = "/notification", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
@PostMapping(value = "/notification", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||||
public ResponseEntity<String> handleTpayNotification(@RequestParam Map<String, String> params) {
|
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 id = params.get("id");
|
||||||
String trId = params.get("tr_id");
|
String trId = params.get("tr_id");
|
||||||
String trAmount = params.get("tr_amount");
|
String trAmount = params.get("tr_amount");
|
||||||
@@ -51,6 +54,7 @@ public class PaymentController {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!expectedMd5.equals(md5sum)) {
|
if (!expectedMd5.equals(md5sum)) {
|
||||||
|
log.warn("❌ Błędna suma kontrolna! Otrzymano: {}, Oczekiwano: {}", md5sum, expectedMd5);
|
||||||
return ResponseEntity.status(400).body("INVALID CHECKSUM");
|
return ResponseEntity.status(400).body("INVALID CHECKSUM");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +63,7 @@ public class PaymentController {
|
|||||||
Payment payment = optionalPayment.get();
|
Payment payment = optionalPayment.get();
|
||||||
|
|
||||||
if ("true".equalsIgnoreCase(trStatus) || "PAID".equalsIgnoreCase(trStatus)) {
|
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);
|
payment.setStatus(Enums.PaymentStatus.CORRECT);
|
||||||
|
|
||||||
if (payment.getOrder() != null) {
|
if (payment.getOrder() != null) {
|
||||||
@@ -73,6 +78,7 @@ public class PaymentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if ("false".equalsIgnoreCase(trStatus)) {
|
} else if ("false".equalsIgnoreCase(trStatus)) {
|
||||||
|
log.warn("❌ Transakcja nieudana: {}", trId);
|
||||||
payment.setStatus(Enums.PaymentStatus.INCORRECT);
|
payment.setStatus(Enums.PaymentStatus.INCORRECT);
|
||||||
|
|
||||||
if (payment.getOrder() != null) {
|
if (payment.getOrder() != null) {
|
||||||
@@ -81,7 +87,10 @@ public class PaymentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
paymentRepository.save(payment);
|
paymentRepository.save(payment);
|
||||||
|
} else {
|
||||||
|
log.warn("⚠️ Brak płatności o tr_id={}", trId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResponseEntity.ok("TRUE");
|
return ResponseEntity.ok("TRUE");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,35 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.controller;
|
package _11.asktpk.artisanconnectbackend.controller;
|
||||||
|
|
||||||
import _11.asktpk.artisanconnectbackend.dto.NoticeResponseDTO;
|
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||||
import _11.asktpk.artisanconnectbackend.dto.RequestResponseDTO;
|
import _11.asktpk.artisanconnectbackend.dto.RequestResponseDTO;
|
||||||
|
import _11.asktpk.artisanconnectbackend.dto.WishlistDTO;
|
||||||
import _11.asktpk.artisanconnectbackend.service.ClientService;
|
import _11.asktpk.artisanconnectbackend.service.ClientService;
|
||||||
import _11.asktpk.artisanconnectbackend.service.NoticeService;
|
import _11.asktpk.artisanconnectbackend.service.NoticeService;
|
||||||
import _11.asktpk.artisanconnectbackend.service.WishlistService;
|
import _11.asktpk.artisanconnectbackend.service.WishlistService;
|
||||||
import _11.asktpk.artisanconnectbackend.utils.Tools;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/wishlist")
|
@RequestMapping("/api/v1/wishlist")
|
||||||
public class WishlistController {
|
public class WishlistController {
|
||||||
private final WishlistService wishlistService;
|
private final WishlistService wishlistService;
|
||||||
private final ClientService clientService;
|
private final ClientService clientService;
|
||||||
private final NoticeService noticeService;
|
private final NoticeService noticeService;
|
||||||
private final Tools tools;
|
|
||||||
|
|
||||||
public WishlistController(WishlistService wishlistService, ClientService clientService, NoticeService noticeService, Tools tools) {
|
public WishlistController(WishlistService wishlistService, ClientService clientService, NoticeService noticeService) {
|
||||||
this.wishlistService = wishlistService;
|
this.wishlistService = wishlistService;
|
||||||
this.clientService = clientService;
|
this.clientService = clientService;
|
||||||
this.noticeService = noticeService;
|
this.noticeService = noticeService;
|
||||||
this.tools = tools;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/toggle/{noticeId}")
|
@PostMapping("/toggle/{noticeId}")
|
||||||
public ResponseEntity<RequestResponseDTO> toggleWishlist(@PathVariable Long noticeId, HttpServletRequest request) {
|
public ResponseEntity<RequestResponseDTO> toggleWishlist(@PathVariable Long noticeId) {
|
||||||
Long clientId = tools.getClientIdFromRequest(request);
|
|
||||||
NoticeResponseDTO noticeResponseDTO = noticeService.getNoticeById(noticeId);
|
Long clientId = 1L;
|
||||||
if (noticeResponseDTO == null) {
|
NoticeDTO noticeDTO = noticeService.getNoticeById(noticeId);
|
||||||
|
if (noticeDTO == null) {
|
||||||
return ResponseEntity.badRequest().body(new RequestResponseDTO("Notice not found"));
|
return ResponseEntity.badRequest().body(new RequestResponseDTO("Notice not found"));
|
||||||
}
|
}
|
||||||
boolean added = wishlistService.toggleWishlist(
|
boolean added = wishlistService.toggleWishlist(
|
||||||
@@ -55,8 +51,9 @@ public class WishlistController {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
public List<NoticeResponseDTO> getWishlistForClient(HttpServletRequest request) {
|
public List<NoticeDTO> getWishlistForClient() {
|
||||||
Long clientId = tools.getClientIdFromRequest(request);
|
// TODO: Replace with actual client ID from authentication context
|
||||||
|
Long clientId = 1L;
|
||||||
return wishlistService.getNoticesInWishlist(clientId);
|
return wishlistService.getNoticesInWishlist(clientId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.dto;
|
|
||||||
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter @Setter
|
|
||||||
public class AttributeDto {
|
|
||||||
private String name;
|
|
||||||
private String value;
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.dto;
|
package _11.asktpk.artisanconnectbackend.dto;
|
||||||
|
|
||||||
|
import _11.asktpk.artisanconnectbackend.entities.AttributesNotice;
|
||||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -8,7 +9,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Getter @Setter
|
@Getter @Setter
|
||||||
public class NoticeResponseDTO {
|
public class NoticeDTO {
|
||||||
private long noticeId;
|
private long noticeId;
|
||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
@@ -25,9 +26,11 @@ public class NoticeResponseDTO {
|
|||||||
|
|
||||||
private LocalDateTime publishDate;
|
private LocalDateTime publishDate;
|
||||||
|
|
||||||
private List<AttributeDto> attributes;
|
private List<AttributesNotice> attributesNotices;
|
||||||
|
|
||||||
public NoticeResponseDTO() {
|
private boolean isWishlisted;
|
||||||
|
|
||||||
|
public NoticeDTO() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.dto;
|
|
||||||
|
|
||||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter @Setter
|
|
||||||
public class NoticeRequestDTO {
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
private Long clientId;
|
|
||||||
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
private Double price;
|
|
||||||
|
|
||||||
private Enums.Category category;
|
|
||||||
|
|
||||||
private Enums.Status status;
|
|
||||||
|
|
||||||
public NoticeRequestDTO() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.dto;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class OrderWithPaymentsDTO {
|
|
||||||
private Long orderId;
|
|
||||||
private String orderType;
|
|
||||||
private String status;
|
|
||||||
private Double amount;
|
|
||||||
private LocalDateTime createdAt;
|
|
||||||
private List<PaymentDTO> payments;
|
|
||||||
|
|
||||||
// Gettery i settery
|
|
||||||
public Long getOrderId() {
|
|
||||||
return orderId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrderId(Long orderId) {
|
|
||||||
this.orderId = orderId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOrderType() {
|
|
||||||
return orderType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrderType(String orderType) {
|
|
||||||
this.orderType = orderType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(String status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getAmount() {
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAmount(Double amount) {
|
|
||||||
this.amount = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDateTime getCreatedAt() {
|
|
||||||
return createdAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreatedAt(LocalDateTime createdAt) {
|
|
||||||
this.createdAt = createdAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<PaymentDTO> getPayments() {
|
|
||||||
return payments;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPayments(List<PaymentDTO> payments) {
|
|
||||||
this.payments = payments;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.dto;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class PaymentDTO {
|
|
||||||
private Long paymentId;
|
|
||||||
private Double amount;
|
|
||||||
private String status;
|
|
||||||
private String transactionPaymentUrl;
|
|
||||||
private String transactionId;
|
|
||||||
|
|
||||||
public void setPaymentId(Long paymentId) {
|
|
||||||
this.paymentId = paymentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAmount(Double amount) {
|
|
||||||
this.amount = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(String status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransactionPaymentUrl(String transactionPaymentUrl) {
|
|
||||||
this.transactionPaymentUrl = transactionPaymentUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransactionId(String transactionId) {
|
|
||||||
this.transactionId = transactionId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.entities;
|
package _11.asktpk.artisanconnectbackend.entities;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "attribute_values")
|
@Table(name = "attribute_values")
|
||||||
@Getter @Setter
|
|
||||||
public class AttributeValues {
|
public class AttributeValues {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@@ -17,4 +14,6 @@ public class AttributeValues {
|
|||||||
private Attributes attribute;
|
private Attributes attribute;
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
// Getters, setters, and constructors
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.entities;
|
package _11.asktpk.artisanconnectbackend.entities;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "attributes")
|
@Table(name = "attributes")
|
||||||
@Getter @Setter
|
|
||||||
public class Attributes {
|
public class Attributes {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@@ -16,6 +12,8 @@ public class Attributes {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "attribute")
|
@OneToMany(mappedBy = "attribute", cascade = CascadeType.ALL)
|
||||||
private List<AttributeValues> attributeValues;
|
private List<AttributeValues> attributeValues;
|
||||||
|
|
||||||
|
// Getters, setters, and constructors
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.entities;
|
package _11.asktpk.artisanconnectbackend.entities;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "attributes_notice")
|
@Table(name = "attributes_notice")
|
||||||
@Getter @Setter
|
|
||||||
public class AttributesNotice {
|
public class AttributesNotice {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private Long notice_id;
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "id_notice")
|
||||||
|
private Notice notice;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "id_value")
|
@JoinColumn(name = "id_value")
|
||||||
private AttributeValues attributeValue;
|
private AttributeValues attributeValue;
|
||||||
|
|
||||||
|
// Getters, setters, and constructors
|
||||||
}
|
}
|
||||||
@@ -35,10 +35,10 @@ public class Notice {
|
|||||||
|
|
||||||
private LocalDateTime publishDate;
|
private LocalDateTime publishDate;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "notice_id")
|
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||||
private List<AttributesNotice> attributesNotices;
|
private List<AttributesNotice> attributesNotices;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "notice")
|
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||||
private List<Order> orders;
|
private List<Order> orders;
|
||||||
|
|
||||||
// @OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
// @OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.repository;
|
package _11.asktpk.artisanconnectbackend.repository;
|
||||||
|
|
||||||
import _11.asktpk.artisanconnectbackend.entities.Notice;
|
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);
|
boolean existsByIdNoticeAndClientId(long noticeId, long clientId);
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ import _11.asktpk.artisanconnectbackend.entities.Order;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface OrderRepository extends JpaRepository<Order, Long> {
|
public interface OrderRepository extends JpaRepository<Order, Long> {
|
||||||
List<Order> findByClientId(Long clientId);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,9 @@ import _11.asktpk.artisanconnectbackend.entities.Payment;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
||||||
Optional<Payment> findByTransactionId(String transactionId);
|
Optional<Payment> findByTransactionId(String transactionId);
|
||||||
|
|
||||||
List<Payment> findAllByOrderId(Long id);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class JwtRequestFilter extends OncePerRequestFilter {
|
|||||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
response.setContentType("application/json");
|
response.setContentType("application/json");
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
String jsonResponse = "{\"error\": \"Token is invalid. Please login again.\"}";
|
String jsonResponse = "{\"error\": \"Token is invalid or expired. Please login again.\"}";
|
||||||
response.getWriter().write(jsonResponse);
|
response.getWriter().write(jsonResponse);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,6 @@ public class JwtRequestFilter extends OncePerRequestFilter {
|
|||||||
} catch (ExpiredJwtException expiredJwtException) {
|
} catch (ExpiredJwtException expiredJwtException) {
|
||||||
logger.error(expiredJwtException.getMessage());
|
logger.error(expiredJwtException.getMessage());
|
||||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
response.getWriter().write(new RequestResponseDTO("Authentication token is expired. Please login again.").toJSON());
|
|
||||||
return;
|
return;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
|
|||||||
@@ -82,10 +82,6 @@ public class JwtUtil {
|
|||||||
return extractAllClaims(token).get("role", String.class);
|
return extractAllClaims(token).get("role", String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long extractUserId(String token) {
|
|
||||||
return extractAllClaims(token).get("userId", Long.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> T extractClaim(String token, Function<Claims, T> claimsResolver) {
|
public <T> T extractClaim(String token, Function<Claims, T> claimsResolver) {
|
||||||
final Claims claims = extractAllClaims(token);
|
final Claims claims = extractAllClaims(token);
|
||||||
return claimsResolver.apply(claims);
|
return claimsResolver.apply(claims);
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.service;
|
package _11.asktpk.artisanconnectbackend.service;
|
||||||
|
|
||||||
import _11.asktpk.artisanconnectbackend.dto.AttributeDto;
|
|
||||||
import _11.asktpk.artisanconnectbackend.dto.NoticeRequestDTO;
|
|
||||||
import _11.asktpk.artisanconnectbackend.entities.AttributesNotice;
|
|
||||||
import _11.asktpk.artisanconnectbackend.entities.Client;
|
import _11.asktpk.artisanconnectbackend.entities.Client;
|
||||||
import _11.asktpk.artisanconnectbackend.entities.Notice;
|
import _11.asktpk.artisanconnectbackend.entities.Notice;
|
||||||
import _11.asktpk.artisanconnectbackend.repository.ClientRepository;
|
import _11.asktpk.artisanconnectbackend.repository.ClientRepository;
|
||||||
import _11.asktpk.artisanconnectbackend.repository.NoticeRepository;
|
import _11.asktpk.artisanconnectbackend.repository.NoticeRepository;
|
||||||
import _11.asktpk.artisanconnectbackend.dto.NoticeResponseDTO;
|
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -17,6 +14,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class NoticeService {
|
public class NoticeService {
|
||||||
@@ -27,21 +25,25 @@ public class NoticeService {
|
|||||||
|
|
||||||
private final NoticeRepository noticeRepository;
|
private final NoticeRepository noticeRepository;
|
||||||
private final ClientRepository clientRepository;
|
private final ClientRepository clientRepository;
|
||||||
|
private final WishlistService wishlistService;
|
||||||
private final ImageService imageService;
|
private final ImageService imageService;
|
||||||
|
|
||||||
public NoticeService(NoticeRepository noticeRepository, ClientRepository clientRepository, ImageService imageService) {
|
public NoticeService(NoticeRepository noticeRepository, ClientRepository clientRepository, WishlistService wishlistService, ImageService imageService) {
|
||||||
this.noticeRepository = noticeRepository;
|
this.noticeRepository = noticeRepository;
|
||||||
this.clientRepository = clientRepository;
|
this.clientRepository = clientRepository;
|
||||||
|
this.wishlistService = wishlistService;
|
||||||
this.imageService = imageService;
|
this.imageService = imageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Notice fromDTO(NoticeRequestDTO dto) {
|
public Notice fromDTO(NoticeDTO dto) {
|
||||||
Notice notice = new Notice();
|
Notice notice = new Notice();
|
||||||
notice.setTitle(dto.getTitle());
|
notice.setTitle(dto.getTitle());
|
||||||
notice.setDescription(dto.getDescription());
|
notice.setDescription(dto.getDescription());
|
||||||
notice.setPrice(dto.getPrice());
|
notice.setPrice(dto.getPrice());
|
||||||
notice.setCategory(dto.getCategory());
|
notice.setCategory(dto.getCategory());
|
||||||
notice.setStatus(dto.getStatus());
|
notice.setStatus(dto.getStatus());
|
||||||
|
notice.setPublishDate(dto.getPublishDate());
|
||||||
|
notice.setAttributesNotices(dto.getAttributesNotices());
|
||||||
|
|
||||||
Client client = clientRepository.findById(dto.getClientId())
|
Client client = clientRepository.findById(dto.getClientId())
|
||||||
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono klienta o ID: " + dto.getClientId()));
|
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono klienta o ID: " + dto.getClientId()));
|
||||||
@@ -50,8 +52,15 @@ public class NoticeService {
|
|||||||
return notice;
|
return notice;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NoticeResponseDTO toDTO(Notice notice) {
|
private NoticeDTO toDTO(Notice notice) {
|
||||||
NoticeResponseDTO dto = new NoticeResponseDTO();
|
NoticeDTO dto = new NoticeDTO();
|
||||||
|
// TODO: To be updated using AuthService after implementing authentication.
|
||||||
|
Optional<Client> client = clientRepository.findById(1L);
|
||||||
|
boolean isWishlisted = false;
|
||||||
|
if (client.isPresent()) {
|
||||||
|
Client c = client.get();
|
||||||
|
isWishlisted = wishlistService.isWishlisted(c, notice);
|
||||||
|
}
|
||||||
dto.setNoticeId(notice.getIdNotice());
|
dto.setNoticeId(notice.getIdNotice());
|
||||||
dto.setTitle(notice.getTitle());
|
dto.setTitle(notice.getTitle());
|
||||||
dto.setClientId(notice.getClient().getId());
|
dto.setClientId(notice.getClient().getId());
|
||||||
@@ -60,30 +69,20 @@ public class NoticeService {
|
|||||||
dto.setCategory(notice.getCategory());
|
dto.setCategory(notice.getCategory());
|
||||||
dto.setStatus(notice.getStatus());
|
dto.setStatus(notice.getStatus());
|
||||||
dto.setPublishDate(notice.getPublishDate());
|
dto.setPublishDate(notice.getPublishDate());
|
||||||
|
dto.setAttributesNotices(notice.getAttributesNotices());
|
||||||
List<AttributeDto> attributes = new ArrayList<>();
|
dto.setWishlisted(isWishlisted);
|
||||||
if (notice.getAttributesNotices() != null) {
|
|
||||||
for (AttributesNotice an : notice.getAttributesNotices()) {
|
|
||||||
AttributeDto attr = new AttributeDto();
|
|
||||||
attr.setName(an.getAttributeValue().getAttribute().getName());
|
|
||||||
attr.setValue(an.getAttributeValue().getValue());
|
|
||||||
attributes.add(attr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dto.setAttributes(attributes);
|
|
||||||
|
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<NoticeResponseDTO> getAllNotices() {
|
public List<NoticeDTO> getAllNotices() {
|
||||||
List<NoticeResponseDTO> result = new ArrayList<>();
|
List<NoticeDTO> result = new ArrayList<>();
|
||||||
for (Notice notice : noticeRepository.findAll()) {
|
for (Notice notice : noticeRepository.findAll()) {
|
||||||
result.add(toDTO(notice));
|
result.add(toDTO(notice));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NoticeResponseDTO getNoticeById(Long id) {
|
public NoticeDTO getNoticeById(Long id) {
|
||||||
Notice notice = noticeRepository.findById(id)
|
Notice notice = noticeRepository.findById(id)
|
||||||
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id));
|
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id));
|
||||||
return toDTO(notice);
|
return toDTO(notice);
|
||||||
@@ -94,17 +93,15 @@ public class NoticeService {
|
|||||||
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id));
|
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long addNotice(NoticeRequestDTO dto) {
|
public Long addNotice(NoticeDTO dto) {
|
||||||
Notice notice = fromDTO(dto);
|
return noticeRepository.save(fromDTO(dto)).getIdNotice();
|
||||||
notice.setPublishDate(LocalDateTime.now());
|
|
||||||
return noticeRepository.save(notice).getIdNotice();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean noticeExists(Long id) {
|
public boolean noticeExists(Long id) {
|
||||||
return noticeRepository.existsById(id);
|
return noticeRepository.existsById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NoticeResponseDTO updateNotice(Long id, NoticeRequestDTO dto) {
|
public NoticeDTO updateNotice(Long id, NoticeDTO dto) {
|
||||||
Notice existingNotice = noticeRepository.findById(id)
|
Notice existingNotice = noticeRepository.findById(id)
|
||||||
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id));
|
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id));
|
||||||
|
|
||||||
@@ -113,6 +110,7 @@ public class NoticeService {
|
|||||||
existingNotice.setPrice(dto.getPrice());
|
existingNotice.setPrice(dto.getPrice());
|
||||||
existingNotice.setCategory(dto.getCategory());
|
existingNotice.setCategory(dto.getCategory());
|
||||||
existingNotice.setStatus(dto.getStatus());
|
existingNotice.setStatus(dto.getStatus());
|
||||||
|
existingNotice.setAttributesNotices(dto.getAttributesNotices());
|
||||||
|
|
||||||
if (dto.getClientId() != null && !dto.getClientId().equals(existingNotice.getClient().getId())) {
|
if (dto.getClientId() != null && !dto.getClientId().equals(existingNotice.getClient().getId())) {
|
||||||
Client client = clientRepository.findById(dto.getClientId())
|
Client client = clientRepository.findById(dto.getClientId())
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import org.springframework.stereotype.Service;
|
|||||||
import _11.asktpk.artisanconnectbackend.entities.Order;
|
import _11.asktpk.artisanconnectbackend.entities.Order;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class OrderService {
|
public class OrderService {
|
||||||
@@ -57,7 +56,8 @@ public class OrderService {
|
|||||||
|
|
||||||
|
|
||||||
public Long addOrder(OrderDTO orderDTO) {
|
public Long addOrder(OrderDTO orderDTO) {
|
||||||
return orderRepository.save(fromDTO(orderDTO)).getId();
|
Order order = fromDTO(orderDTO);
|
||||||
|
return orderRepository.save(order).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long changeOrderStatus(Long id, Enums.OrderStatus status) {
|
public Long changeOrderStatus(Long id, Enums.OrderStatus status) {
|
||||||
@@ -76,8 +76,4 @@ public class OrderService {
|
|||||||
return orderRepository.findById(id)
|
return orderRepository.findById(id)
|
||||||
.orElseThrow(() -> new RuntimeException("Nie znaleziono zamówienia o ID: " + id));
|
.orElseThrow(() -> new RuntimeException("Nie znaleziono zamówienia o ID: " + id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Order> getOrdersByClientId(Long clientId) {
|
|
||||||
return orderRepository.findByClientId(clientId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ import org.springframework.web.reactive.function.BodyInserters;
|
|||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PaymentService {
|
public class PaymentService {
|
||||||
private final WebClient webClient;
|
private final WebClient webClient;
|
||||||
@@ -82,10 +80,4 @@ public class PaymentService {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Payment> getPaymentsByOrderId(Long id) {
|
|
||||||
return paymentRepository.findAllByOrderId(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.service;
|
package _11.asktpk.artisanconnectbackend.service;
|
||||||
|
|
||||||
import _11.asktpk.artisanconnectbackend.dto.WishlistDTO;
|
import _11.asktpk.artisanconnectbackend.dto.WishlistDTO;
|
||||||
import _11.asktpk.artisanconnectbackend.dto.NoticeResponseDTO;
|
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||||
import _11.asktpk.artisanconnectbackend.entities.Client;
|
import _11.asktpk.artisanconnectbackend.entities.Client;
|
||||||
import _11.asktpk.artisanconnectbackend.entities.Notice;
|
import _11.asktpk.artisanconnectbackend.entities.Notice;
|
||||||
import _11.asktpk.artisanconnectbackend.entities.Wishlist;
|
import _11.asktpk.artisanconnectbackend.entities.Wishlist;
|
||||||
@@ -31,6 +31,12 @@ public class WishlistService {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isWishlisted(Client client, Notice notice) {
|
||||||
|
Optional<Wishlist> existingEntry = wishlistRepository.findByClientAndNotice(client, notice);
|
||||||
|
|
||||||
|
return existingEntry.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean toggleWishlist(Client client, Notice notice) {
|
public boolean toggleWishlist(Client client, Notice notice) {
|
||||||
Optional<Wishlist> existingEntry = wishlistRepository.findByClientAndNotice(client, notice);
|
Optional<Wishlist> existingEntry = wishlistRepository.findByClientAndNotice(client, notice);
|
||||||
|
|
||||||
@@ -55,7 +61,7 @@ public class WishlistService {
|
|||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<NoticeResponseDTO> getNoticesInWishlist(Long clientId) {
|
public List<NoticeDTO> getNoticesInWishlist(Long clientId) {
|
||||||
List<Wishlist> wishlistEntries = wishlistRepository.findAllByClientId(clientId);
|
List<Wishlist> wishlistEntries = wishlistRepository.findAllByClientId(clientId);
|
||||||
|
|
||||||
return wishlistEntries.stream()
|
return wishlistEntries.stream()
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
package _11.asktpk.artisanconnectbackend.utils;
|
|
||||||
|
|
||||||
import _11.asktpk.artisanconnectbackend.security.JwtUtil;
|
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class Tools {
|
|
||||||
private final JwtUtil jwtUtil;
|
|
||||||
|
|
||||||
public Tools(JwtUtil jwtUtil) {
|
|
||||||
this.jwtUtil = jwtUtil;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getClientIdFromRequest(HttpServletRequest request) {
|
|
||||||
String authorizationHeader = request.getHeader("Authorization");
|
|
||||||
if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) {
|
|
||||||
return jwtUtil.extractUserId(authorizationHeader.substring(7));
|
|
||||||
} else {
|
|
||||||
return -1L;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,45 +17,4 @@ INSERT INTO notice (title, description, client_id, price, category, status, publ
|
|||||||
('Drewniany stół', 'Solidny stół wykonany z litego drewna dębowego.', 3, 1200.00, 'Furniture', 'ACTIVE', '2023-09-15'),
|
('Drewniany stół', 'Solidny stół wykonany z litego drewna dębowego.', 3, 1200.00, 'Furniture', 'ACTIVE', '2023-09-15'),
|
||||||
('Ceramiczna waza', 'Piękna waza ceramiczna, idealna na prezent.', 2, 300.00, 'Ceramics', 'INACTIVE', '2023-08-20'),
|
('Ceramiczna waza', 'Piękna waza ceramiczna, idealna na prezent.', 2, 300.00, 'Ceramics', 'INACTIVE', '2023-08-20'),
|
||||||
('Obraz olejny', 'Obraz olejny przedstawiający krajobraz górski.', 4, 800.00, 'Painting', 'ACTIVE', '2023-07-10'),
|
('Obraz olejny', 'Obraz olejny przedstawiający krajobraz górski.', 4, 800.00, 'Painting', 'ACTIVE', '2023-07-10'),
|
||||||
('Skórzany portfel', 'Ręcznie wykonany portfel ze skóry naturalnej.', 1, 250.00, 'Leatherwork', 'ACTIVE', '2023-06-05');
|
('Skórzany portfel', 'Ręcznie wykonany portfel ze skóry naturalnej.', 1, 250.00, 'Leatherwork', 'ACTIVE', '2023-06-05');
|
||||||
|
|
||||||
|
|
||||||
insert into attributes (name) values
|
|
||||||
('Kolor'),
|
|
||||||
('Materiał');
|
|
||||||
|
|
||||||
-- Kolory
|
|
||||||
insert into attribute_values (value, id_attribute) values
|
|
||||||
('Zielony', 1),
|
|
||||||
('Czerwony', 1),
|
|
||||||
('Niebieski', 1),
|
|
||||||
('Żółty', 1),
|
|
||||||
('Biały', 1),
|
|
||||||
('Czarny', 1),
|
|
||||||
('Różowy', 1),
|
|
||||||
('Szary', 1),
|
|
||||||
('Fioletowy', 1),
|
|
||||||
('Pomarańczowy', 1),
|
|
||||||
('Inny', 1);
|
|
||||||
|
|
||||||
-- Materiały
|
|
||||||
insert into attribute_values (value, id_attribute) values
|
|
||||||
('Bawełna', 2),
|
|
||||||
('Wełna', 2),
|
|
||||||
('Syntetyk', 2),
|
|
||||||
('Skóra', 2),
|
|
||||||
('Len', 2),
|
|
||||||
('Jedwab', 2),
|
|
||||||
('Poliester', 2),
|
|
||||||
('Akryl', 2),
|
|
||||||
('Wiskoza', 2),
|
|
||||||
('Nylon', 2),
|
|
||||||
('Inny', 2);
|
|
||||||
|
|
||||||
insert into attributes_notice (id_value, notice_id) values
|
|
||||||
(1, 1), -- Ręcznie robiona biżuteria - Zielony
|
|
||||||
(22, 1),
|
|
||||||
(2, 2), -- Drewniany stół - Czerwony
|
|
||||||
(3, 3), -- Ceramiczna waza - Niebieski
|
|
||||||
(4, 4), -- Obraz olejny - Żółty
|
|
||||||
(5, 5); -- Skórzany portfel - Biały
|
|
||||||
@@ -1,33 +1,591 @@
|
|||||||
package _11.asktpk.artisanconnectbackend;
|
package _11.asktpk.artisanconnectbackend;
|
||||||
|
|
||||||
|
import _11.asktpk.artisanconnectbackend.dto.CategoriesDTO;
|
||||||
|
import _11.asktpk.artisanconnectbackend.dto.ClientDTO;
|
||||||
|
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||||
|
import _11.asktpk.artisanconnectbackend.dto.WishlistDTO;
|
||||||
|
import _11.asktpk.artisanconnectbackend.entities.Client;
|
||||||
|
import _11.asktpk.artisanconnectbackend.entities.Notice;
|
||||||
|
import _11.asktpk.artisanconnectbackend.entities.Wishlist;
|
||||||
|
import _11.asktpk.artisanconnectbackend.repository.ClientRepository;
|
||||||
|
import _11.asktpk.artisanconnectbackend.repository.NoticeRepository;
|
||||||
|
import _11.asktpk.artisanconnectbackend.repository.WishlistRepository;
|
||||||
|
import _11.asktpk.artisanconnectbackend.service.ClientService;
|
||||||
|
import _11.asktpk.artisanconnectbackend.service.ImageService;
|
||||||
|
import _11.asktpk.artisanconnectbackend.service.NoticeService;
|
||||||
|
import _11.asktpk.artisanconnectbackend.service.WishlistService;
|
||||||
|
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||||
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||||
|
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||||
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
|
import org.springframework.http.*;
|
||||||
|
import _11.asktpk.artisanconnectbackend.entities.Image;
|
||||||
|
import _11.asktpk.artisanconnectbackend.repository.ImageRepository;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.UrlResource;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
|
import static _11.asktpk.artisanconnectbackend.utils.Enums.Role.USER;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testy dla funkcjonalności klienta w backendzie.
|
||||||
|
*/
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
class ArtisanConnectBackendApplicationTests {
|
class ArtisanConnectBackendApplicationTests {
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(ArtisanConnectBackendApplicationTests.class);
|
private static final Logger logger = LogManager.getLogger(ArtisanConnectBackendApplicationTests.class);
|
||||||
|
|
||||||
// @Test
|
@LocalServerPort
|
||||||
// void testPostgresDatabase() {
|
private final int port;
|
||||||
// postgresDatabase.add(new Notice("Test Notice", "Username", "Test Description"));
|
|
||||||
// Boolean isRecordAvailable = postgresDatabase.get().size() > 0;
|
private final ClientService clientService;
|
||||||
// if(isRecordAvailable) {
|
private final TestRestTemplate restTemplate;
|
||||||
// logger.info("The record is available in the database");
|
|
||||||
// } else {
|
@Autowired
|
||||||
// logger.error("The record is not available in the database");
|
public ArtisanConnectBackendApplicationTests(ClientService clientService, @LocalServerPort int port) {
|
||||||
// }
|
this.clientService = clientService;
|
||||||
// assert isRecordAvailable;
|
this.port = port;
|
||||||
// }
|
this.restTemplate = new TestRestTemplate();
|
||||||
//
|
}
|
||||||
// @Test
|
|
||||||
// void getAllNotices() throws IOException {
|
|
||||||
// OkHttpClient client = new OkHttpClient().newBuilder()
|
@Nested
|
||||||
// .build();
|
@DisplayName("Testy jednostkowe ClientService")
|
||||||
// MediaType mediaType = MediaType.parse("text/plain");
|
class ClientServiceTest {
|
||||||
// Request request = new Request.Builder()
|
|
||||||
// .url("http://localhost:8080/api/v1/notices/all")
|
private final ClientRepository clientRepository;
|
||||||
// .build();
|
private final ClientService clientService;
|
||||||
// Response response = client.newCall(request).execute();
|
|
||||||
// }
|
ClientServiceTest() {
|
||||||
}
|
logger.info("Inicjalizacja mocków dla ClientService");
|
||||||
|
this.clientRepository = mock(ClientRepository.class);
|
||||||
|
this.clientService = new ClientService(clientRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien poprawnie mapować klientów na ClientDTO")
|
||||||
|
void testClientMappingToDTO() {
|
||||||
|
logger.info("Tworzenie danych klientów...");
|
||||||
|
Client client = createTestClient("Jan", "Kowalski");
|
||||||
|
when(clientRepository.findAll()).thenReturn(List.of(client));
|
||||||
|
|
||||||
|
logger.info("Wywołanie metody getAllClients...");
|
||||||
|
List<ClientDTO> clientDTOList = clientService.getAllClients();
|
||||||
|
|
||||||
|
assertThat(clientDTOList).hasSize(1);
|
||||||
|
assertThat(clientDTOList.get(0).getFirstName()).isEqualTo("Jan");
|
||||||
|
verify(clientRepository, times(1)).findAll();
|
||||||
|
logger.info("Test zakończony poprawnie");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Client createTestClient(String firstName, String lastName) {
|
||||||
|
Client client = new Client();
|
||||||
|
client.setFirstName(firstName);
|
||||||
|
client.setLastName(lastName);
|
||||||
|
client.setEmail(firstName.toLowerCase() + "." + lastName.toLowerCase() + "@example.com");
|
||||||
|
client.setRole(USER);
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("Testy integracyjne ClientController")
|
||||||
|
class ClientControllerTest {
|
||||||
|
|
||||||
|
private final int port;
|
||||||
|
private final TestRestTemplate restTemplate;
|
||||||
|
private final ClientService clientService;
|
||||||
|
private final NoticeService noticeService;
|
||||||
|
private final NoticeRepository noticeRepository;
|
||||||
|
private final Logger logger = LogManager.getLogger(ClientControllerTest.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ClientControllerTest(
|
||||||
|
@LocalServerPort int port,
|
||||||
|
TestRestTemplate restTemplate,
|
||||||
|
ClientService clientService,
|
||||||
|
NoticeService noticeService,
|
||||||
|
NoticeRepository noticeRepository) {
|
||||||
|
this.port = port;
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
this.clientService = clientService;
|
||||||
|
this.noticeService = noticeService;
|
||||||
|
this.noticeRepository = noticeRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void cleanDatabase() {
|
||||||
|
|
||||||
|
noticeRepository.deleteAll();
|
||||||
|
|
||||||
|
clientService.getAllClients().forEach(client -> {
|
||||||
|
try {
|
||||||
|
clientService.deleteClient(client.getId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Błąd podczas usuwania klienta: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasNotices(Long clientId) {
|
||||||
|
return noticeService.getAllNotices().stream()
|
||||||
|
.anyMatch(notice -> notice.getClientId().equals(clientId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien poprawnie usunąć klienta z powiązanymi ogłoszeniami")
|
||||||
|
void shouldDeleteClientWithNotices() {
|
||||||
|
ClientDTO client = clientService.addClient(createTestDTO("client@example.com", "Jan", "Kowalski"));
|
||||||
|
|
||||||
|
NoticeDTO notice = new NoticeDTO();
|
||||||
|
notice.setClientId(client.getId());
|
||||||
|
notice.setTitle("Test Notice");
|
||||||
|
Long noticeId = noticeService.addNotice(notice);
|
||||||
|
|
||||||
|
ResponseEntity<Void> deleteNoticeResponse = restTemplate.exchange(
|
||||||
|
createURLWithPort("/api/v1/notices/delete/" + noticeId),
|
||||||
|
HttpMethod.DELETE,
|
||||||
|
null,
|
||||||
|
Void.class
|
||||||
|
);
|
||||||
|
assertThat(deleteNoticeResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
|
||||||
|
ResponseEntity<Void> deleteClientResponse = restTemplate.exchange(
|
||||||
|
createURLWithPort("/api/v1/clients/delete/" + client.getId()),
|
||||||
|
HttpMethod.DELETE,
|
||||||
|
null,
|
||||||
|
Void.class
|
||||||
|
);
|
||||||
|
|
||||||
|
assertThat(deleteClientResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
assertThat(clientService.clientExists(client.getId())).isFalse();
|
||||||
|
assertThat(noticeService.noticeExists(noticeId)).isFalse();
|
||||||
|
}
|
||||||
|
@Autowired
|
||||||
|
private ClientRepository clientRepository;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien zwracać wszystkich klientów")
|
||||||
|
void shouldReturnAllClients() {
|
||||||
|
ClientDTO client1 = clientService.addClient(createTestDTO("client1@example.com", "Anna", "Nowak"));
|
||||||
|
ClientDTO client2 = clientService.addClient(createTestDTO("client2@example.com", "Adam", "Kowalski"));
|
||||||
|
|
||||||
|
ResponseEntity<ClientDTO[]> response = restTemplate.getForEntity(
|
||||||
|
createURLWithPort("/api/v1/clients/get/all"),
|
||||||
|
ClientDTO[].class
|
||||||
|
);
|
||||||
|
|
||||||
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
assertThat(response.getBody()).isNotNull();
|
||||||
|
assertThat(response.getBody()).hasSize(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien zwrócić błąd przy próbie usunięcia klienta z powiązanymi ogłoszeniami bez kaskady")
|
||||||
|
void shouldFailWhenDeletingClientWithNoticesWithoutCascade() {
|
||||||
|
noticeService.getAllNotices().forEach(n -> noticeService.deleteNotice(n.getNoticeId()));
|
||||||
|
clientService.getAllClients().forEach(c -> clientService.deleteClient(c.getId()));
|
||||||
|
|
||||||
|
ClientDTO client = clientService.addClient(createTestDTO("client@example.com", "Jan", "Kowalski"));
|
||||||
|
|
||||||
|
NoticeDTO notice = new NoticeDTO();
|
||||||
|
notice.setClientId(client.getId());
|
||||||
|
notice.setTitle("Test Notice");
|
||||||
|
noticeService.addNotice(notice);
|
||||||
|
|
||||||
|
try {
|
||||||
|
clientService.deleteClient(client.getId());
|
||||||
|
fail("Powinien zostać rzucony wyjątek DataIntegrityViolationException");
|
||||||
|
} catch (DataIntegrityViolationException e) {
|
||||||
|
// Oczekiwany wyjątek
|
||||||
|
assertThat(e.getMessage()).contains("could not execute statement");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien poprawnie usunąć klienta bez powiązanych ogłoszeń")
|
||||||
|
void shouldDeleteClientWithoutNotices() {
|
||||||
|
ClientDTO client = clientService.addClient(createTestDTO("client@example.com", "Jan", "Kowalski"));
|
||||||
|
|
||||||
|
ResponseEntity<Void> deleteResponse = restTemplate.exchange(
|
||||||
|
createURLWithPort("/api/v1/clients/delete/" + client.getId()),
|
||||||
|
HttpMethod.DELETE,
|
||||||
|
null,
|
||||||
|
Void.class
|
||||||
|
);
|
||||||
|
|
||||||
|
assertThat(deleteResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
assertThat(clientService.clientExists(client.getId())).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ClientDTO createTestDTO(String email, String firstName, String lastName) {
|
||||||
|
ClientDTO clientDTO = new ClientDTO();
|
||||||
|
clientDTO.setEmail(email);
|
||||||
|
clientDTO.setFirstName(firstName);
|
||||||
|
clientDTO.setLastName(lastName);
|
||||||
|
clientDTO.setRole(USER);
|
||||||
|
return clientDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createURLWithPort(String uri) {
|
||||||
|
return "http://localhost:" + port + uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("Testy jednostkowe NoticeService")
|
||||||
|
class NoticeServiceUnitTest {
|
||||||
|
|
||||||
|
private final NoticeRepository noticeRepository;
|
||||||
|
private final ClientRepository clientRepository;
|
||||||
|
private final NoticeService noticeService;
|
||||||
|
|
||||||
|
NoticeServiceUnitTest() {
|
||||||
|
this.noticeRepository = mock(NoticeRepository.class);
|
||||||
|
this.clientRepository = mock(ClientRepository.class);
|
||||||
|
this.noticeService = new NoticeService(
|
||||||
|
noticeRepository,
|
||||||
|
clientRepository,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien poprawnie dodać ogłoszenie")
|
||||||
|
void shouldAddNoticeSuccessfully() {
|
||||||
|
Client client = createTestClient("test@example.com", "Anna", "Kowalska");
|
||||||
|
when(clientRepository.findById(1L)).thenReturn(Optional.of(client));
|
||||||
|
|
||||||
|
NoticeDTO noticeDTO = new NoticeDTO();
|
||||||
|
noticeDTO.setClientId(1L);
|
||||||
|
noticeDTO.setTitle("Test Notice");
|
||||||
|
noticeDTO.setDescription("Opis ogłoszenia");
|
||||||
|
noticeDTO.setPrice(100.0);
|
||||||
|
|
||||||
|
Notice notice = new Notice();
|
||||||
|
notice.setIdNotice(1L);
|
||||||
|
|
||||||
|
when(noticeRepository.save(any(Notice.class))).thenReturn(notice);
|
||||||
|
|
||||||
|
Long savedNoticeId = noticeService.addNotice(noticeDTO);
|
||||||
|
|
||||||
|
assertThat(savedNoticeId).isEqualTo(1L);
|
||||||
|
verify(noticeRepository, times(1)).save(any(Notice.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien zwrócić wyjątek, gdy klient dla ogłoszenia nie istnieje")
|
||||||
|
void shouldThrowExceptionWhenClientNotFound() {
|
||||||
|
NoticeDTO noticeDTO = new NoticeDTO();
|
||||||
|
noticeDTO.setClientId(1L);
|
||||||
|
|
||||||
|
when(clientRepository.findById(1L)).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
assertThrows(EntityNotFoundException.class, () -> noticeService.addNotice(noticeDTO));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Client createTestClient(String email, String firstName, String lastName) {
|
||||||
|
Client client = new Client();
|
||||||
|
client.setId(1L);
|
||||||
|
client.setEmail(email);
|
||||||
|
client.setFirstName(firstName);
|
||||||
|
client.setLastName(lastName);
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("Testy integracyjne ImageService")
|
||||||
|
class ImageServiceTest {
|
||||||
|
|
||||||
|
private final ImageRepository imageRepository;
|
||||||
|
private final ImageService imageService;
|
||||||
|
|
||||||
|
ImageServiceTest() throws Exception {
|
||||||
|
this.imageRepository = mock(ImageRepository.class);
|
||||||
|
Constructor<ImageService> constructor = ImageService.class.getDeclaredConstructor(ImageRepository.class);
|
||||||
|
constructor.setAccessible(true);
|
||||||
|
this.imageService = constructor.newInstance(imageRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien poprawnie zapisać obraz w magazynie plików")
|
||||||
|
void shouldSaveImageToStorage() throws IOException {
|
||||||
|
MultipartFile file = mock(MultipartFile.class);
|
||||||
|
when(file.getOriginalFilename()).thenReturn("test.jpg");
|
||||||
|
when(file.getInputStream()).thenReturn(Files.newInputStream(Path.of("src/test/resources/test.jpg")));
|
||||||
|
|
||||||
|
String uploadDirectory = "upload_dir";
|
||||||
|
Path uploadPath = Path.of(uploadDirectory);
|
||||||
|
Files.createDirectories(uploadPath);
|
||||||
|
|
||||||
|
String savedFileName = imageService.saveImageToStorage(uploadDirectory, file);
|
||||||
|
|
||||||
|
assertTrue(savedFileName.contains(".jpg"));
|
||||||
|
assertTrue(Files.exists(uploadPath.resolve(savedFileName)));
|
||||||
|
|
||||||
|
Files.deleteIfExists(uploadPath.resolve(savedFileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien poprawnie zapisać nazwę obrazu do bazy danych")
|
||||||
|
void shouldAddImageNameToDB() {
|
||||||
|
String filename = UUID.randomUUID() + "test.jpg";
|
||||||
|
Long noticeId = 1L;
|
||||||
|
|
||||||
|
imageService.addImageNameToDB(filename, noticeId);
|
||||||
|
|
||||||
|
verify(imageRepository, times(1)).save(Mockito.any(Image.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien poprawnie pobrać obraz")
|
||||||
|
void shouldGetImage() throws IOException {
|
||||||
|
Path imagePath = Path.of("src/test/resources/test.jpg");
|
||||||
|
Resource resource = imageService.getImage("src/test/resources", "test.jpg");
|
||||||
|
|
||||||
|
assertNotNull(resource);
|
||||||
|
assertTrue(resource instanceof UrlResource);
|
||||||
|
assertTrue(Files.exists(imagePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien zgłosić błąd, gdy obraz nie zostanie znaleziony")
|
||||||
|
void shouldThrowExceptionWhenImageNotFound() {
|
||||||
|
Exception exception = assertThrows(IOException.class, () -> {
|
||||||
|
imageService.getImage("invalid/path", "missing.jpg");
|
||||||
|
});
|
||||||
|
|
||||||
|
assertThat(exception).hasMessageContaining("File not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien poprawnie usuwać obraz z magazynu plików i bazy danych")
|
||||||
|
void shouldDeleteImage() throws IOException {
|
||||||
|
Path imagePath = Files.createTempFile("temp-dir", "temp-image.jpg");
|
||||||
|
String imageName = imagePath.getFileName().toString();
|
||||||
|
String imageDirectory = imagePath.getParent().toString();
|
||||||
|
|
||||||
|
Image image = new Image();
|
||||||
|
image.setImageName(imageName);
|
||||||
|
when(imageRepository.existsImageByImageNameEqualsIgnoreCase(imageName)).thenReturn(true);
|
||||||
|
|
||||||
|
imageService.deleteImage(imageDirectory, imageName);
|
||||||
|
|
||||||
|
assertFalse(Files.exists(imagePath));
|
||||||
|
verify(imageRepository, times(1)).deleteByImageNameEquals(imageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien poprawnie zwrócić listę nazw obrazów dla podanego ogłoszenia")
|
||||||
|
void shouldGetImagesListForNotice() throws Exception {
|
||||||
|
Long noticeId = 1L;
|
||||||
|
List<Image> images = List.of(
|
||||||
|
createTestImage(1L, noticeId, "image1.jpg"),
|
||||||
|
createTestImage(2L, noticeId, "image2.jpg")
|
||||||
|
);
|
||||||
|
when(imageRepository.findByNoticeId(noticeId)).thenReturn(images);
|
||||||
|
|
||||||
|
List<String> imageNames = imageService.getImagesList(noticeId);
|
||||||
|
|
||||||
|
assertThat(imageNames).hasSize(2);
|
||||||
|
assertThat(imageNames).containsExactly("image1.jpg", "image2.jpg");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Image createTestImage(Long id, Long noticeId, String imageName) {
|
||||||
|
Image image = new Image();
|
||||||
|
image.setId(id);
|
||||||
|
image.setNoticeId(noticeId);
|
||||||
|
image.setImageName(imageName);
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("Testy integracyjne WishlistService")
|
||||||
|
class WishlistServiceTest {
|
||||||
|
|
||||||
|
private final WishlistRepository wishlistRepository;
|
||||||
|
private final NoticeService noticeService;
|
||||||
|
private final WishlistService wishlistService;
|
||||||
|
|
||||||
|
WishlistServiceTest() {
|
||||||
|
this.wishlistRepository = mock(WishlistRepository.class);
|
||||||
|
this.noticeService = mock(NoticeService.class);
|
||||||
|
this.wishlistService = new WishlistService(wishlistRepository, noticeService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien poprawnie zwrócić wishlist dla klienta")
|
||||||
|
void shouldGetWishlistForClient() {
|
||||||
|
Long clientId = 1L;
|
||||||
|
Wishlist wishlist1 = createTestWishlist(1L, clientId, 10L);
|
||||||
|
Wishlist wishlist2 = createTestWishlist(2L, clientId, 20L);
|
||||||
|
|
||||||
|
when(wishlistRepository.findAllByClientId(clientId)).thenReturn(List.of(wishlist1, wishlist2));
|
||||||
|
|
||||||
|
List<WishlistDTO> result = wishlistService.getWishlistForClientId(clientId);
|
||||||
|
|
||||||
|
assertThat(result).hasSize(2);
|
||||||
|
assertThat(result.get(0).getNoticeId()).isEqualTo(10L);
|
||||||
|
verify(wishlistRepository, times(1)).findAllByClientId(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien poprawnie dodać lub usunąć element z wishlist")
|
||||||
|
void shouldToggleWishlist() {
|
||||||
|
Client client = createTestClient(1L, "test@example.com");
|
||||||
|
Notice notice = createTestNotice(10L);
|
||||||
|
|
||||||
|
// Scenariusz 1: Element istnieje i powinien zostać usunięty
|
||||||
|
when(wishlistRepository.findByClientAndNotice(client, notice)).thenReturn(Optional.of(new Wishlist()));
|
||||||
|
|
||||||
|
boolean removed = wishlistService.toggleWishlist(client, notice);
|
||||||
|
|
||||||
|
assertThat(removed).isFalse();
|
||||||
|
verify(wishlistRepository, times(1)).delete(any(Wishlist.class));
|
||||||
|
|
||||||
|
// Scenariusz 2: Element nie istnieje i powinien zostać dodany
|
||||||
|
when(wishlistRepository.findByClientAndNotice(client, notice)).thenReturn(Optional.empty());
|
||||||
|
|
||||||
|
boolean added = wishlistService.toggleWishlist(client, notice);
|
||||||
|
|
||||||
|
assertThat(added).isTrue();
|
||||||
|
verify(wishlistRepository, times(1)).save(any(Wishlist.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien zwrócić listę ogłoszeń w wishlist klienta")
|
||||||
|
void shouldGetNoticesInWishlist() {
|
||||||
|
Long clientId = 1L;
|
||||||
|
Wishlist wishlist1 = createTestWishlist(1L, clientId, 10L);
|
||||||
|
Wishlist wishlist2 = createTestWishlist(2L, clientId, 20L);
|
||||||
|
|
||||||
|
when(wishlistRepository.findAllByClientId(clientId)).thenReturn(List.of(wishlist1, wishlist2));
|
||||||
|
when(noticeService.getNoticeById(10L)).thenReturn(createNoticeDTO(10L, "Ogłoszenie 1"));
|
||||||
|
when(noticeService.getNoticeById(20L)).thenReturn(createNoticeDTO(20L, "Ogłoszenie 2"));
|
||||||
|
|
||||||
|
List<NoticeDTO> result = wishlistService.getNoticesInWishlist(clientId);
|
||||||
|
|
||||||
|
assertThat(result).hasSize(2);
|
||||||
|
assertThat(result.get(0).getNoticeId()).isEqualTo(10L);
|
||||||
|
assertThat(result.get(1).getNoticeId()).isEqualTo(20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Wishlist createTestWishlist(Long id, Long clientId, Long noticeId) {
|
||||||
|
Wishlist wishlist = new Wishlist();
|
||||||
|
wishlist.setId(id);
|
||||||
|
|
||||||
|
Client client = new Client();
|
||||||
|
client.setId(clientId);
|
||||||
|
wishlist.setClient(client);
|
||||||
|
|
||||||
|
Notice notice = new Notice();
|
||||||
|
notice.setIdNotice(noticeId);
|
||||||
|
wishlist.setNotice(notice);
|
||||||
|
|
||||||
|
return wishlist;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Client createTestClient(Long id, String email) {
|
||||||
|
Client client = new Client();
|
||||||
|
client.setId(id);
|
||||||
|
client.setEmail(email);
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Notice createTestNotice(Long noticeId) {
|
||||||
|
Notice notice = new Notice();
|
||||||
|
notice.setIdNotice(noticeId);
|
||||||
|
return notice;
|
||||||
|
}
|
||||||
|
|
||||||
|
private NoticeDTO createNoticeDTO(Long noticeId, String title) {
|
||||||
|
NoticeDTO noticeDTO = new NoticeDTO();
|
||||||
|
noticeDTO.setNoticeId(noticeId);
|
||||||
|
noticeDTO.setTitle(title);
|
||||||
|
return noticeDTO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("Testy dla VariablesController")
|
||||||
|
class VariablesControllerTest {
|
||||||
|
|
||||||
|
private final int port;
|
||||||
|
private final TestRestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public VariablesControllerTest(@LocalServerPort int port, TestRestTemplate restTemplate) {
|
||||||
|
this.port = port;
|
||||||
|
this.restTemplate = restTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien zwrócić kategorie")
|
||||||
|
void shouldGetCategories() {
|
||||||
|
String url = createURLWithPort("/api/v1/vars/categories");
|
||||||
|
|
||||||
|
ResponseEntity<CategoriesDTO[]> response = restTemplate.getForEntity(url, CategoriesDTO[].class);
|
||||||
|
|
||||||
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
assertThat(response.getBody()).isNotNull().isNotEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien zwrócić statusy")
|
||||||
|
void shouldGetStatuses() {
|
||||||
|
String url = createURLWithPort("/api/v1/vars/statuses");
|
||||||
|
|
||||||
|
ResponseEntity<Enums.Status[]> response = restTemplate.getForEntity(url, Enums.Status[].class);
|
||||||
|
|
||||||
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
assertThat(response.getBody()).isNotNull().isNotEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Powinien zwrócić role")
|
||||||
|
void shouldGetRoles() {
|
||||||
|
String url = createURLWithPort("/api/v1/vars/roles");
|
||||||
|
|
||||||
|
ResponseEntity<Enums.Role[]> response = restTemplate.getForEntity(url, Enums.Role[].class);
|
||||||
|
|
||||||
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
|
assertThat(response.getBody()).isNotNull().isNotEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createURLWithPort(String uri) {
|
||||||
|
return "http://localhost:" + port + uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
BIN
src/test/resources/test.jpeg
Normal file
BIN
src/test/resources/test.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 108 KiB |
BIN
src/test/resources/test.jpg
Normal file
BIN
src/test/resources/test.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
BIN
src/test/resources/test.png
Normal file
BIN
src/test/resources/test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 435 KiB |
Reference in New Issue
Block a user