Commit bd9700e7 authored by saliou673's avatar saliou673
Browse files

SERVER: fix post adding issue

parent ad329509
package com.example.server;
import com.example.server.model.user.User;
import com.example.server.model.user.UserEntity;
import com.example.server.repository.PostRepository;
import com.example.server.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import javax.annotation.PostConstruct;
@EnableAutoConfiguration(exclude = {EmbeddedMongoAutoConfiguration.class})
@EnableMongoRepositories
@SpringBootApplication
public class ServerApplication {
@Autowired
private UserRepository repository;
@Autowired
private PostRepository postRepository;
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
@PostConstruct
public void delete() {
postRepository.deleteAll();
}
}
......@@ -34,7 +34,6 @@ public class PostController {
@PostMapping("/{userid}")
public ResponseEntity<Post> add(@RequestBody PostEntity post, @PathVariable String userid) {
User author = userService.getById(userid);
Post newPost = new PostEntity(post.getSubject(), post.getContent());
newPost.setAuthor(author);
......@@ -75,7 +74,7 @@ public class PostController {
return new ResponseEntity<>("Post repository is empty", HttpStatus.NOT_FOUND);
}
@GetMapping("/all")
@GetMapping()
public ResponseEntity<List<Post>> getAll() {
return new ResponseEntity<>(postService.findAll(), HttpStatus.OK);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment