Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ”€ :: (#99) νŒ”λ‘œμ›Œ μ‚­μ œ API #100

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.moizaspringserver.domain.follow.exception;

import com.example.moizaspringserver.global.error.exception.CustomException;
import com.example.moizaspringserver.global.error.exception.ErrorCode;

public class NoSuchFollowerException extends CustomException {
ericlee05 marked this conversation as resolved.
Show resolved Hide resolved
public static final NoSuchFollowerException EXCEPTION = new NoSuchFollowerException();

private NoSuchFollowerException() {
super(ErrorCode.FOLLOW_NO_SUCH_FOLLOWER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.moizaspringserver.domain.follow.presentation.dto.response.GetAllFollowingResponse;
import com.example.moizaspringserver.domain.follow.service.FollowEstablishService;
import com.example.moizaspringserver.domain.follow.service.FollowQueryService;
import com.example.moizaspringserver.domain.follow.service.FollowerDeleteService;
import com.example.moizaspringserver.domain.follow.service.FollowerQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -18,6 +19,8 @@ public class FollowController {
private final FollowerQueryService followerQueryService;
private final FollowEstablishService followEstablishService;

private final FollowerDeleteService followerDeleteService;

@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/{user-id}")
public void addFollow(@PathVariable("user-id") Integer userId) {
Expand All @@ -33,4 +36,10 @@ public GetAllFollowingResponse getAllFollowing(@PathVariable("user-id") Integer
public GetAllFollowerResponse getAllFollower(@PathVariable("user-id") Integer userId) {
return followerQueryService.execute(userId);
}

@ResponseStatus(HttpStatus.NO_CONTENT)
@DeleteMapping("/{user-id}/follower")
public void deleteFollower(@PathVariable("user-id") Integer userId) {
followerDeleteService.execute(userId);
}
}
Original file line number Diff line number Diff line change
@@ -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.NoSuchFollowerException;
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(() -> NoSuchFollowerException.EXCEPTION);

followRepository.delete(followerRelation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public enum ErrorCode {
NOTICE_ATTACHMENT_FILE_NOT_FOUND(404, "Notice Attachment File Not Found" ),


FOLLOW_ALREADY_EXISTS(409, "Follow Already Exists");
FOLLOW_ALREADY_EXISTS(409, "Follow Already Exists"),
FOLLOW_NO_SUCH_FOLLOWER(404, "No such Follower");
ericlee05 marked this conversation as resolved.
Show resolved Hide resolved


private final int status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ 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.POST, "/follow/{user-id}").authenticated()
.antMatchers(HttpMethod.GET, "/follow/following/{user-id}").authenticated()
.antMatchers(HttpMethod.DELETE, "/follow/{user-id}/follower").authenticated()

// feeds
.antMatchers(HttpMethod.DELETE, "/feeds/{feed-id}").authenticated()
Expand Down