Skip to content

Instantly share code, notes, and snippets.

@ManduTheCat
Created December 29, 2022 08:01
Show Gist options
  • Save ManduTheCat/4c42eebdae9e19917d1cec0fa319ef80 to your computer and use it in GitHub Desktop.
Save ManduTheCat/4c42eebdae9e19917d1cec0fa319ef80 to your computer and use it in GitHub Desktop.
package com.buealstargram.buealstargram.controller;
import com.buealstargram.buealstargram.entity.Content;
import com.buealstargram.buealstargram.repository.ContentRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.*;
@RestController
@RequestMapping("/content")
@Slf4j
public class InstarRestController {
@Autowired
private ContentRepository contentRepository;
@GetMapping
public List<Content> list(){
List<Map<String, Objects> >res = new ArrayList<>();
List<Content> contentList = contentRepository.findAll();
return contentList;
}
@PostMapping
public Map<String, String> post(@RequestPart("picture")MultipartFile pic,
@RequestParam("title") String title,@RequestParam("password") String password
){
String path = System.getProperty("user.dir");
File file = new File(path + "/src/main/resources/static/"+ pic.getOriginalFilename());
Content content = new Content();
content.setTitle(title);
content.setPassword(password);
content.setPath(file.getPath());
log.info(content.getTitle());
log.info(content.getPassword());
log.info(content.getPath());
log.info("int {}", content.getUid());
Content saved = contentRepository.save(content);
log.info(saved.getTitle());
Map<String, String> res = new HashMap<>();
res.put("path", pic.getOriginalFilename());
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment