-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
19 changed files
with
204 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/com/e2i1/linkeepserver/domain/friends/business/FriendsBusiness.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,65 @@ | ||
package com.e2i1.linkeepserver.domain.friends.business; | ||
|
||
import com.e2i1.linkeepserver.common.annotation.Business; | ||
import com.e2i1.linkeepserver.domain.collaborators.service.CollaboratorsService; | ||
import com.e2i1.linkeepserver.domain.friends.converter.FriendsConverter; | ||
import com.e2i1.linkeepserver.domain.friends.dto.FriendStatusResDTO; | ||
import com.e2i1.linkeepserver.domain.friends.dto.FriendsResDTO; | ||
import com.e2i1.linkeepserver.domain.friends.entity.FriendsEntity; | ||
import com.e2i1.linkeepserver.domain.friends.service.FriendsService; | ||
import com.e2i1.linkeepserver.domain.users.entity.UsersEntity; | ||
import com.e2i1.linkeepserver.domain.users.service.UsersService; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import io.jsonwebtoken.lang.Collections; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Business | ||
@RequiredArgsConstructor | ||
public class FriendsBusiness { | ||
private final FriendsService friendsService; | ||
private final UsersService usersService; | ||
private final CollaboratorsService collaboratorsService; | ||
private final FriendsConverter friendsConverter; | ||
|
||
|
||
public List<FriendsResDTO> getFollowers(UsersEntity user) { | ||
List<FriendsEntity> FriendsList = friendsService.getFollowers(user); | ||
return FriendsList.stream().map(friend -> { | ||
long cnt = collaboratorsService.countCollection(friend.getFollowingUser()); | ||
return friendsConverter.toFriendsResDTO(friend.getFollowingUser(), cnt); | ||
}).toList(); | ||
|
||
} | ||
|
||
public List<FriendsResDTO> getFollowings(UsersEntity user) { | ||
List<FriendsEntity> FriendsList = friendsService.getFollowings(user); | ||
for(FriendsEntity f : FriendsList) | ||
System.out.println(f.getId()); | ||
return FriendsList.stream().map(friend -> { | ||
long cnt = collaboratorsService.countCollection(friend.getFollowedUser()); | ||
System.out.println(friend.getFollowedUser()+" : "+cnt); | ||
|
||
return friendsConverter.toFriendsResDTO(friend.getFollowedUser(), cnt); | ||
}).toList(); | ||
|
||
} | ||
|
||
public void insertFollow(String nickName, UsersEntity followingUser) { | ||
UsersEntity followedUser = usersService.findByNickName(nickName); | ||
FriendsEntity friend = friendsConverter.toFriendsEntity(followedUser,followingUser); | ||
friendsService.insertFriend(friend); | ||
} | ||
|
||
@Transactional | ||
public FriendStatusResDTO changeStatus(long userId, UsersEntity follower ) { | ||
UsersEntity followee = usersService.findById(userId); | ||
FriendsEntity friend = friendsService.findByFollowedUserAndFollowingUser(followee,follower); | ||
friend.updateStatus(); | ||
return friendsConverter.toFriendStatusResDTO(friend.getIsFollowing()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/e2i1/linkeepserver/domain/friends/converter/FriendsConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
package com.e2i1.linkeepserver.domain.friends.converter; | ||
|
||
import com.e2i1.linkeepserver.common.annotation.Converter; | ||
import com.e2i1.linkeepserver.domain.friends.dto.FriendStatusResDTO; | ||
import com.e2i1.linkeepserver.domain.friends.dto.FriendsResDTO; | ||
import com.e2i1.linkeepserver.domain.friends.entity.FriendsEntity; | ||
import com.e2i1.linkeepserver.domain.users.entity.UsersEntity; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Converter | ||
@RequiredArgsConstructor | ||
public class FriendsConverter { | ||
|
||
public FriendsEntity toFriendsEntity(UsersEntity followedUser, UsersEntity followingUser) { | ||
return FriendsEntity.builder() | ||
.followedUser(followedUser) | ||
.followingUser(followingUser) | ||
.isFollowing(true).build(); | ||
} | ||
|
||
public FriendsResDTO toFriendsResDTO(UsersEntity user, long cnt) { | ||
return FriendsResDTO.builder().nickName(user.getNickname()).userId(user.getId()).numOfCollections(cnt).build(); | ||
} | ||
public FriendStatusResDTO toFriendStatusResDTO(boolean followStatus){ | ||
return FriendStatusResDTO.builder().followStatus(followStatus).build(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/e2i1/linkeepserver/domain/friends/dto/FriendReqDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.e2i1.linkeepserver.domain.friends.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class FriendReqDTO { | ||
private String nickname; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/e2i1/linkeepserver/domain/friends/dto/FriendStatusReqDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.e2i1.linkeepserver.domain.friends.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class FriendStatusReqDTO { | ||
private long userId; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/e2i1/linkeepserver/domain/friends/dto/FriendStatusResDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.e2i1.linkeepserver.domain.friends.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class FriendStatusResDTO { | ||
private boolean followStatus; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
src/main/java/com/e2i1/linkeepserver/domain/friends/repository/FriendsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package com.e2i1.linkeepserver.domain.friends.repository; | ||
|
||
import com.e2i1.linkeepserver.domain.friends.entity.FriendsEntity; | ||
import com.e2i1.linkeepserver.domain.users.entity.UsersEntity; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.repository.Repository; | ||
|
||
public interface FriendsRepository extends Repository<FriendsEntity,Long> { | ||
public interface FriendsRepository extends JpaRepository<FriendsEntity,Long> { | ||
public List<FriendsEntity> findByFollowedUserAndIsFollowing(UsersEntity user,boolean isFollow); | ||
public List<FriendsEntity> findByFollowingUserAndIsFollowing(UsersEntity user,boolean isFollow); | ||
Optional <FriendsEntity> findByFollowedUserAndFollowingUser(UsersEntity followee, UsersEntity follower); | ||
|
||
} |
24 changes: 23 additions & 1 deletion
24
src/main/java/com/e2i1/linkeepserver/domain/friends/service/FriendsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
package com.e2i1.linkeepserver.domain.friends.service; | ||
|
||
import com.e2i1.linkeepserver.common.error.ErrorCode; | ||
import com.e2i1.linkeepserver.common.exception.ApiException; | ||
import com.e2i1.linkeepserver.domain.friends.entity.FriendsEntity; | ||
import com.e2i1.linkeepserver.domain.friends.repository.FriendsRepository; | ||
import com.e2i1.linkeepserver.domain.users.entity.UsersEntity; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FriendsService { | ||
private FriendsRepository friendsRepository; | ||
private final FriendsRepository friendsRepository; | ||
|
||
public List<FriendsEntity> getFollowers(UsersEntity user) { | ||
return friendsRepository.findByFollowedUserAndIsFollowing(user,true); | ||
} | ||
|
||
public List<FriendsEntity> getFollowings(UsersEntity user) { | ||
return friendsRepository.findByFollowingUserAndIsFollowing(user,true); | ||
} | ||
public FriendsEntity insertFriend(FriendsEntity friend) { | ||
return friendsRepository.save(friend); | ||
} | ||
|
||
public FriendsEntity findByFollowedUserAndFollowingUser(UsersEntity followee, UsersEntity follower) { | ||
return friendsRepository.findByFollowedUserAndFollowingUser(followee,follower).orElseThrow(() -> new ApiException(ErrorCode.FRINEDS_NOT_FOUND)); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters