Skip to content

Commit b211337

Browse files
committed
refactor parte 1
1 parent f44ae71 commit b211337

24 files changed

+415
-174
lines changed

src/main/java/com/outfitlab/project/domain/entities/User.java

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/main/java/com/outfitlab/project/domain/interfaces/ITrippoService.java renamed to src/main/java/com/outfitlab/project/domain/interfaces/ITripoService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import java.io.IOException;
88
import java.util.Map;
99

10-
public interface ITrippoService {
11-
Map<String, String> uploadImageToTrippo(MultipartFile image) throws IOException; // me va a devolver el image_token
10+
public interface ITripoService {
11+
12+
String requestUploadImageApiTripo(MultipartFile image) throws IOException;
1213

1314
ByteArrayResource getImageResource(MultipartFile image) throws IOException;
1415

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package com.outfitlab.project.domain.models;
2+
3+
import java.time.LocalDateTime;
4+
5+
6+
public class TripoModel {
7+
8+
private Long id;
9+
private String taskId;
10+
private String imageToken;
11+
private String originalFilename;
12+
private String fileExtension;
13+
private ModelStatus status;
14+
private String minioImagePath;
15+
private String minioModelPath;
16+
private String tripoModelUrl;
17+
private LocalDateTime createdAt;
18+
private LocalDateTime updatedAt;
19+
private String errorMessage;
20+
21+
public TripoModel() {}
22+
23+
public TripoModel(String taskId, String imageToken, String originalFilename,
24+
String fileExtension, String minioImagePath, ModelStatus status) {
25+
this.taskId = taskId;
26+
this.imageToken = imageToken;
27+
this.originalFilename = originalFilename;
28+
this.fileExtension = fileExtension;
29+
this.minioImagePath = minioImagePath;
30+
this.status = status;
31+
}
32+
33+
public TripoModel(Long id, String taskId, String imageToken, String originalFilename, String fileExtension,
34+
ModelStatus status, String minioImagePath, String minioModelPath, String tripoModelUrl,
35+
LocalDateTime createdAt, LocalDateTime updatedAt, String errorMessage) {
36+
this.id = id;
37+
this.taskId = taskId;
38+
this.imageToken = imageToken;
39+
this.originalFilename = originalFilename;
40+
this.fileExtension = fileExtension;
41+
this.status = status;
42+
this.minioImagePath = minioImagePath;
43+
this.minioModelPath = minioModelPath;
44+
this.tripoModelUrl = tripoModelUrl;
45+
this.createdAt = createdAt;
46+
this.updatedAt = updatedAt;
47+
this.errorMessage = errorMessage;
48+
}
49+
50+
public Long getId() {
51+
return id;
52+
}
53+
54+
public void setId(Long id) {
55+
this.id = id;
56+
}
57+
58+
public String getTaskId() {
59+
return taskId;
60+
}
61+
62+
public void setTaskId(String taskId) {
63+
this.taskId = taskId;
64+
}
65+
66+
public String getImageToken() {
67+
return imageToken;
68+
}
69+
70+
public void setImageToken(String imageToken) {
71+
this.imageToken = imageToken;
72+
}
73+
74+
public String getOriginalFilename() {
75+
return originalFilename;
76+
}
77+
78+
public void setOriginalFilename(String originalFilename) {
79+
this.originalFilename = originalFilename;
80+
}
81+
82+
public String getFileExtension() {
83+
return fileExtension;
84+
}
85+
86+
public void setFileExtension(String fileExtension) {
87+
this.fileExtension = fileExtension;
88+
}
89+
90+
public ModelStatus getStatus() {
91+
return status;
92+
}
93+
94+
public void setStatus(ModelStatus status) {
95+
this.status = status;
96+
}
97+
98+
public String getMinioImagePath() {
99+
return minioImagePath;
100+
}
101+
102+
public void setMinioImagePath(String minioImagePath) {
103+
this.minioImagePath = minioImagePath;
104+
}
105+
106+
public String getMinioModelPath() {
107+
return minioModelPath;
108+
}
109+
110+
public void setMinioModelPath(String minioModelPath) {
111+
this.minioModelPath = minioModelPath;
112+
}
113+
114+
public String getTripoModelUrl() {
115+
return tripoModelUrl;
116+
}
117+
118+
public void setTripoModelUrl(String tripoModelUrl) {
119+
this.tripoModelUrl = tripoModelUrl;
120+
}
121+
122+
public LocalDateTime getCreatedAt() {
123+
return createdAt;
124+
}
125+
126+
public void setCreatedAt(LocalDateTime createdAt) {
127+
this.createdAt = createdAt;
128+
}
129+
130+
public LocalDateTime getUpdatedAt() {
131+
return updatedAt;
132+
}
133+
134+
public void setUpdatedAt(LocalDateTime updatedAt) {
135+
this.updatedAt = updatedAt;
136+
}
137+
138+
public String getErrorMessage() {
139+
return errorMessage;
140+
}
141+
142+
public void setErrorMessage(String errorMessage) {
143+
this.errorMessage = errorMessage;
144+
}
145+
146+
public enum ModelStatus {
147+
PENDING,
148+
PROCESSING,
149+
COMPLETED,
150+
FAILED,
151+
DOWNLOADED
152+
}
153+
154+
public TripoModel toModel() {
155+
return new TripoModel(
156+
id,
157+
taskId,
158+
imageToken,
159+
originalFilename,
160+
fileExtension,
161+
TripoModel.ModelStatus.valueOf(status.name()),
162+
minioImagePath,
163+
minioModelPath,
164+
tripoModelUrl,
165+
createdAt,
166+
updatedAt,
167+
errorMessage
168+
);
169+
}
170+
171+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.outfitlab.project.domain.models;
2+
3+
public class UserModel {
4+
private int id;
5+
private String name;
6+
7+
public UserModel(int id, String name) {
8+
this.id = id;
9+
this.name = name;
10+
}
11+
12+
public int getId() {
13+
return id;
14+
}
15+
public void setId(int id) {
16+
this.id = id;
17+
}
18+
public String getName() {
19+
return name;
20+
}
21+
public void setName(String name) {
22+
this.name = name;
23+
}
24+
}

src/main/java/com/outfitlab/project/domain/repositories/TripoModelRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.outfitlab.project.domain.repositories;
22

3-
import com.outfitlab.project.domain.entities.TripoModel;
3+
import com.outfitlab.project.domain.models.TripoModel;
44
import org.springframework.data.jpa.repository.JpaRepository;
55
import org.springframework.stereotype.Repository;
66

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.outfitlab.project.domain.uc;
2+
3+
import com.fasterxml.jackson.databind.JsonNode;
4+
import com.outfitlab.project.domain.exceptions.ImageInvalidFormatException;
5+
import com.outfitlab.project.domain.interfaces.ITripoService;
6+
import org.springframework.core.io.ByteArrayResource;
7+
import org.springframework.http.HttpEntity;
8+
import org.springframework.http.HttpHeaders;
9+
import org.springframework.http.MediaType;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.util.LinkedMultiValueMap;
12+
import org.springframework.util.MultiValueMap;
13+
import org.springframework.web.multipart.MultipartFile;
14+
15+
import java.io.IOException;
16+
import java.util.HashMap;
17+
import java.util.Map;
18+
19+
public class UploadImageToTripo {
20+
21+
private final ITripoService tripoService;
22+
23+
public UploadImageToTripo(ITripoService tripoService1) {
24+
this.tripoService = tripoService1;
25+
}
26+
27+
public Map<String, String> execute(MultipartFile image) throws IOException {
28+
if (!validateExtension(image.getOriginalFilename())) {
29+
throw new ImageInvalidFormatException("Formato de imagen no válido. Solo se aceptan JPG, JPEG, PNG y WEBP.");
30+
}
31+
32+
byte[] imageBytes = image.getBytes();
33+
String originalFilename = image.getOriginalFilename();
34+
String extension = getFileExtension(originalFilename);
35+
36+
Map<String, String> uploadResult = new HashMap<>();
37+
uploadResult.put("originalFilename", originalFilename);
38+
uploadResult.put("fileExtension", extension);
39+
40+
String imageToken = tripoService.requestUploadImageApiTripo(image);
41+
uploadResult.put("imageToken", imageToken);
42+
43+
return uploadResult;
44+
}
45+
46+
public boolean validateExtension(String filename) {
47+
String extension = getFileExtension(filename);
48+
return extension.equals("jpg") ||
49+
extension.equals("jpeg") ||
50+
extension.equals("png") ||
51+
extension.equals("webp");
52+
}
53+
54+
public String getFileExtension(String nombreArchivo) {
55+
if (nombreArchivo == null || nombreArchivo.isEmpty()) {
56+
return "";
57+
}
58+
int dotIndex = nombreArchivo.lastIndexOf('.');
59+
if (dotIndex > 0 && dotIndex < nombreArchivo.length() - 1) {
60+
return nombreArchivo.substring(dotIndex+1).toLowerCase();
61+
}
62+
return "";
63+
}
64+
65+
}

src/main/java/com/outfitlab/project/infrastructure/TrippoControllerService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.outfitlab.project.infrastructure;
22

3-
import com.outfitlab.project.domain.entities.TripoModel;
3+
import com.outfitlab.project.domain.models.TripoModel;
44
import com.outfitlab.project.domain.repositories.TripoModelRepository;
55
import lombok.AllArgsConstructor;
66
import org.springframework.stereotype.Service;
@@ -18,7 +18,7 @@ public class TrippoControllerService {
1818
public TripoModel uploadAndProcessImage(MultipartFile imageFile) throws Exception {
1919
if (imageFile.isEmpty()) throw new IllegalArgumentException("Archivo vacío");
2020

21-
Map<String, String> uploadData = trippoService.uploadImageToTrippo(imageFile);
21+
Map<String, String> uploadData = trippoService.requestUploadImageApiTripo(imageFile);
2222
String taskId = trippoService.generateImageToModelTrippo(uploadData);
2323
System.out.println(this.trippoService.checkTaskStatus(taskId));
2424

0 commit comments

Comments
 (0)