Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 86e902bbfe | |||
| d9a8ffe4bd | |||
| a7c8f22658 | |||
| f31885c795 |
@@ -6,6 +6,7 @@ import _11.asktpk.artisanconnectbackend.service.NoticeService;
|
|||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@@ -29,7 +30,7 @@ public class ImageController {
|
|||||||
private String uploadDir;
|
private String uploadDir;
|
||||||
|
|
||||||
@PostMapping("/upload/{id}")
|
@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 {
|
try {
|
||||||
if(file.isEmpty()) {
|
if(file.isEmpty()) {
|
||||||
return ResponseEntity.badRequest().body(new RequestResponseDTO("File is empty"));
|
return ResponseEntity.badRequest().body(new RequestResponseDTO("File is empty"));
|
||||||
@@ -44,10 +45,11 @@ public class ImageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String newImageName = imageService.saveImageToStorage(uploadDir, file);
|
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));
|
return ResponseEntity.ok(new RequestResponseDTO("Image uploaded successfully with new name: " + newImageName));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
return ResponseEntity.status(HttpStatus.UNSUPPORTED_MEDIA_TYPE).body(new RequestResponseDTO(e.getMessage()));
|
return ResponseEntity.status(HttpStatus.UNSUPPORTED_MEDIA_TYPE).body(new RequestResponseDTO(e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -40,10 +40,11 @@ public class ImageService {
|
|||||||
return uniqueFileName;
|
return uniqueFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addImageNameToDB(String filename, Long noticeId) {
|
public void addImageNameToDB(String filename, Long noticeId, boolean isMainImage) {
|
||||||
Image image = new Image();
|
Image image = new Image();
|
||||||
image.setImageName(filename);
|
image.setImageName(filename);
|
||||||
image.setNoticeId(noticeId);
|
image.setNoticeId(noticeId);
|
||||||
|
image.setMainImage(isMainImage);
|
||||||
imageRepository.save(image);
|
imageRepository.save(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,33 @@
|
|||||||
spring.application.name=ArtisanConnectBackend
|
spring.application.name=ArtisanConnectBackend
|
||||||
|
|
||||||
## PostgreSQL
|
spring.datasource.url=${DB_URL:jdbc:postgresql://db:5432/postgres}
|
||||||
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
|
spring.datasource.username=${DB_USER:postgres}
|
||||||
|
spring.datasource.password=${DB_PASS:postgres}
|
||||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||||
spring.datasource.username=postgres
|
|
||||||
spring.datasource.password=postgres
|
|
||||||
|
|
||||||
#initial data for db injection
|
|
||||||
spring.sql.init.data-locations=classpath:sql/data.sql
|
spring.sql.init.data-locations=classpath:sql/data.sql
|
||||||
spring.sql.init.mode=always
|
spring.sql.init.mode=always
|
||||||
spring.jpa.defer-datasource-initialization=true
|
spring.jpa.defer-datasource-initialization=true
|
||||||
|
|
||||||
# create and drop table, good for testing, production set to none or comment it
|
spring.jpa.hibernate.ddl-auto=update
|
||||||
spring.jpa.hibernate.ddl-auto=create-drop
|
|
||||||
|
|
||||||
file.upload-dir=/Users/andsol/Desktop/uploads
|
file.upload-dir=${IMAGES_UPLOAD_DIR:/app/images}
|
||||||
spring.servlet.multipart.max-file-size=10MB
|
spring.servlet.multipart.max-file-size=${MAX_FILE_SIZE:10MB}
|
||||||
spring.servlet.multipart.max-request-size=10MB
|
spring.servlet.multipart.max-request-size=${MAX_REQUEST_SIZE:10MB}
|
||||||
|
|
||||||
spring.mail.host=smtp.sendgrid.net
|
spring.mail.host=${MAIL_HOST}
|
||||||
spring.mail.port=587
|
spring.mail.port=${MAIL_PORT}
|
||||||
spring.mail.username=apikey
|
spring.mail.username=${MAIL_USER}
|
||||||
spring.mail.password=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
|
spring.mail.password=${MAIL_PASSWORD}
|
||||||
spring.mail.properties.mail.smtp.auth=true
|
|
||||||
spring.mail.properties.mail.smtp.starttls.enable=true
|
|
||||||
|
|
||||||
tpay.clientId = 01JQKC048X62ST9V59HNRSXD92-01JQKC2CQHPYXQFSFX8BKC24BX
|
tpay.clientId=${TPAY_CLIENT_ID}
|
||||||
tpay.clientSecret = 44898642be53381cdcc47f3e44bf5a15e592f5d270fc3a6cf6fb81a8b8ebffb9
|
tpay.clientSecret=${TPAY_SECRET}
|
||||||
tpay.authUrl = https://openapi.sandbox.tpay.com/oauth/auth
|
tpay.authUrl=${TPAY_AUTH_URL}
|
||||||
tpay.transactionUrl = https://openapi.sandbox.tpay.com/transactions
|
tpay.transactionUrl=${TPAY_TRANSACTION_URL}
|
||||||
tpay.securityCode = )IY7E)YSM!A)Q6O-GN#U7U_33s9qObk8
|
tpay.securityCode = ${TPAY_SECURITY_CODE}
|
||||||
|
|
||||||
#jwt settings
|
jwt.secret=${JWT_SECRET}
|
||||||
jwt.secret=DIXLsOs3FKmCAQwISd0SKsHMXJrPl3IKIRkVlkOvYW7kEcdUTbxh8zFe1B3eZWkY
|
jwt.expiration=1200000
|
||||||
jwt.expiration=300000
|
|
||||||
|
|
||||||
logging.file.name=logs/payment-notifications.log
|
logging.file.name=logs/payment-notifications.log
|
||||||
logging.level.TpayLogger=INFO
|
logging.level.TpayLogger=INFO
|
||||||
@@ -5,11 +5,11 @@ VALUES
|
|||||||
|
|
||||||
INSERT INTO clients (email, first_name, last_name, password, role_id)
|
INSERT INTO clients (email, first_name, last_name, password, role_id)
|
||||||
VALUES
|
VALUES
|
||||||
('dignissim.tempor.arcu@aol.ca', 'Diana', 'Harrison', 'password', 1),
|
('dignissim.tempor.arcu@aol.ca', 'Diana', 'Harrison', '', 1),
|
||||||
('john.doe@example.com', 'John', 'Doe', 'password123', 2),
|
('john.doe@example.com', 'John', 'Doe', '', 2),
|
||||||
('jane.smith@example.com', 'Jane', 'Smith', 'securepass', 1),
|
('jane.smith@example.com', 'Jane', 'Smith', '', 1),
|
||||||
('michael.brown@example.com', 'Michael', 'Brown', 'mypassword', 1),
|
('michael.brown@example.com', 'Michael', 'Brown', '', 1),
|
||||||
('emily.jones@example.com', 'Emily', 'Jones', 'passw0rd', 1);
|
('emily.jones@example.com', 'Emily', 'Jones', '', 1);
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO notice (title, description, client_id, price, category, status, publish_date) VALUES
|
INSERT INTO notice (title, description, client_id, price, category, status, publish_date) VALUES
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
package _11.asktpk.artisanconnectbackend;
|
|
||||||
|
|
||||||
import _11.asktpk.artisanconnectbackend.security.JwtUtil;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
@AutoConfigureMockMvc
|
|
||||||
class EmailControllerIntegrationTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MockMvc mockMvc;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JwtUtil jwtUtil;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Wysyłanie Maila z waznym tokenem")
|
|
||||||
void testSendEmailWithValidAuthToken() throws Exception {
|
|
||||||
System.out.println("Startowanie testSendEmailWithValidAuthToken");
|
|
||||||
String jsonPayload = """
|
|
||||||
{
|
|
||||||
"to": "test@example.com",
|
|
||||||
"subject": "Test Subject",
|
|
||||||
"body": "Test Body"
|
|
||||||
}
|
|
||||||
""";
|
|
||||||
System.out.println("Wysyłanie JSON payload: " + jsonPayload);
|
|
||||||
|
|
||||||
String jwtToken = "Bearer " + jwtUtil.generateToken("test@example.com", "USER", 1L);
|
|
||||||
|
|
||||||
MvcResult result = mockMvc.perform(post("/api/v1/email/send")
|
|
||||||
.header("Authorization", jwtToken)
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.content(jsonPayload))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(content().string("Email wysłany pomyślnie"))
|
|
||||||
.andReturn();
|
|
||||||
|
|
||||||
System.out.println("Status odpowiedzi: " + result.getResponse().getStatus());
|
|
||||||
System.out.println("Treść odpowiedzi: " + result.getResponse().getContentAsString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Wysyłanie Maila bez tokena")
|
|
||||||
void testSendEmailWithoutAuthToken() throws Exception {
|
|
||||||
System.out.println("Startowanie testSendEmailWithoutAuthToken");
|
|
||||||
String jsonPayload = """
|
|
||||||
{
|
|
||||||
"to": "test@example.com",
|
|
||||||
"subject": "Test Subject",
|
|
||||||
"body": "Test Body"
|
|
||||||
}
|
|
||||||
""";
|
|
||||||
System.out.println("Wysyłanie JSON payload: " + jsonPayload);
|
|
||||||
|
|
||||||
MvcResult result = mockMvc.perform(post("/api/v1/email/send")
|
|
||||||
.contentType(MediaType.APPLICATION_JSON)
|
|
||||||
.content(jsonPayload))
|
|
||||||
.andExpect(status().isForbidden())
|
|
||||||
.andReturn();
|
|
||||||
|
|
||||||
System.out.println("Status odpowiedzi: " + result.getResponse().getStatus());
|
|
||||||
System.out.println("Treść odpowiedzi: " + result.getResponse().getContentAsString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -39,6 +39,9 @@ class NoticeServiceTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private AttributeValuesRepository attributeValuesRepository;
|
private AttributeValuesRepository attributeValuesRepository;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AttributesNoticeRepository attributesNoticeRepository;
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private NoticeService noticeService;
|
private NoticeService noticeService;
|
||||||
|
|
||||||
@@ -121,8 +124,8 @@ class NoticeServiceTest {
|
|||||||
@DisplayName("Dodanie ogłoszenia z atrybutami")
|
@DisplayName("Dodanie ogłoszenia z atrybutami")
|
||||||
void addNotice_WithAttributes_ShouldSaveAttributes() {
|
void addNotice_WithAttributes_ShouldSaveAttributes() {
|
||||||
AttributeDto attributeDto = new AttributeDto();
|
AttributeDto attributeDto = new AttributeDto();
|
||||||
attributeDto.setName("Materiał");
|
attributeDto.setName("Kolor");
|
||||||
attributeDto.setValue("Drewno");
|
attributeDto.setValue("Zielony");
|
||||||
sampleNoticeRequest.setAttributes(List.of(attributeDto));
|
sampleNoticeRequest.setAttributes(List.of(attributeDto));
|
||||||
|
|
||||||
when(clientRepository.findById(1L)).thenReturn(Optional.of(sampleClient));
|
when(clientRepository.findById(1L)).thenReturn(Optional.of(sampleClient));
|
||||||
|
|||||||
Reference in New Issue
Block a user