Compare commits
30 Commits
paymentInt
...
environmen
| Author | SHA1 | Date | |
|---|---|---|---|
| a7c8f22658 | |||
| f31885c795 | |||
| edeb36cb8c | |||
| bacfd529aa | |||
| 8656ececf1 | |||
| 1d104493b5 | |||
| 3355914c70 | |||
| d51161221c | |||
|
|
422daeb99e | ||
|
|
3204b921c4 | ||
| f56ffacec3 | |||
| 0f14c72fdd | |||
| 2589c6010e | |||
|
|
1ec6e62c04 | ||
| 00b9f99af5 | |||
| 81cbc1f4b2 | |||
| 190083c133 | |||
| 501121f235 | |||
| 62a5ad1bc6 | |||
| 5262749e2d | |||
| 5f548de73a | |||
| ffbd8d220c | |||
| 0d32b4a495 | |||
| 8ea5d84779 | |||
| a09603f8cb | |||
| 45c607060a | |||
| 0b85fed4b8 | |||
| d2163e1601 | |||
| 293be1d46e | |||
| f4c8177270 |
36
pom.xml
36
pom.xml
@@ -44,6 +44,11 @@
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
|
||||
<version>2.4.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
@@ -77,7 +82,38 @@
|
||||
<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>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
<version>0.11.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>0.11.5</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>0.11.5</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package _11.asktpk.artisanconnectbackend.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
public class AppConfig {
|
||||
|
||||
@Bean
|
||||
public PasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package _11.asktpk.artisanconnectbackend.config;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.security.JwtRequestFilter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class SecurityConfig {
|
||||
|
||||
private final JwtRequestFilter jwtRequestFilter;
|
||||
|
||||
public SecurityConfig(JwtRequestFilter jwtRequestFilter) {
|
||||
this.jwtRequestFilter = jwtRequestFilter;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.cors(cors -> cors.configure(http))
|
||||
.csrf(AbstractHttpConfigurer::disable)
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/api/v1/auth/**", "/api/v1/payments/notification").permitAll()
|
||||
.anyRequest().authenticated())
|
||||
.sessionManagement(session -> session
|
||||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
|
||||
|
||||
http.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
|
||||
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package _11.asktpk.artisanconnectbackend.controller;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.customExceptions.ClientAlreadyExistsException;
|
||||
import _11.asktpk.artisanconnectbackend.customExceptions.WrongLoginPasswordException;
|
||||
import _11.asktpk.artisanconnectbackend.dto.*;
|
||||
import _11.asktpk.artisanconnectbackend.service.AuthService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/auth")
|
||||
public class AuthController {
|
||||
|
||||
private final AuthService authService;
|
||||
|
||||
public AuthController(AuthService authService) {
|
||||
this.authService = authService;
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
public ResponseEntity<?> login(@RequestBody AuthRequestDTO authRequestDTO) {
|
||||
if (authRequestDTO.getEmail() == null || authRequestDTO.getPassword() == null
|
||||
|| authRequestDTO.getEmail().isEmpty() || authRequestDTO.getPassword().isEmpty()) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RequestResponseDTO("Przekazano puste login lub hasło"));
|
||||
}
|
||||
|
||||
authRequestDTO.setEmail(authRequestDTO.getEmail().toLowerCase());
|
||||
|
||||
try {
|
||||
AuthResponseDTO responseDTO = authService.login(authRequestDTO.getEmail(), authRequestDTO.getPassword());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(responseDTO);
|
||||
|
||||
} catch (WrongLoginPasswordException e) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new RequestResponseDTO(e.getMessage()));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RequestResponseDTO(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public ResponseEntity<?> register(@RequestBody ClientRegistrationDTO clientRegistrationDTO) {
|
||||
if (clientRegistrationDTO.getEmail() == null || clientRegistrationDTO.getPassword() == null
|
||||
|| clientRegistrationDTO.getEmail().isEmpty() || clientRegistrationDTO.getPassword().isEmpty()) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RequestResponseDTO("Przekazano puste login lub hasło"));
|
||||
}
|
||||
|
||||
clientRegistrationDTO.setEmail(clientRegistrationDTO.getEmail().toLowerCase());
|
||||
|
||||
try {
|
||||
AuthResponseDTO registrationData = authService.register(clientRegistrationDTO.getEmail(), clientRegistrationDTO.getPassword(), clientRegistrationDTO.getFirstName(), clientRegistrationDTO.getLastName());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(registrationData);
|
||||
} catch (ClientAlreadyExistsException clientAlreadyExistsException) {
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT)
|
||||
.body(new RequestResponseDTO(clientAlreadyExistsException.getMessage()));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RequestResponseDTO(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
public ResponseEntity<RequestResponseDTO> logout(HttpServletRequest request) {
|
||||
String authHeader = request.getHeader("Authorization");
|
||||
|
||||
if (authHeader != null && authHeader.startsWith("Bearer ")) {
|
||||
String token = authHeader.substring(7);
|
||||
authService.logout(token);
|
||||
return ResponseEntity.ok(new RequestResponseDTO("Successfully logged out"));
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RequestResponseDTO("Invalid token"));
|
||||
}
|
||||
|
||||
@PostMapping("/google")
|
||||
public ResponseEntity<?> authenticateWithGoogle(@RequestBody GoogleAuthRequestDTO dto) {
|
||||
if(dto.getGoogleToken() == null){
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RequestResponseDTO("Invalid or empty token"));
|
||||
}
|
||||
|
||||
try {
|
||||
AuthResponseDTO response = authService.googleLogin(dto.getGoogleToken());
|
||||
return ResponseEntity.status(HttpStatus.OK).body(response);
|
||||
} catch (HttpClientErrorException httpClientErrorException) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RequestResponseDTO("Google access token is invalid or expired"));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
|
||||
.body(new RequestResponseDTO("Authentication Error (Google): " + e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,16 +24,16 @@ public class ClientController {
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public ResponseEntity getClientById(@PathVariable long id) {
|
||||
public ResponseEntity<?> getClientById(@PathVariable long id) {
|
||||
if(clientService.getClientById(id) != null) {
|
||||
return new ResponseEntity(clientService.getClientById(id), HttpStatus.OK);
|
||||
return new ResponseEntity<>(clientService.getClientByIdDTO(id), HttpStatus.OK);
|
||||
} else {
|
||||
return new ResponseEntity(HttpStatus.NOT_FOUND);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity addClient(@RequestBody ClientDTO clientDTO) {
|
||||
public ResponseEntity<?> addClient(@RequestBody ClientDTO clientDTO) {
|
||||
if(clientService.clientExists(clientDTO.getId())) {
|
||||
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||
} else {
|
||||
@@ -43,7 +43,7 @@ public class ClientController {
|
||||
|
||||
// TODO: do zrobienia walidacja danych
|
||||
@PutMapping("/edit/{id}")
|
||||
public ResponseEntity updateClient(@PathVariable("id") long id, @RequestBody ClientDTO clientDTO) {
|
||||
public ResponseEntity<?> updateClient(@PathVariable("id") long id, @RequestBody ClientDTO clientDTO) {
|
||||
if(clientService.clientExists(id)) {
|
||||
return new ResponseEntity<>(clientService.updateClient(id, clientDTO),HttpStatus.OK);
|
||||
} else {
|
||||
@@ -52,7 +52,7 @@ public class ClientController {
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ResponseEntity deleteClient(@PathVariable("id") long id) {
|
||||
public ResponseEntity<?> deleteClient(@PathVariable("id") long id) {
|
||||
if(clientService.clientExists(id)) {
|
||||
clientService.deleteClient(id);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ 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.data.repository.query.Param;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -29,7 +30,7 @@ public class ImageController {
|
||||
private String uploadDir;
|
||||
|
||||
@PostMapping("/upload/{id}")
|
||||
public ResponseEntity<RequestResponseDTO> uploadImage(@RequestParam("file") MultipartFile file, @PathVariable("id") Long noticeId) {
|
||||
public ResponseEntity<RequestResponseDTO> uploadImage(@RequestParam("file") MultipartFile file, @PathVariable("id") Long noticeId, @Param("isMainImage") Boolean isMainImage) {
|
||||
try {
|
||||
if(file.isEmpty()) {
|
||||
return ResponseEntity.badRequest().body(new RequestResponseDTO("File is empty"));
|
||||
@@ -44,10 +45,11 @@ public class ImageController {
|
||||
}
|
||||
|
||||
String newImageName = imageService.saveImageToStorage(uploadDir, file);
|
||||
imageService.addImageNameToDB(newImageName, noticeId);
|
||||
imageService.addImageNameToDB(newImageName, noticeId, isMainImage);
|
||||
|
||||
return ResponseEntity.ok(new RequestResponseDTO("Image uploaded successfully with new name: " + newImageName));
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
return ResponseEntity.status(HttpStatus.UNSUPPORTED_MEDIA_TYPE).body(new RequestResponseDTO(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
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.dto.*;
|
||||
import _11.asktpk.artisanconnectbackend.service.ClientService;
|
||||
import _11.asktpk.artisanconnectbackend.service.NoticeService;
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
import _11.asktpk.artisanconnectbackend.utils.Tools;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RequestMapping("/api/v1/notices")
|
||||
@@ -19,14 +19,16 @@ import java.util.List;
|
||||
public class NoticeController {
|
||||
private final NoticeService noticeService;
|
||||
private final ClientService clientService;
|
||||
private final Tools tools;
|
||||
|
||||
public NoticeController(NoticeService noticeService, ClientService clientService) {
|
||||
public NoticeController(NoticeService noticeService, ClientService clientService, Tools tools) {
|
||||
this.noticeService = noticeService;
|
||||
this.clientService = clientService;
|
||||
this.tools = tools;
|
||||
}
|
||||
|
||||
@GetMapping("/get/all")
|
||||
public List<NoticeDTO> getAllNotices() {
|
||||
public List<NoticeResponseDTO> getAllNotices() {
|
||||
return noticeService.getAllNotices();
|
||||
}
|
||||
|
||||
@@ -40,57 +42,34 @@ public class NoticeController {
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity<NoticeAdditionDTO> addNotice(@RequestBody NoticeDTO dto) {
|
||||
if (!clientService.clientExists(dto.getClientId())) {
|
||||
public ResponseEntity<NoticeAdditionDTO> addNotice(@RequestBody NoticeRequestDTO dto, HttpServletRequest request) {
|
||||
Long clientId = tools.getClientIdFromRequest(request);
|
||||
if (!clientService.clientExists(clientId)) {
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.BAD_REQUEST)
|
||||
.body(new NoticeAdditionDTO("Nie znaleziono klienta o ID: " + dto.getClientId()));
|
||||
.body(new NoticeAdditionDTO("Nie znaleziono klienta o ID: " + clientId));
|
||||
}
|
||||
|
||||
if (dto.getCategory() == null) {
|
||||
dto.setClientId(clientId);
|
||||
|
||||
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"));
|
||||
}
|
||||
dto.setPublishDate(java.time.LocalDateTime.now());
|
||||
|
||||
Long newNoticeId = noticeService.addNotice(dto);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(new NoticeAdditionDTO(newNoticeId ,"Dodano ogłoszenie."));
|
||||
}
|
||||
|
||||
// TODO: zamiast dodawać tutaj pętlą, musi to robić NoticeService, trzeba zaimplementować odpowienią metodę
|
||||
@PostMapping("/bulk_add")
|
||||
public ResponseEntity<String> addNotices(@RequestBody List<NoticeDTO> notices_list) {
|
||||
ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.CREATED);
|
||||
List<String> errors = new ArrayList<>();
|
||||
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) {
|
||||
public ResponseEntity<Object> editNotice(@PathVariable("id") long id, @RequestBody NoticeRequestDTO dto, HttpServletRequest request) {
|
||||
Long clientIdFromToken = tools.getClientIdFromRequest(request);
|
||||
if (noticeService.noticeExists(id)) {
|
||||
if (!noticeService.isNoticeOwnedByClient(id, clientIdFromToken)) {
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(new RequestResponseDTO("Nie masz uprawnień do edycji tego ogłoszenia."));
|
||||
}
|
||||
try {
|
||||
return new ResponseEntity<>(noticeService.updateNotice(id, dto), HttpStatus.OK);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(noticeService.updateNotice(id, dto));
|
||||
} catch (EntityNotFoundException e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
|
||||
}
|
||||
@@ -100,8 +79,13 @@ public class NoticeController {
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ResponseEntity<RequestResponseDTO> deleteNotice(@PathVariable("id") long id) {
|
||||
public ResponseEntity<RequestResponseDTO> deleteNotice(@PathVariable("id") long id, HttpServletRequest request) {
|
||||
Long clientIdFromToken = tools.getClientIdFromRequest(request);
|
||||
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);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new RequestResponseDTO("Pomyślnie usunięto ogłoszenie o ID: " + id));
|
||||
} else {
|
||||
@@ -109,9 +93,10 @@ public class NoticeController {
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/boost/{id}")
|
||||
public ResponseEntity<RequestResponseDTO> boostNotice(@PathVariable("id") long clientId, @RequestBody NoticeBoostDTO dto) {
|
||||
if (!noticeService.isNoticeOwnedByClient(dto.getNoticeId(), clientId)) {
|
||||
@PostMapping("/boost")
|
||||
public ResponseEntity<RequestResponseDTO> boostNotice(@RequestBody NoticeBoostDTO dto, HttpServletRequest request) {
|
||||
Long clientId = tools.getClientIdFromRequest(request);
|
||||
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());
|
||||
|
||||
@@ -1,51 +1,136 @@
|
||||
package _11.asktpk.artisanconnectbackend.controller;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.dto.*;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Client;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Order;
|
||||
import _11.asktpk.artisanconnectbackend.service.ClientService;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Payment;
|
||||
import _11.asktpk.artisanconnectbackend.service.OrderService;
|
||||
import _11.asktpk.artisanconnectbackend.service.PaymentService;
|
||||
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.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/orders")
|
||||
public class OrderController {
|
||||
|
||||
private final OrderService orderService;
|
||||
private final PaymentService paymentService;
|
||||
private final Tools tools;
|
||||
|
||||
public OrderController(OrderService orderService, PaymentService paymentService) {
|
||||
public OrderController(OrderService orderService, PaymentService paymentService, Tools tools) {
|
||||
this.orderService = orderService;
|
||||
this.paymentService = paymentService;
|
||||
this.tools = tools;
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity addClient(@RequestBody OrderDTO orderDTO) {
|
||||
return new ResponseEntity<>(orderService.addOrder(orderDTO), HttpStatus.CREATED);
|
||||
public ResponseEntity<?> addClient(@RequestBody OrderDTO orderDTO, HttpServletRequest request) {
|
||||
orderDTO.setClientId(tools.getClientIdFromRequest(request));
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(orderService.addOrder(orderDTO));
|
||||
}
|
||||
|
||||
@PutMapping("/changeStatus")
|
||||
public ResponseEntity changeStatus(@RequestBody OrderStatusDTO orderStatusDTO) {
|
||||
return new ResponseEntity<>(orderService.changeOrderStatus(orderStatusDTO.getId(),orderStatusDTO.getStatus()), HttpStatus.OK);
|
||||
public ResponseEntity<?> changeStatus(@RequestBody OrderStatusDTO orderStatusDTO) {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(orderService.changeOrderStatus(orderStatusDTO.getId(), orderStatusDTO.getStatus()));
|
||||
}
|
||||
|
||||
@PostMapping("/token")
|
||||
public ResponseEntity<?> fetchToken() {
|
||||
Order order = orderService.getOrderById(1L);
|
||||
OAuthPaymentResponseDTO authPaymentDTO= paymentService.getOAuthToken();
|
||||
public ResponseEntity<?> fetchToken(@RequestParam Long orderId) {
|
||||
Order order = orderService.getOrderById(orderId);
|
||||
Client client = order.getClient();
|
||||
OAuthPaymentResponseDTO authPaymentDTO = paymentService.getOAuthToken();
|
||||
TransactionPaymentRequestDTO.Payer payer = new TransactionPaymentRequestDTO.Payer(
|
||||
"patryk@test.pl", "Patryk Test");
|
||||
client.getEmail(), client.getFirstName()+' '+client.getLastName());
|
||||
|
||||
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);
|
||||
|
||||
return ResponseEntity.ok(response);
|
||||
TransactionPaymentRequestDTO.Callbacks callbacks = new TransactionPaymentRequestDTO.Callbacks();
|
||||
TransactionPaymentRequestDTO.PayerUrls payerUrls = new TransactionPaymentRequestDTO.PayerUrls();
|
||||
payerUrls.setSuccess("com.hamx.artisanconnect://dashboard/userNotices");
|
||||
payerUrls.setError("com.hamx.artisanconnect://dashboard/userNotices");
|
||||
callbacks.setPayerUrls(payerUrls);
|
||||
|
||||
TransactionPaymentRequestDTO paymentRequest = new TransactionPaymentRequestDTO(
|
||||
order.getAmount(), paymentDescription, payer, callbacks);
|
||||
|
||||
String response = paymentService.createTransaction(order, authPaymentDTO.getAccess_token(), paymentRequest);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(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,9 +39,6 @@ public class PaymentController {
|
||||
|
||||
@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");
|
||||
@@ -54,7 +51,6 @@ public class PaymentController {
|
||||
);
|
||||
|
||||
if (!expectedMd5.equals(md5sum)) {
|
||||
log.warn("❌ Błędna suma kontrolna! Otrzymano: {}, Oczekiwano: {}", md5sum, expectedMd5);
|
||||
return ResponseEntity.status(400).body("INVALID CHECKSUM");
|
||||
}
|
||||
|
||||
@@ -63,7 +59,6 @@ public class PaymentController {
|
||||
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) {
|
||||
@@ -78,7 +73,6 @@ public class PaymentController {
|
||||
}
|
||||
|
||||
} else if ("false".equalsIgnoreCase(trStatus)) {
|
||||
log.warn("❌ Transakcja nieudana: {}", trId);
|
||||
payment.setStatus(Enums.PaymentStatus.INCORRECT);
|
||||
|
||||
if (payment.getOrder() != null) {
|
||||
@@ -87,10 +81,7 @@ public class PaymentController {
|
||||
}
|
||||
|
||||
paymentRepository.save(payment);
|
||||
} else {
|
||||
log.warn("⚠️ Brak płatności o tr_id={}", trId);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok("TRUE");
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.util.Map;
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/vars")
|
||||
public class VariablesController {
|
||||
|
||||
@GetMapping("/categories")
|
||||
public List<CategoriesDTO> getAllVariables() {
|
||||
List<CategoriesDTO> categoriesDTOList = new ArrayList<>();
|
||||
@@ -31,10 +30,4 @@ public class VariablesController {
|
||||
public List<Enums.Status> getAllStatuses() {
|
||||
return List.of(Enums.Status.values());
|
||||
}
|
||||
|
||||
@GetMapping("/roles")
|
||||
public List<Enums.Role> getAllRoles() {
|
||||
return List.of(Enums.Role.values());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,35 +1,39 @@
|
||||
package _11.asktpk.artisanconnectbackend.controller;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeResponseDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.RequestResponseDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.WishlistDTO;
|
||||
import _11.asktpk.artisanconnectbackend.service.ClientService;
|
||||
import _11.asktpk.artisanconnectbackend.service.NoticeService;
|
||||
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.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/wishlist")
|
||||
public class WishlistController {
|
||||
private final WishlistService wishlistService;
|
||||
private final ClientService clientService;
|
||||
private final NoticeService noticeService;
|
||||
private final Tools tools;
|
||||
|
||||
public WishlistController(WishlistService wishlistService, ClientService clientService, NoticeService noticeService) {
|
||||
public WishlistController(WishlistService wishlistService, ClientService clientService, NoticeService noticeService, Tools tools) {
|
||||
this.wishlistService = wishlistService;
|
||||
this.clientService = clientService;
|
||||
this.noticeService = noticeService;
|
||||
this.tools = tools;
|
||||
}
|
||||
|
||||
@PostMapping("/toggle")
|
||||
public ResponseEntity<RequestResponseDTO> toggleWishlist(@RequestBody WishlistDTO wishlistDTO) {
|
||||
Long noticeId = wishlistDTO.getNoticeId();
|
||||
Long clientId = wishlistDTO.getClientId();
|
||||
NoticeDTO noticeDTO = noticeService.getNoticeById(noticeId);
|
||||
if (noticeDTO == null) {
|
||||
@PostMapping("/toggle/{noticeId}")
|
||||
public ResponseEntity<RequestResponseDTO> toggleWishlist(@PathVariable Long noticeId, HttpServletRequest request) {
|
||||
Long clientId = tools.getClientIdFromRequest(request);
|
||||
NoticeResponseDTO noticeResponseDTO = noticeService.getNoticeById(noticeId);
|
||||
if (noticeResponseDTO == null) {
|
||||
return ResponseEntity.badRequest().body(new RequestResponseDTO("Notice not found"));
|
||||
}
|
||||
boolean added = wishlistService.toggleWishlist(
|
||||
@@ -51,9 +55,8 @@ public class WishlistController {
|
||||
// }
|
||||
|
||||
@GetMapping("/")
|
||||
public List<NoticeDTO> getWishlistForClient() {
|
||||
// TODO: Replace with actual client ID from authentication context
|
||||
Long clientId = 1L;
|
||||
public List<NoticeResponseDTO> getWishlistForClient(HttpServletRequest request) {
|
||||
Long clientId = tools.getClientIdFromRequest(request);
|
||||
return wishlistService.getNoticesInWishlist(clientId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package _11.asktpk.artisanconnectbackend.customExceptions;
|
||||
|
||||
public class ClientAlreadyExistsException extends Exception {
|
||||
public ClientAlreadyExistsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package _11.asktpk.artisanconnectbackend.customExceptions;
|
||||
|
||||
public class WrongLoginPasswordException extends Exception {
|
||||
public WrongLoginPasswordException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter
|
||||
public class AttributeDto {
|
||||
private String name;
|
||||
private String value;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter
|
||||
public class AuthRequestDTO {
|
||||
private String email;
|
||||
private String password;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter @AllArgsConstructor
|
||||
public class AuthResponseDTO {
|
||||
private Long user_id;
|
||||
private String user_role;
|
||||
private String token;
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import jakarta.validation.constraints.Email;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums.Role;
|
||||
|
||||
@Getter @Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ClientDTO {
|
||||
private Long id;
|
||||
|
||||
@@ -18,5 +20,5 @@ public class ClientDTO {
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String image;
|
||||
private Role role;
|
||||
private String role;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter
|
||||
public class ClientRegistrationDTO {
|
||||
@Email
|
||||
@NotBlank
|
||||
private String email;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String password;
|
||||
}
|
||||
@@ -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 GoogleAuthRequestDTO {
|
||||
private String googleToken;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
public class ImageRequestDTO {
|
||||
public Resource image;
|
||||
public Long noticeId;
|
||||
public boolean isMainImage;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import java.util.List;
|
||||
|
||||
@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;
|
||||
|
||||
private List<AttributeDto> attributes;
|
||||
|
||||
public NoticeRequestDTO() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.entities.AttributesNotice;
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -9,7 +8,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Getter @Setter
|
||||
public class NoticeDTO {
|
||||
public class NoticeResponseDTO {
|
||||
private long noticeId;
|
||||
|
||||
private String title;
|
||||
@@ -26,11 +25,9 @@ public class NoticeDTO {
|
||||
|
||||
private LocalDateTime publishDate;
|
||||
|
||||
private List<AttributesNotice> attributesNotices;
|
||||
private List<AttributeDto> attributes;
|
||||
|
||||
private boolean isWishlisted;
|
||||
|
||||
public NoticeDTO() {
|
||||
public NoticeResponseDTO() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Getter @Setter
|
||||
public class OrderWithPaymentsDTO {
|
||||
private Long orderId;
|
||||
private String orderType;
|
||||
private String status;
|
||||
private Double amount;
|
||||
private LocalDateTime createdAt;
|
||||
private List<PaymentDTO> payments;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -10,4 +10,8 @@ public class RequestResponseDTO {
|
||||
public RequestResponseDTO(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String toJSON() {
|
||||
return "{\"message\":\"" + message + "\"}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ToString
|
||||
public class TransactionPaymentRequestDTO {
|
||||
private double amount;
|
||||
private String description;
|
||||
private Payer payer;
|
||||
private Callbacks callbacks;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -22,4 +21,21 @@ public class TransactionPaymentRequestDTO {
|
||||
private String email;
|
||||
private String name;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class Callbacks {
|
||||
private PayerUrls payerUrls;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class PayerUrls {
|
||||
private String success;
|
||||
private String error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,27 @@ import lombok.Setter;
|
||||
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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package _11.asktpk.artisanconnectbackend.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "attribute_values")
|
||||
@Getter @Setter
|
||||
public class AttributeValues {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@@ -14,6 +17,4 @@ public class AttributeValues {
|
||||
private Attributes attribute;
|
||||
|
||||
private String value;
|
||||
|
||||
// Getters, setters, and constructors
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package _11.asktpk.artisanconnectbackend.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Setter;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "attributes")
|
||||
@Getter @Setter
|
||||
public class Attributes {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@@ -12,8 +16,6 @@ public class Attributes {
|
||||
|
||||
private String name;
|
||||
|
||||
@OneToMany(mappedBy = "attribute", cascade = CascadeType.ALL)
|
||||
@OneToMany(mappedBy = "attribute")
|
||||
private List<AttributeValues> attributeValues;
|
||||
|
||||
// Getters, setters, and constructors
|
||||
}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
package _11.asktpk.artisanconnectbackend.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Setter;
|
||||
import lombok.Getter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "attributes_notice")
|
||||
@Getter @Setter
|
||||
public class AttributesNotice {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "id_notice")
|
||||
private Notice notice;
|
||||
private Long notice_id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "id_value")
|
||||
private AttributeValues attributeValue;
|
||||
|
||||
// Getters, setters, and constructors
|
||||
}
|
||||
@@ -1,17 +1,26 @@
|
||||
package _11.asktpk.artisanconnectbackend.entities;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.utils.Enums.Role;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "clients")
|
||||
@Getter @Setter
|
||||
@NoArgsConstructor
|
||||
public class Client {
|
||||
public Client(String email, String password, String firstName, String lastName) {
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
@@ -24,14 +33,15 @@ public class Client {
|
||||
|
||||
private String lastName;
|
||||
|
||||
private String image; // Optional field
|
||||
private String image;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@ManyToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "role_id", referencedColumnName = "id")
|
||||
private Role role;
|
||||
|
||||
// @OneToMany(mappedBy = "client", cascade = CascadeType.ALL)
|
||||
// private List<Notice> notices;
|
||||
|
||||
@OneToMany(mappedBy = "client", cascade = CascadeType.ALL)
|
||||
private List<Order> orders;
|
||||
|
||||
@CreationTimestamp
|
||||
private Date createdAt;
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package _11.asktpk.artisanconnectbackend.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "global_variables")
|
||||
public class GlobalVariables {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
// Getters, setters, and constructors
|
||||
}
|
||||
@@ -35,10 +35,10 @@ public class Notice {
|
||||
|
||||
private LocalDateTime publishDate;
|
||||
|
||||
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||
@OneToMany(mappedBy = "notice_id")
|
||||
private List<AttributesNotice> attributesNotices;
|
||||
|
||||
@OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||
@OneToMany(mappedBy = "notice")
|
||||
private List<Order> orders;
|
||||
|
||||
// @OneToMany(mappedBy = "notice", cascade = CascadeType.ALL)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package _11.asktpk.artisanconnectbackend.entities;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "roles")
|
||||
@Getter
|
||||
@Setter
|
||||
public class Role {
|
||||
@Id
|
||||
private Long id;
|
||||
@Column(name="rolename")
|
||||
private String role;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package _11.asktpk.artisanconnectbackend.repository;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.entities.AttributeValues;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Attributes;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface AttributeValuesRepository extends JpaRepository<AttributeValues, Long> {
|
||||
|
||||
Optional<AttributeValues> findByAttributeAndValue(Attributes attribute, String value);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package _11.asktpk.artisanconnectbackend.repository;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.entities.AttributesNotice;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface AttributesNoticeRepository extends JpaRepository<AttributesNotice, Long> {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package _11.asktpk.artisanconnectbackend.repository;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.entities.Attributes;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface AttributesRepository extends JpaRepository<Attributes, Long> {
|
||||
Optional<Attributes> findByName(String name);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package _11.asktpk.artisanconnectbackend.repository;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.entities.Client;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface ClientRepository extends JpaRepository<Client, Long> {
|
||||
Client findByEmail(String email);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package _11.asktpk.artisanconnectbackend.repository;
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,10 @@ import _11.asktpk.artisanconnectbackend.entities.Order;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface OrderRepository extends JpaRepository<Order, Long> {
|
||||
|
||||
List<Order> findByClientId(Long clientId);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,12 @@ import _11.asktpk.artisanconnectbackend.entities.Payment;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
||||
Optional<Payment> findByTransactionId(String transactionId);
|
||||
|
||||
List<Payment> findAllByOrderId(Long id);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package _11.asktpk.artisanconnectbackend.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Role;
|
||||
|
||||
@Repository
|
||||
public interface RolesRepository extends JpaRepository<Role, String> {
|
||||
Role findRoleById(Long id);
|
||||
|
||||
Role findRoleByRole(String role);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package _11.asktpk.artisanconnectbackend.security;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.dto.RequestResponseDTO;
|
||||
import io.jsonwebtoken.ExpiredJwtException;
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@Component
|
||||
public class JwtRequestFilter extends OncePerRequestFilter {
|
||||
|
||||
private final JwtUtil jwtUtil;
|
||||
|
||||
public JwtRequestFilter(JwtUtil jwtUtil) {
|
||||
this.jwtUtil = jwtUtil;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull FilterChain chain)
|
||||
throws ServletException, IOException {
|
||||
|
||||
final String authorizationHeader = request.getHeader("Authorization");
|
||||
|
||||
String email = null;
|
||||
String jwt = null;
|
||||
|
||||
if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) {
|
||||
jwt = authorizationHeader.substring(7);
|
||||
|
||||
try {
|
||||
if (jwtUtil.isBlacklisted(jwt) || !jwtUtil.isLatestToken(jwt)) {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
String jsonResponse = "{\"error\": \"Token is invalid. Please login again.\"}";
|
||||
response.getWriter().write(jsonResponse);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
email = jwtUtil.extractEmail(jwt);
|
||||
} catch (ExpiredJwtException expiredJwtException) {
|
||||
logger.error(expiredJwtException.getMessage());
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
response.getWriter().write(new RequestResponseDTO("Authentication token is expired. Please login again.").toJSON());
|
||||
return;
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
response.getWriter().write(new RequestResponseDTO(e.getMessage()).toJSON());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (email != null && SecurityContextHolder.getContext().getAuthentication() == null) {
|
||||
String role = jwtUtil.extractRole(jwt);
|
||||
|
||||
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(
|
||||
email, null, Collections.singletonList(new SimpleGrantedAuthority("ROLE_" + role)));
|
||||
|
||||
authToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
||||
SecurityContextHolder.getContext().setAuthentication(authToken);
|
||||
}
|
||||
|
||||
// logger.info("Token of user " + jwtUtil.extractEmail(jwt) + (jwtUtil.isTokenExpired(jwt) ? " is expired" : " is not expired"));
|
||||
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package _11.asktpk.artisanconnectbackend.security;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Component
|
||||
public class JwtUtil {
|
||||
|
||||
@Value("${jwt.secret:defaultSecretKeyNeedsToBeAtLeast32BytesLong}")
|
||||
private String secret;
|
||||
|
||||
@Value("${jwt.expiration}")
|
||||
private long expiration;
|
||||
|
||||
// sterowanie tokenami wygasnietymi
|
||||
private final Set<String> blacklistedTokens = ConcurrentHashMap.newKeySet();
|
||||
|
||||
public void blacklistToken(String token) {
|
||||
blacklistedTokens.add(token);
|
||||
}
|
||||
|
||||
public boolean isBlacklisted(String token) {
|
||||
return blacklistedTokens.contains(token);
|
||||
}
|
||||
|
||||
|
||||
private SecretKey getSigningKey() {
|
||||
return Keys.hmacShaKeyFor(secret.getBytes());
|
||||
}
|
||||
|
||||
private final Map<String, String> userActiveTokens = new ConcurrentHashMap<>();
|
||||
|
||||
public boolean isLatestToken(String token) {
|
||||
String email = extractEmail(token);
|
||||
String tokenId = extractTokenId(token);
|
||||
String latestTokenId = userActiveTokens.get(email);
|
||||
|
||||
return latestTokenId != null && latestTokenId.equals(tokenId);
|
||||
}
|
||||
|
||||
public String generateToken(String email, String role, Long userId) {
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
claims.put("role", role);
|
||||
claims.put("userId", userId);
|
||||
claims.put("tokenId", UUID.randomUUID().toString());
|
||||
|
||||
String token = createToken(claims, email);
|
||||
|
||||
userActiveTokens.put(email, extractTokenId(token));
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
private String createToken(Map<String, Object> claims, String subject) {
|
||||
return Jwts.builder()
|
||||
.setClaims(claims)
|
||||
.setSubject(subject)
|
||||
.setIssuedAt(new Date())
|
||||
.setExpiration(new Date(System.currentTimeMillis() + expiration))
|
||||
.signWith(getSigningKey(), SignatureAlgorithm.HS256)
|
||||
.compact();
|
||||
}
|
||||
|
||||
public String extractTokenId(String token) {
|
||||
return extractAllClaims(token).get("tokenId", String.class);
|
||||
}
|
||||
|
||||
public String extractEmail(String token) {
|
||||
return extractClaim(token, Claims::getSubject);
|
||||
}
|
||||
|
||||
public String extractRole(String token) {
|
||||
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) {
|
||||
final Claims claims = extractAllClaims(token);
|
||||
return claimsResolver.apply(claims);
|
||||
}
|
||||
|
||||
private Claims extractAllClaims(String token) {
|
||||
return Jwts.parserBuilder()
|
||||
.setSigningKey(getSigningKey())
|
||||
.build()
|
||||
.parseClaimsJws(token)
|
||||
.getBody();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package _11.asktpk.artisanconnectbackend.service;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.customExceptions.ClientAlreadyExistsException;
|
||||
import _11.asktpk.artisanconnectbackend.customExceptions.WrongLoginPasswordException;
|
||||
import _11.asktpk.artisanconnectbackend.dto.AuthResponseDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.ClientDTO;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Client;
|
||||
import _11.asktpk.artisanconnectbackend.security.JwtUtil;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AuthService {
|
||||
|
||||
private final ClientService clientService;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final JwtUtil jwtUtil;
|
||||
|
||||
public AuthService(ClientService clientService, JwtUtil jwtUtil, PasswordEncoder passwordEncoder) {
|
||||
this.clientService = clientService;
|
||||
this.jwtUtil = jwtUtil;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
public AuthResponseDTO login(String email, String password) throws Exception {
|
||||
Client client = clientService.getClientByEmail(email);
|
||||
if (client == null) {
|
||||
throw new Exception("Klient o podanym adresie nie istnieje!");
|
||||
}
|
||||
|
||||
if (passwordEncoder.matches(password, client.getPassword())) {
|
||||
String token = jwtUtil.generateToken(client.getEmail(), client.getRole().getRole(), client.getId());
|
||||
log.info("User logged in with {}", client.getEmail());
|
||||
return new AuthResponseDTO(client.getId(), client.getRole().getRole(), token);
|
||||
}
|
||||
throw new WrongLoginPasswordException("Login lub hasło jest niepoprawny!");
|
||||
}
|
||||
|
||||
public AuthResponseDTO register(String email, String password, String firstName, String lastName) throws Exception {
|
||||
if (clientService.getClientByEmail(email) != null) {
|
||||
throw new ClientAlreadyExistsException("Klient o podanym adresie email już istnieje!");
|
||||
}
|
||||
|
||||
Client newClient = new Client();
|
||||
newClient.setEmail(email);
|
||||
newClient.setPassword(passwordEncoder.encode(password));
|
||||
newClient.setFirstName(firstName);
|
||||
newClient.setLastName(lastName);
|
||||
|
||||
ClientDTO savedClient = clientService.registerClient(newClient);
|
||||
if (savedClient != null) {
|
||||
log.info("New user registered with {}", savedClient.getEmail());
|
||||
String token = jwtUtil.generateToken(
|
||||
savedClient.getEmail(),
|
||||
savedClient.getRole(),
|
||||
savedClient.getId()
|
||||
);
|
||||
|
||||
return new AuthResponseDTO(savedClient.getId(), savedClient.getRole(), token);
|
||||
} else {
|
||||
throw new Exception("Rejestracja nie powiodła się!");
|
||||
}
|
||||
}
|
||||
|
||||
public void logout(String token) {
|
||||
jwtUtil.blacklistToken(token);
|
||||
}
|
||||
|
||||
public AuthResponseDTO googleLogin(String googleAccessToken) throws Exception {
|
||||
String googleUserInfoUrl = "https://www.googleapis.com/oauth2/v3/userinfo";
|
||||
|
||||
ResponseEntity<Map> response;
|
||||
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setBearerAuth(googleAccessToken);
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
response = restTemplate.exchange(
|
||||
googleUserInfoUrl, HttpMethod.GET, new HttpEntity<>(headers), Map.class);
|
||||
|
||||
|
||||
Map<String, Object> userInfo = response.getBody();
|
||||
|
||||
// String googleId = (String) userInfo.get("sub"); Potencjalnie możemy używać googlowskiego ID, ale to ma konflikt z naszym generowanym
|
||||
if (userInfo == null) {
|
||||
throw new Exception("Pobrany użytkownik jest pusty! Może to być spowodowane niepoprawnym tokenem lub brakiem dostępu do Google API.");
|
||||
}
|
||||
String email = (String) userInfo.get("email");
|
||||
String name = (String) userInfo.get("name");
|
||||
|
||||
Client client = clientService.getClientByEmail(email);
|
||||
if (client == null) {
|
||||
client = new Client();
|
||||
client.setEmail(email);
|
||||
client.setFirstName(name);
|
||||
client.setRole(clientService.getUserRole()); // to pobiera po prostu role "USER" z tabeli w bazie
|
||||
clientService.saveClientToDB(client);
|
||||
}
|
||||
|
||||
String jwt = jwtUtil.generateToken(client.getEmail(), client.getRole().getRole(), client.getId());
|
||||
log.info("User authenticated with google: {}", client.getEmail());
|
||||
return new AuthResponseDTO(
|
||||
client.getId(),
|
||||
client.getRole().getRole(),
|
||||
jwt
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package _11.asktpk.artisanconnectbackend.service;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.dto.ClientDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.ClientRegistrationDTO;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Client;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Role;
|
||||
import _11.asktpk.artisanconnectbackend.repository.ClientRepository;
|
||||
import _11.asktpk.artisanconnectbackend.repository.RolesRepository;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -11,37 +14,61 @@ import java.util.List;
|
||||
@Service
|
||||
public class ClientService {
|
||||
private final ClientRepository clientRepository;
|
||||
private final RolesRepository rolesRepository;
|
||||
|
||||
public ClientService(ClientRepository clientRepository) {
|
||||
public ClientService(ClientRepository clientRepository, RolesRepository rolesRepository) {
|
||||
this.clientRepository = clientRepository;
|
||||
this.rolesRepository = rolesRepository;
|
||||
}
|
||||
|
||||
private ClientDTO toDto(Client client) {
|
||||
public ClientDTO toDto(Client client) {
|
||||
if(client == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ClientDTO dto = new ClientDTO();
|
||||
|
||||
dto.setId(client.getId());
|
||||
dto.setFirstName(client.getFirstName());
|
||||
dto.setLastName(client.getLastName());
|
||||
dto.setEmail(client.getEmail());
|
||||
dto.setRole(client.getRole());
|
||||
dto.setRole(client.getRole().getRole());
|
||||
dto.setImage(client.getImage());
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private Client fromDto(ClientDTO dto) {
|
||||
public Client fromDto(ClientDTO dto) {
|
||||
Client client = new Client();
|
||||
Role rola;
|
||||
|
||||
if (clientRepository.findById(dto.getId()).isPresent()) {
|
||||
rola = clientRepository.findById(dto.getId()).get().getRole();
|
||||
} else {
|
||||
rola = new Role();
|
||||
rola.setRole("USER");
|
||||
}
|
||||
|
||||
client.setId(dto.getId());
|
||||
client.setFirstName(dto.getFirstName());
|
||||
client.setLastName(dto.getLastName());
|
||||
client.setEmail(dto.getEmail());
|
||||
client.setRole(dto.getRole());
|
||||
client.setRole(rola);
|
||||
client.setImage(dto.getImage());
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
private Client fromDto(ClientRegistrationDTO dto) {
|
||||
Client client = new Client();
|
||||
|
||||
client.setFirstName(dto.getFirstName());
|
||||
client.setLastName(dto.getLastName());
|
||||
client.setEmail(dto.getEmail());
|
||||
client.setPassword(dto.getPassword());
|
||||
return client;
|
||||
}
|
||||
|
||||
public List<ClientDTO> getAllClients() {
|
||||
List<Client> clients = clientRepository.findAll();
|
||||
return clients.stream().map(this::toDto).toList();
|
||||
@@ -51,6 +78,18 @@ public class ClientService {
|
||||
return clientRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public ClientDTO getClientByIdDTO(Long id) {
|
||||
return toDto(clientRepository.findById(id).orElse(null));
|
||||
}
|
||||
|
||||
public Client getClientByEmail(String email) {
|
||||
return clientRepository.findByEmail(email);
|
||||
}
|
||||
|
||||
public Role getUserRole() {
|
||||
return rolesRepository.findRoleByRole("USER");
|
||||
}
|
||||
|
||||
public boolean clientExists(Long id) {
|
||||
return clientRepository.existsById(id);
|
||||
}
|
||||
@@ -59,15 +98,21 @@ public class ClientService {
|
||||
return toDto(clientRepository.save(fromDto(clientDTO)));
|
||||
}
|
||||
|
||||
public Client saveClientToDB(Client client) {
|
||||
return clientRepository.save(client);
|
||||
}
|
||||
|
||||
public ClientDTO updateClient(long id, ClientDTO clientDTO) {
|
||||
Client existingClient = clientRepository.findById(id)
|
||||
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id));
|
||||
|
||||
Role newRole = rolesRepository.findRoleByRole(clientDTO.getRole());
|
||||
|
||||
existingClient.setEmail(clientDTO.getEmail());
|
||||
existingClient.setFirstName(clientDTO.getFirstName());
|
||||
existingClient.setLastName(clientDTO.getLastName());
|
||||
existingClient.setImage(clientDTO.getImage());
|
||||
existingClient.setRole(clientDTO.getRole());
|
||||
existingClient.setRole(newRole);
|
||||
|
||||
return toDto(clientRepository.save(existingClient));
|
||||
}
|
||||
@@ -75,4 +120,9 @@ public class ClientService {
|
||||
public void deleteClient(Long id) {
|
||||
clientRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public ClientDTO registerClient(Client client) {
|
||||
client.setRole(getUserRole()); // ID 1 - USER role
|
||||
return toDto(clientRepository.save(client));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.setFrom("noreply@zikor.pl");
|
||||
message.setTo(email.getTo());
|
||||
message.setSubject(email.getSubject());
|
||||
message.setText(email.getBody());
|
||||
mailSender.send(message);
|
||||
}
|
||||
}
|
||||
@@ -40,10 +40,11 @@ public class ImageService {
|
||||
return uniqueFileName;
|
||||
}
|
||||
|
||||
public void addImageNameToDB(String filename, Long noticeId) {
|
||||
public void addImageNameToDB(String filename, Long noticeId, boolean isMainImage) {
|
||||
Image image = new Image();
|
||||
image.setImageName(filename);
|
||||
image.setNoticeId(noticeId);
|
||||
image.setMainImage(isMainImage);
|
||||
imageRepository.save(image);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package _11.asktpk.artisanconnectbackend.service;
|
||||
|
||||
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.dto.NoticeDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.AttributeDto;
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeRequestDTO;
|
||||
import _11.asktpk.artisanconnectbackend.entities.*;
|
||||
import _11.asktpk.artisanconnectbackend.repository.*;
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeResponseDTO;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -14,7 +14,6 @@ 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 {
|
||||
@@ -25,25 +24,32 @@ public class NoticeService {
|
||||
|
||||
private final NoticeRepository noticeRepository;
|
||||
private final ClientRepository clientRepository;
|
||||
private final WishlistService wishlistService;
|
||||
private final ImageService imageService;
|
||||
private final AttributesRepository attributesRepository;
|
||||
private final AttributeValuesRepository attributeValuesRepository;
|
||||
private final AttributesNoticeRepository attributesNoticeRepository;
|
||||
|
||||
public NoticeService(NoticeRepository noticeRepository, ClientRepository clientRepository, WishlistService wishlistService, ImageService imageService) {
|
||||
public NoticeService(NoticeRepository noticeRepository,
|
||||
ClientRepository clientRepository,
|
||||
ImageService imageService,
|
||||
AttributesRepository attributesRepository,
|
||||
AttributeValuesRepository attributeValuesRepository,
|
||||
AttributesNoticeRepository attributesNoticeRepository) {
|
||||
this.noticeRepository = noticeRepository;
|
||||
this.clientRepository = clientRepository;
|
||||
this.wishlistService = wishlistService;
|
||||
this.imageService = imageService;
|
||||
this.attributesRepository = attributesRepository;
|
||||
this.attributeValuesRepository = attributeValuesRepository;
|
||||
this.attributesNoticeRepository = attributesNoticeRepository;
|
||||
}
|
||||
|
||||
public Notice fromDTO(NoticeDTO dto) {
|
||||
public Notice fromDTO(NoticeRequestDTO dto) {
|
||||
Notice notice = new Notice();
|
||||
notice.setTitle(dto.getTitle());
|
||||
notice.setDescription(dto.getDescription());
|
||||
notice.setPrice(dto.getPrice());
|
||||
notice.setCategory(dto.getCategory());
|
||||
notice.setStatus(dto.getStatus());
|
||||
notice.setPublishDate(dto.getPublishDate());
|
||||
notice.setAttributesNotices(dto.getAttributesNotices());
|
||||
|
||||
Client client = clientRepository.findById(dto.getClientId())
|
||||
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono klienta o ID: " + dto.getClientId()));
|
||||
@@ -52,15 +58,8 @@ public class NoticeService {
|
||||
return notice;
|
||||
}
|
||||
|
||||
private NoticeDTO toDTO(Notice notice) {
|
||||
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);
|
||||
}
|
||||
private NoticeResponseDTO toDTO(Notice notice) {
|
||||
NoticeResponseDTO dto = new NoticeResponseDTO();
|
||||
dto.setNoticeId(notice.getIdNotice());
|
||||
dto.setTitle(notice.getTitle());
|
||||
dto.setClientId(notice.getClient().getId());
|
||||
@@ -69,20 +68,30 @@ public class NoticeService {
|
||||
dto.setCategory(notice.getCategory());
|
||||
dto.setStatus(notice.getStatus());
|
||||
dto.setPublishDate(notice.getPublishDate());
|
||||
dto.setAttributesNotices(notice.getAttributesNotices());
|
||||
dto.setWishlisted(isWishlisted);
|
||||
|
||||
List<AttributeDto> attributes = new ArrayList<>();
|
||||
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;
|
||||
}
|
||||
|
||||
public List<NoticeDTO> getAllNotices() {
|
||||
List<NoticeDTO> result = new ArrayList<>();
|
||||
public List<NoticeResponseDTO> getAllNotices() {
|
||||
List<NoticeResponseDTO> result = new ArrayList<>();
|
||||
for (Notice notice : noticeRepository.findAll()) {
|
||||
result.add(toDTO(notice));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public NoticeDTO getNoticeById(Long id) {
|
||||
public NoticeResponseDTO getNoticeById(Long id) {
|
||||
Notice notice = noticeRepository.findById(id)
|
||||
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id));
|
||||
return toDTO(notice);
|
||||
@@ -93,15 +102,48 @@ public class NoticeService {
|
||||
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id));
|
||||
}
|
||||
|
||||
public Long addNotice(NoticeDTO dto) {
|
||||
return noticeRepository.save(fromDTO(dto)).getIdNotice();
|
||||
public Long addNotice(NoticeRequestDTO dto) {
|
||||
Notice notice = fromDTO(dto);
|
||||
notice.setPublishDate(LocalDateTime.now());
|
||||
Notice savedNotice = noticeRepository.save(notice);
|
||||
|
||||
if (dto.getAttributes() != null && !dto.getAttributes().isEmpty()) {
|
||||
saveAttributes(savedNotice.getIdNotice(), dto.getAttributes());
|
||||
}
|
||||
|
||||
return savedNotice.getIdNotice();
|
||||
}
|
||||
|
||||
private void saveAttributes(Long noticeId, List<AttributeDto> attributeDtos) {
|
||||
for (AttributeDto attributeDto : attributeDtos) {
|
||||
Attributes attribute = attributesRepository.findByName(attributeDto.getName())
|
||||
.orElseGet(() -> {
|
||||
Attributes newAttribute = new Attributes();
|
||||
newAttribute.setName(attributeDto.getName());
|
||||
return attributesRepository.save(newAttribute);
|
||||
});
|
||||
|
||||
AttributeValues attributeValue = attributeValuesRepository
|
||||
.findByAttributeAndValue(attribute, attributeDto.getValue())
|
||||
.orElseGet(() -> {
|
||||
AttributeValues newValue = new AttributeValues();
|
||||
newValue.setAttribute(attribute);
|
||||
newValue.setValue(attributeDto.getValue());
|
||||
return attributeValuesRepository.save(newValue);
|
||||
});
|
||||
|
||||
AttributesNotice attributesNotice = new AttributesNotice();
|
||||
attributesNotice.setNotice_id(noticeId);
|
||||
attributesNotice.setAttributeValue(attributeValue);
|
||||
attributesNoticeRepository.save(attributesNotice);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean noticeExists(Long id) {
|
||||
return noticeRepository.existsById(id);
|
||||
}
|
||||
|
||||
public NoticeDTO updateNotice(Long id, NoticeDTO dto) {
|
||||
public NoticeResponseDTO updateNotice(Long id, NoticeRequestDTO dto) {
|
||||
Notice existingNotice = noticeRepository.findById(id)
|
||||
.orElseThrow(() -> new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id));
|
||||
|
||||
@@ -110,7 +152,6 @@ public class NoticeService {
|
||||
existingNotice.setPrice(dto.getPrice());
|
||||
existingNotice.setCategory(dto.getCategory());
|
||||
existingNotice.setStatus(dto.getStatus());
|
||||
existingNotice.setAttributesNotices(dto.getAttributesNotices());
|
||||
|
||||
if (dto.getClientId() != null && !dto.getClientId().equals(existingNotice.getClient().getId())) {
|
||||
Client client = clientRepository.findById(dto.getClientId())
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.stereotype.Service;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Order;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class OrderService {
|
||||
@@ -56,8 +57,7 @@ public class OrderService {
|
||||
|
||||
|
||||
public Long addOrder(OrderDTO orderDTO) {
|
||||
Order order = fromDTO(orderDTO);
|
||||
return orderRepository.save(order).getId();
|
||||
return orderRepository.save(fromDTO(orderDTO)).getId();
|
||||
}
|
||||
|
||||
public Long changeOrderStatus(Long id, Enums.OrderStatus status) {
|
||||
@@ -76,4 +76,8 @@ public class OrderService {
|
||||
return orderRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Nie znaleziono zamówienia o ID: " + id));
|
||||
}
|
||||
|
||||
public List<Order> getOrdersByClientId(Long clientId) {
|
||||
return orderRepository.findByClientId(clientId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class PaymentService {
|
||||
private final WebClient webClient;
|
||||
@@ -69,13 +71,21 @@ public class PaymentService {
|
||||
|
||||
payment.setStatus(Enums.PaymentStatus.PENDING);
|
||||
|
||||
payment.setTransactionId(response.getTransactionId());
|
||||
payment.setTransactionId(response.getTitle());
|
||||
payment.setTransactionPaymentUrl(response.getTransactionPaymentUrl());
|
||||
paymentRepository.save(payment);
|
||||
|
||||
System.out.println(response);
|
||||
|
||||
return response.getTransactionPaymentUrl();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Payment> getPaymentsByOrderId(Long id) {
|
||||
return paymentRepository.findAllByOrderId(id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package _11.asktpk.artisanconnectbackend.service;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.dto.WishlistDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeResponseDTO;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Client;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Notice;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Wishlist;
|
||||
@@ -31,12 +31,6 @@ public class WishlistService {
|
||||
.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) {
|
||||
Optional<Wishlist> existingEntry = wishlistRepository.findByClientAndNotice(client, notice);
|
||||
|
||||
@@ -61,7 +55,7 @@ public class WishlistService {
|
||||
return dto;
|
||||
}
|
||||
|
||||
public List<NoticeDTO> getNoticesInWishlist(Long clientId) {
|
||||
public List<NoticeResponseDTO> getNoticesInWishlist(Long clientId) {
|
||||
List<Wishlist> wishlistEntries = wishlistRepository.findAllByClientId(clientId);
|
||||
|
||||
return wishlistEntries.stream()
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,41 @@
|
||||
spring.application.name=ArtisanConnectBackend
|
||||
|
||||
## PostgreSQL
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
|
||||
spring.datasource.url=${DB_URL:jdbc:postgresql://db:5432/postgres}
|
||||
spring.datasource.username=${DB_USER:postgres}
|
||||
spring.datasource.password=${DB_PASS:postgres}
|
||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
spring.datasource.username=postgres
|
||||
spring.datasource.password=postgres
|
||||
|
||||
#initial data for db injection
|
||||
#Injekcja danych przyk?adowych przy starcie bazy
|
||||
spring.sql.init.data-locations=classpath:sql/data.sql
|
||||
spring.sql.init.mode=always
|
||||
spring.jpa.defer-datasource-initialization=true
|
||||
|
||||
# create and drop table, good for testing, production set to none or comment it
|
||||
#Sposób zachowania JPA
|
||||
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
|
||||
#Gdzie uploadujemy zdj?cia i maksymalny rozmiar
|
||||
file.upload-dir=${IMAGES_UPLOAD_DIR:/app/images}
|
||||
spring.servlet.multipart.max-file-size=${MAX_FILE_SIZE:10MB}
|
||||
spring.servlet.multipart.max-request-size=${MAX_REQUEST_SIZE:10MB}
|
||||
|
||||
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
|
||||
#Ustawienia wysy?ania maili
|
||||
spring.mail.host=${MAIL_HOST}
|
||||
spring.mail.port=${MAIL_PORT}
|
||||
spring.mail.username=${MAIL_USER}
|
||||
spring.mail.password=${MAIL_PASSWORD}
|
||||
|
||||
#Ustawienia TPay
|
||||
tpay.clientId=${TPAY_CLIENT_ID}
|
||||
tpay.clientSecret=${TPAY_SECRET}
|
||||
tpay.authUrl=${TPAY_AUTH_URL}
|
||||
tpay.transactionUrl=${TPAY_TRANSACTION_URL}
|
||||
tpay.securityCode = ${TPAY_SECURITY_CODE}
|
||||
|
||||
#Ustawienia JWT
|
||||
jwt.secret=${JWT_SECRET}
|
||||
jwt.expiration=1200000
|
||||
|
||||
#Ustawienia logowania
|
||||
logging.file.name=logs/payment-notifications.log
|
||||
logging.level.TpayLogger=INFO
|
||||
logging.level.TpayLogger=INFO
|
||||
@@ -1,10 +1,15 @@
|
||||
INSERT INTO clients (email, first_name, image, last_name, password, role)
|
||||
INSERT INTO roles (id, rolename)
|
||||
VALUES
|
||||
('dignissim.tempor.arcu@aol.ca', 'Diana', 'null', 'Harrison', 'password', 'USER'),
|
||||
('john.doe@example.com', 'John', 'null', 'Doe', 'password123', 'ADMIN'),
|
||||
('jane.smith@example.com', 'Jane', 'null', 'Smith', 'securepass', 'USER'),
|
||||
('michael.brown@example.com', 'Michael', 'null', 'Brown', 'mypassword', 'USER'),
|
||||
('emily.jones@example.com', 'Emily', 'null', 'Jones', 'passw0rd', 'USER');
|
||||
(1, 'USER'),
|
||||
(2, 'ADMIN');
|
||||
|
||||
INSERT INTO clients (email, first_name, last_name, password, role_id)
|
||||
VALUES
|
||||
('dignissim.tempor.arcu@aol.ca', 'Diana', 'Harrison', 'password', 1),
|
||||
('john.doe@example.com', 'John', 'Doe', 'password123', 2),
|
||||
('jane.smith@example.com', 'Jane', 'Smith', 'securepass', 1),
|
||||
('michael.brown@example.com', 'Michael', 'Brown', 'mypassword', 1),
|
||||
('emily.jones@example.com', 'Emily', 'Jones', 'passw0rd', 1);
|
||||
|
||||
|
||||
INSERT INTO notice (title, description, client_id, price, category, status, publish_date) VALUES
|
||||
@@ -12,4 +17,45 @@ 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'),
|
||||
('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'),
|
||||
('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
|
||||
|
||||
Reference in New Issue
Block a user