Commit b0881124 authored by Mamadou Diallo's avatar Mamadou Diallo
Browse files

update

parent c018a20c
......@@ -12,6 +12,8 @@ import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.example.server.utils.Const.HOME;
public class SecSecurityConfig extends WebSecurityConfigurerAdapter {
private final List<IUser> users = Stream.of(
......@@ -40,7 +42,7 @@ public class SecSecurityConfig extends WebSecurityConfigurerAdapter {
.csrf().disable()
.authorizeRequests()
.antMatchers("/api/admin/**").hasRole(Const.ADMIN)
.antMatchers("/api/home/").hasAnyRole(Const.USER, Const.ADMIN)
.antMatchers(HOME).hasAnyRole(Const.USER, Const.ADMIN)
.antMatchers("/api/login*").permitAll()
.anyRequest().authenticated();
}
......
package com.example.server.controller;
import com.example.server.exceptions.CommentNotFoundException;
import com.example.server.model.Comment;
import com.example.server.repository.CommentRepository;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/comment")
public class CommentController {
private final CommentRepository repository;
@PostMapping("/add")
public Comment add(@RequestBody JsonNode jsonNode) {
return null;
}
@PutMapping("/{id}")
public Comment update(@RequestBody JsonNode jsonNode, @PathVariable String id) {
if(!repository.existsById(id)){
throw new CommentNotFoundException(id);
}
repository.deleteById(id);
//return userRepository.save(newUser);
return null;
}
@GetMapping("/{id}")
public Optional<Comment> getById(@PathVariable String id) {
return repository.findById(id);
}
@DeleteMapping("/{id}")
public void deleteById(@PathVariable String id) {
if(!repository.existsById(id)){
throw new CommentNotFoundException(id);
}
repository.deleteById(id);
}
public List<Comment> getAll() {
return repository.findAll();
}
}
package com.example.server.controller;
import com.example.server.model.Comment;
import com.example.server.model.Post;
import com.example.server.model.User;
import com.example.server.services.ServiceImpl;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
import static com.example.server.utils.Const.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class Controller {
private final ServiceImpl service;
@GetMapping(HOME)
public ResponseEntity<String> homePage(){
return ResponseEntity.ok("welcome on board");
}
@PostMapping(ADD_USER)
public User addUser(@RequestBody JsonNode jsonNode){
return null;
}
@PostMapping(ADD_COMMENT)
public Comment addComment(@RequestBody JsonNode jsonNode){
return null;
}
@PostMapping(ADD_POST)
public Post addPost(@RequestBody JsonNode jsonNode){
return null;
}
@GetMapping(GET_USER)
public Optional<User> getUserById(@PathVariable String id){
return service.getUserById(id);
}
@GetMapping(GET_COMMENT)
public Optional<Comment> getCommentById(@PathVariable String id){
return service.getCommentById(id);
}
@GetMapping(GET_POST)
public Optional<Post> getPostById(@PathVariable String id){
return service.getPostById(id);
}
@DeleteMapping(DELETE_USER)
public void deleteUser(@PathVariable String id){
service.deleteUser(id);
}
@DeleteMapping(DELETE_COMMENT)
public void deleteComment(@PathVariable String id){
service.deleteComment(id);
}
@DeleteMapping(DELETE_POST)
public void deletePost(@PathVariable String id){
service.deletePost(id);
}
@PutMapping(UPDATE_USER)
public User updateUser(@PathVariable String id, @PathVariable JsonNode jsonNode){
return null;
}
@PutMapping(UPDATE_COMMENT)
public Comment updateComment(@PathVariable String id, @PathVariable JsonNode jsonNode){
return null;
}
@PutMapping(UPDATE_POST)
public Post updatePost(@PathVariable String id, @PathVariable JsonNode jsonNode){
return null;
}
@GetMapping(GET_USER_LIST)
public List<User> getUserList(){
return service.getUserList();
}
@GetMapping(GET_COMMENT_LIST)
public List<Comment> getCommentList(){
return service.getCommentList();
}
@GetMapping(GET_POST_LIST)
public List<Post> getPostList(){
return service.getPostList();
@GetMapping("/home")
public String homePage(){
return "Welcome";
}
}
package com.example.server.controller;
import com.example.server.exceptions.PostNotFoundException;
import com.example.server.model.Post;
import com.example.server.repository.PostRepository;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/post")
public class PostController {
private final PostRepository repository;
@PostMapping("/add")
public Post add(@RequestBody JsonNode jsonNode) {
return null;
}
@PutMapping("/{id}")
public Post update(@RequestBody JsonNode jsonNode, @PathVariable String id) {
if(!repository.existsById(id)){
throw new PostNotFoundException(id);
}
repository.deleteById(id);
//return userRepository.save(newUser);
return null;
}
@GetMapping("/{id}")
public Optional<Post> getById(@PathVariable String id) {
return repository.findById(id);
}
@DeleteMapping("/{id}")
public void deleteById(@PathVariable String id) {
if(!repository.existsById(id)){
throw new PostNotFoundException(id);
}
repository.deleteById(id);
}
public List<Post> getAll() {
return repository.findAll();
}
}
package com.example.server.controller;
import com.example.server.exceptions.UserNotFoundException;
import com.example.server.model.User;
import com.example.server.repository.UserRepository;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@RequiredArgsConstructor
@RequestMapping("api/user")
public class UserController {
private final UserRepository repository;
@PostMapping("/add")
public User add(@RequestBody JsonNode jsonNode) {
return null;
}
@PutMapping("/{id}")
public User update(@PathVariable String idUser, @RequestBody JsonNode jsonNode) {
if(!repository.existsById(idUser)){
throw new UserNotFoundException(idUser);
}
repository.deleteById(idUser);
//return userRepository.save(newUser);
return null;
}
@GetMapping("/{id}")
public Optional<User> getById(@PathVariable String id) {
return repository.findById(id);
}
@DeleteMapping("/{id}")
public void deleteById(@PathVariable String id) {
if(!repository.existsById(id)){
throw new UserNotFoundException(id);
}
repository.deleteById(id);
}
public List<User> getAll() {
return repository.findAll();
}
}
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