diff --git a/src/main/java/com/example/moizaspringserver/domain/follow/presentation/FollowController.java b/src/main/java/com/example/moizaspringserver/domain/follow/presentation/FollowController.java index ae3ad289..28eff864 100644 --- a/src/main/java/com/example/moizaspringserver/domain/follow/presentation/FollowController.java +++ b/src/main/java/com/example/moizaspringserver/domain/follow/presentation/FollowController.java @@ -2,10 +2,7 @@ import com.example.moizaspringserver.domain.follow.presentation.dto.response.GetAllFollowerResponse; import com.example.moizaspringserver.domain.follow.presentation.dto.response.GetAllFollowingResponse; -import com.example.moizaspringserver.domain.follow.service.FollowDeleteService; -import com.example.moizaspringserver.domain.follow.service.FollowEstablishService; -import com.example.moizaspringserver.domain.follow.service.FollowQueryService; -import com.example.moizaspringserver.domain.follow.service.FollowerQueryService; +import com.example.moizaspringserver.domain.follow.service.*; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @@ -18,7 +15,7 @@ public class FollowController { private final FollowerQueryService followerQueryService; private final FollowEstablishService followEstablishService; - + private final FollowerDeleteService followerDeleteService; private final FollowDeleteService followDeleteService; @ResponseStatus(HttpStatus.CREATED) @@ -42,4 +39,10 @@ public GetAllFollowerResponse getAllFollower(@PathVariable("user-id") Integer us public void deleteFollowing(@PathVariable("user-id") Integer userId) { followDeleteService.execute(userId); } + + @ResponseStatus(HttpStatus.NO_CONTENT) + @DeleteMapping("/{user-id}/follower") + public void deleteFollower(@PathVariable("user-id") Integer userId) { + followerDeleteService.execute(userId); + } } diff --git a/src/main/java/com/example/moizaspringserver/domain/follow/service/FollowerDeleteService.java b/src/main/java/com/example/moizaspringserver/domain/follow/service/FollowerDeleteService.java new file mode 100644 index 00000000..626d5fb6 --- /dev/null +++ b/src/main/java/com/example/moizaspringserver/domain/follow/service/FollowerDeleteService.java @@ -0,0 +1,28 @@ +package com.example.moizaspringserver.domain.follow.service; + +import com.example.moizaspringserver.domain.follow.entity.Follow; +import com.example.moizaspringserver.domain.follow.exception.NoSuchFollowException; +import com.example.moizaspringserver.domain.follow.repository.FollowRepository; +import com.example.moizaspringserver.domain.user.entity.User; +import com.example.moizaspringserver.domain.user.facade.UserFacade; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +public class FollowerDeleteService { + private final UserFacade userFacade; + private final FollowRepository followRepository; + + @Transactional + public void execute(Integer followerIdToDelete) { + User queryUser = userFacade.queryCurrentUser(); + User targetUser = userFacade.queryUserById(followerIdToDelete); + + Follow followerRelation = followRepository.findByUserAndTargetUser(targetUser, queryUser) + .orElseThrow(() -> NoSuchFollowException.EXCEPTION); + + followRepository.delete(followerRelation); + } +} diff --git a/src/main/java/com/example/moizaspringserver/global/error/exception/ErrorCode.java b/src/main/java/com/example/moizaspringserver/global/error/exception/ErrorCode.java index 4f5f55c3..b5d4bd53 100644 --- a/src/main/java/com/example/moizaspringserver/global/error/exception/ErrorCode.java +++ b/src/main/java/com/example/moizaspringserver/global/error/exception/ErrorCode.java @@ -48,8 +48,7 @@ public enum ErrorCode { FOLLOW_ALREADY_EXISTS(409, "Follow Already Exists"), - FOLLOW_NOT_FOUND(404, "No such Follow"); - + FOLLOW_NOT_FOUND(404, "No Such Follow"); private final int status; private final String message; diff --git a/src/main/java/com/example/moizaspringserver/global/security/SecurityConfig.java b/src/main/java/com/example/moizaspringserver/global/security/SecurityConfig.java index b01f7396..e4248f02 100644 --- a/src/main/java/com/example/moizaspringserver/global/security/SecurityConfig.java +++ b/src/main/java/com/example/moizaspringserver/global/security/SecurityConfig.java @@ -58,14 +58,14 @@ protected void configure(HttpSecurity http) throws Exception { .antMatchers(HttpMethod.DELETE, "/notices/{notice-id}").hasAnyAuthority("ADMIN") // follow - .antMatchers(HttpMethod.POST, "/follow/*").authenticated() - .antMatchers(HttpMethod.GET, "/following/*").authenticated() - .antMatchers(HttpMethod.DELETE, "/*/following").authenticated() + .antMatchers(HttpMethod.POST, "/follow/{user-id}").authenticated() + .antMatchers(HttpMethod.GET, "/follow/following/{user-id}").authenticated() + .antMatchers(HttpMethod.DELETE, "/follow/{user-id}/follower").authenticated() + .antMatchers(HttpMethod.DELETE, "/{user-id}/following").authenticated() // feeds .antMatchers(HttpMethod.DELETE, "/feeds/{feed-id}").authenticated() - .antMatchers(HttpMethod.PATCH, "/feeds/temporaries/{feed-id}").hasAnyAuthority(UserType.ROLE_STUDENT.name(), UserType.ROLE_GRADUATE.name()) - + // notice .antMatchers(HttpMethod.GET, "/notices/{notice-id}").authenticated()