Implemented follower logic
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package dev.mednikov.social.connections.web;
|
||||
|
||||
import dev.mednikov.social.connections.domain.CreateFollowerRequestDto;
|
||||
import dev.mednikov.social.connections.domain.FollowerDto;
|
||||
import dev.mednikov.social.connections.services.FollowerService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/followers")
|
||||
public class FollowerRestController {
|
||||
|
||||
private final FollowerService followerService;
|
||||
|
||||
public FollowerRestController(FollowerService followerService) {
|
||||
this.followerService = followerService;
|
||||
}
|
||||
|
||||
@GetMapping("/find")
|
||||
public ResponseEntity<FollowerDto> findExistingFollower (
|
||||
@RequestParam(value = "followerId", required = true) String followerId,
|
||||
@RequestParam(value = "followedId", required = true) String followedId
|
||||
) {
|
||||
Long ownerId = Long.parseLong(followerId);
|
||||
Long followedUserId = Long.parseLong(followedId);
|
||||
Optional<FollowerDto> result = this.followerService.findExistingFollower(ownerId, followedUserId);
|
||||
return ResponseEntity.of(result);
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public @ResponseBody FollowerDto createFollower (@RequestBody CreateFollowerRequestDto body) {
|
||||
return this.followerService.createFollower(body);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void deleteFollower (@PathVariable Long id){
|
||||
this.followerService.deleteFollower(id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user