Project management bug fixes
This commit is contained in:
@@ -109,6 +109,16 @@ public class ProjectController {
|
||||
return projectService.addComment(taskId, userId, request.getContent(), request.getImagesJson());
|
||||
}
|
||||
|
||||
@GetMapping("/tasks/attachments/download")
|
||||
public Mono<org.springframework.http.ResponseEntity<byte[]>> downloadAttachment(
|
||||
@RequestParam String filePath,
|
||||
@RequestParam String contentType) {
|
||||
return projectService.downloadAttachment(contentType, filePath)
|
||||
.map(res -> org.springframework.http.ResponseEntity.ok()
|
||||
.header(org.springframework.http.HttpHeaders.CONTENT_TYPE, contentType)
|
||||
.body(java.util.Base64.getDecoder().decode(res.getBase64Content())));
|
||||
}
|
||||
|
||||
@Data
|
||||
static class CreateProjectRequest {
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -22,6 +26,8 @@ public class ProjectService {
|
||||
private final ProjectRepository projectRepository;
|
||||
private final ProjectTaskRepository projectTaskRepository;
|
||||
private final ProjectTaskCommentRepository projectTaskCommentRepository;
|
||||
private final MinioServiceClient minioServiceClient;
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
public Flux<Project> getProjectsByUser(Long userId) {
|
||||
return projectRepository.findByUserId(userId);
|
||||
@@ -108,10 +114,65 @@ public class ProjectService {
|
||||
comment.setTaskId(taskId);
|
||||
comment.setUserId(userId);
|
||||
comment.setContent(content);
|
||||
if (imagesJson != null && !imagesJson.isEmpty()) {
|
||||
comment.setImages(imagesJson);
|
||||
}
|
||||
comment.setCreatedAt(LocalDateTime.now());
|
||||
return projectTaskCommentRepository.save(comment);
|
||||
|
||||
if (imagesJson == null || imagesJson.trim().isEmpty() || imagesJson.equals("[]")) {
|
||||
return projectTaskCommentRepository.save(comment);
|
||||
}
|
||||
|
||||
try {
|
||||
List<Map<String, String>> attachments = objectMapper.readValue(imagesJson, new TypeReference<List<Map<String, String>>>() {});
|
||||
|
||||
// Backward compatibility for old base64 array
|
||||
if (!attachments.isEmpty() && !attachments.get(0).containsKey("base64Content") && !attachments.get(0).containsKey("filePath")) {
|
||||
comment.setImages(imagesJson);
|
||||
return projectTaskCommentRepository.save(comment);
|
||||
}
|
||||
|
||||
return Flux.fromIterable(attachments)
|
||||
.flatMap(att -> {
|
||||
if (att.containsKey("filePath")) {
|
||||
// Already uploaded
|
||||
return Mono.just(att);
|
||||
}
|
||||
String fileName = att.get("fileName");
|
||||
String contentType = att.get("contentType");
|
||||
String base64Content = att.get("base64Content");
|
||||
if (base64Content == null) return Mono.just(att);
|
||||
|
||||
String uniqueFileName = java.util.UUID.randomUUID().toString() + "_" + fileName;
|
||||
String directoryPath = "tasks/" + taskId;
|
||||
|
||||
return minioServiceClient.uploadFile(directoryPath, contentType, uniqueFileName, base64Content)
|
||||
.map(minioResponse -> {
|
||||
Map<String, String> result = new java.util.HashMap<>();
|
||||
result.put("fileName", fileName);
|
||||
result.put("contentType", contentType);
|
||||
if (minioResponse.isSuccess()) {
|
||||
result.put("filePath", minioResponse.getFilePath());
|
||||
}
|
||||
return result;
|
||||
});
|
||||
})
|
||||
.collectList()
|
||||
.flatMap(uploadedAttachments -> {
|
||||
try {
|
||||
String newImagesJson = objectMapper.writeValueAsString(uploadedAttachments);
|
||||
comment.setImages(newImagesJson);
|
||||
return projectTaskCommentRepository.save(comment);
|
||||
} catch (Exception e) {
|
||||
return Mono.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
// Fallback for simple string array (from old app version)
|
||||
comment.setImages(imagesJson);
|
||||
return projectTaskCommentRepository.save(comment);
|
||||
}
|
||||
}
|
||||
|
||||
public Mono<MinioServiceClient.MinioDownloadResponse> downloadAttachment(String contentType, String filePath) {
|
||||
return minioServiceClient.downloadFile(contentType, filePath);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user