import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Controller;
import
org.springframework.web.bind.annotation.GetMapping;
import
org.springframework.web.bind.annotation.PostMapping;
import
org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestParam;
import
org.springframework.web.bind.annotation.ResponseBody;
import
com.gfg.postgresql.model.geek_author;
import
com.gfg.postgresql.repository.AuthorRepository;
@Controller
@RequestMapping
(path=
"/geek"
)
public
class
AuthorController {
@Autowired
private
AuthorRepository authorRepository;
@PostMapping
(path=
"/addauthor"
)
public
@ResponseBody
String addAuthors (
@RequestParam
String author_name
,
@RequestParam
String email_id) {
geek_author geekAuthor =
new
geek_author();
geekAuthor.setAuthor_name(author_name);
geekAuthor.setEmail_id(email_id);
authorRepository.save(geekAuthor);
return
"Details got Saved"
;
}
@GetMapping
(path=
"/authors"
)
public
@ResponseBody
Iterable<geek_author> getAllAuthors() {
return
authorRepository.findAll();
}
}