Files
iu-social-connections/src/main/java/dev/mednikov/social/connections/web/FollowerRestController.java

46 lines
1.6 KiB
Java

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);
}
}