Skip to content

Commit

Permalink
fix: new header-type documentName for file
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-urner committed Jul 8, 2024
1 parent c1ceabc commit a0f3dfc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import java.util.Map;
import java.util.List;
import java.time.LocalDateTime;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RestController
@RequestMapping("/volunteers")
Expand Down Expand Up @@ -213,8 +211,9 @@ public VolunteerDocument postNewDocument(
@PathVariable int volunteerId,
@RequestParam MultipartFile document,
@RequestParam int documentTypeId,
@RequestParam String documentName,
@AuthenticationPrincipal UserPrincipal principal) {
return volunteerService.saveDocument(document, documentTypeId, volunteerId, principal.getUsername());
return volunteerService.saveDocument(document, documentTypeId, volunteerId, documentName, principal.getUsername());
}

// **********************************
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/urner/volodb/service/VolunteerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ public String SetAvatar(MultipartFile avatar, int volunteerId) {
return dbVolunteer.getAvatar();
}

public VolunteerDocument saveDocument(MultipartFile file, int documentTypeId, int volunteerId, String username) {
public VolunteerDocument saveDocument(MultipartFile file, int documentTypeId, int volunteerId, String documentName,
String username) {
String fileExtension = FilenameUtils.getExtension(file.getOriginalFilename());
String bucket = "volunteer-" + volunteerId;
String object = "documents/document-" + UUID.randomUUID().toString() + "." + fileExtension;
Expand All @@ -271,6 +272,7 @@ public VolunteerDocument saveDocument(MultipartFile file, int documentTypeId, in
voloDoc.setSize(file.getSize());
voloDoc.setUsername(username);
voloDoc.setPath(bucket + "/" + object);
voloDoc.setName(documentName);

fileService.saveFile(file, bucket, object);
return volunteerDocumentService.save(voloDoc);
Expand Down

0 comments on commit a0f3dfc

Please sign in to comment.