Skip to content

Commit

Permalink
feat: now post can be created with pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
Vicente1215 committed Apr 22, 2023
1 parent 328775e commit 186a52a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.daw.alist.controllers.rest;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -26,6 +27,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import static net.daw.alist.utils.Utils.pathToImage;

Expand Down Expand Up @@ -64,16 +66,31 @@ public ResponseEntity<Post> createPost(Authentication auth, @RequestBody Data co

User author = (User) auth.getPrincipal();
author = userService.findByID(author.getId()).orElseThrow();
List<PostItem> items = content.getItems();
for (PostItem item: items) {

// Imprimir las imágenes base64 recibidas
System.out.println("Imágenes recibidas: " + content.getItems().stream().map(ItemData::getImageBase64).collect(Collectors.toList()));

// Convertir la lista de objetos ItemData en objetos PostItem
List<PostItem> items = content.getItems().stream().map(itemData -> {
try {
return new PostItem(itemData.getDescription(), itemData.getImageBase64());
} catch (IOException | SQLException e) {
throw new RuntimeException("Error al crear el objeto PostItem", e);
}
}).collect(Collectors.toList());

for (PostItem item : items) {
postItemService.save(item);
}

List<Topic> topicList = topicService.getTopics(content.getTopicStrings());
Post post = new Post(author, content.getTitle(), topicList, items);
postService.save(post);

return new ResponseEntity<>(post, HttpStatus.CREATED);
}


@Operation(summary = "Get specific post")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Post found", content = {
Expand Down Expand Up @@ -163,7 +180,21 @@ public ResponseEntity<Post> downvotePost(Authentication authentication, @PathVar
private static class Data {
private final String title;
private final List<String> topicStrings;
private final List<PostItem> items;
private final List<ItemData> items;
}

@AllArgsConstructor
@Getter
@Setter
@EqualsAndHashCode
private static class ItemData {
@JsonProperty("description")
private final String description;

@JsonProperty("image")
private final String imageBase64;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class CreatePostComponent implements OnInit {
items: descriptionsAndImages
};

console.log('items', this.myForm.get('descriptionsAndImages')?.value);
console.log('Imágenes enviadas:', descriptionsAndImages.map((item: { image: any; }) => item.image));

this.postService.createPost(post).subscribe(
(response) => {
Expand Down

0 comments on commit 186a52a

Please sign in to comment.