-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from dailylifev1/dm
#66 DAILYLIFE2-20 dm
- Loading branch information
Showing
22 changed files
with
310 additions
and
154 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,5 @@ public ResponseEntity<Boolean> deleteBoard(@PathVariable("boardNum")Long boardNu | |
} | ||
|
||
|
||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/dailylife/domain/follow/controller/FollowingController.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,52 @@ | ||
package com.dailylife.domain.follow.controller; | ||
|
||
import com.dailylife.domain.follow.dto.FollowingRequest; | ||
import com.dailylife.domain.follow.entity.Follow; | ||
import com.dailylife.domain.follow.service.FollowingService; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.validation.Valid; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("api/users") | ||
@RequiredArgsConstructor | ||
@Api(tags = "Following API") | ||
public class FollowingController { | ||
|
||
private final FollowingService followingService; | ||
|
||
@ApiOperation(value = "팔로우를 추가합니다.", notes = "팔로우를 추가합니다.") | ||
@PostMapping("/following") | ||
public ResponseEntity<Follow> following(@Valid @RequestBody FollowingRequest followingRequest) { | ||
return ResponseEntity.ok(followingService.following(followingRequest)); | ||
} | ||
|
||
@ApiOperation(value = "팔로우를 해제합니다.", notes = "팔로우를 해제합니다.") | ||
@PostMapping("/unfollowing") | ||
public ResponseEntity<String> unfollowing(@Valid @RequestBody FollowingRequest followingRequest) { | ||
followingService.unfollowing(followingRequest); | ||
return ResponseEntity.ok("확인"); | ||
} | ||
|
||
@ApiOperation(value = "팔로워를 확인합니다.", notes = "팔로워를 확인합니다.") | ||
@PostMapping("/getFollower") | ||
public ResponseEntity<List<Follow>> getFollower() { | ||
return ResponseEntity.ok(followingService.getFollower()); | ||
} | ||
|
||
@ApiOperation(value = "팔로우를 확인합니다", notes = "팔로우를 확인합니다.") | ||
@PostMapping("/getFollow") | ||
public String getFollow() { | ||
followingService.getFollow(); | ||
return null; | ||
} | ||
|
||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/com/dailylife/domain/follow/repository/FollowingRepository.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,17 @@ | ||
package com.dailylife.domain.follow.repository; | ||
|
||
import com.dailylife.domain.follow.entity.Follow; | ||
import com.dailylife.domain.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface FollowingRepository extends JpaRepository<Follow, Long> { | ||
|
||
Optional<List<Follow>> findByFollowNum(Long followNum); | ||
|
||
void deleteByFollowNum(Long followNum); | ||
|
||
Optional<List<Follow>> findByUser(User user); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/dailylife/domain/follow/service/FollowingService.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,16 @@ | ||
package com.dailylife.domain.follow.service; | ||
|
||
import com.dailylife.domain.follow.dto.FollowingRequest; | ||
import com.dailylife.domain.follow.entity.Follow; | ||
|
||
import java.util.List; | ||
|
||
public interface FollowingService { | ||
Follow following(FollowingRequest userFollowRequest); | ||
|
||
List<Follow> getFollower(); | ||
|
||
void unfollowing(FollowingRequest followingRequest); | ||
|
||
List<Follow> getFollow(); | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/dailylife/domain/follow/service/FollowingServiceImpl.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,67 @@ | ||
package com.dailylife.domain.follow.service; | ||
|
||
import com.dailylife.domain.user.entity.User; | ||
import com.dailylife.domain.user.repository.UserRepository; | ||
import com.dailylife.domain.follow.dto.FollowingRequest; | ||
import com.dailylife.domain.follow.entity.Follow; | ||
import com.dailylife.domain.follow.repository.FollowingRepository; | ||
import com.dailylife.global.jwt.service.JwtService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
@Slf4j | ||
public class FollowingServiceImpl implements FollowingService { | ||
|
||
private final FollowingRepository userFollowRepository; | ||
private final JwtService jwtService; | ||
private final UserRepository userRepository; | ||
|
||
@Override | ||
@Transactional | ||
public Follow following(FollowingRequest userFollowRequest) { | ||
|
||
try{ | ||
userRepository.findByUserNum(userFollowRequest.getFollowNum()).get(); | ||
}catch (Exception e){ | ||
e.printStackTrace(); | ||
throw new RuntimeException("유저를 찾을수 없습니다."); | ||
} | ||
|
||
User user = userRepository.findByUserId(jwtService.getLoginId()); | ||
|
||
return userFollowRepository.save(Follow.toEntity(userFollowRequest,user)); | ||
|
||
} | ||
|
||
|
||
@Override | ||
@Transactional | ||
public void unfollowing(FollowingRequest followingRequest) { | ||
|
||
User user = userRepository.findByUserId(jwtService.getLoginId()); | ||
userFollowRepository.deleteByFollowNum(followingRequest.getFollowNum()); | ||
|
||
} | ||
|
||
@Override | ||
@Transactional | ||
public List<Follow> getFollow() { | ||
User user = userRepository.findByUserId(jwtService.getLoginId()); | ||
return userFollowRepository.findByUser(user).orElseThrow(RuntimeException::new); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public List<Follow> getFollower() { | ||
User user = userRepository.findByUserId(jwtService.getLoginId()); | ||
return userFollowRepository.findByFollowNum(user.getUserNum()).orElseThrow(RuntimeException::new); | ||
} | ||
|
||
|
||
} |
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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/dailylife/domain/user/dto/UserDetailResponse.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,39 @@ | ||
package com.dailylife.domain.user.dto; | ||
|
||
import com.dailylife.domain.board.entity.Board; | ||
import com.dailylife.domain.user.entity.User; | ||
import io.swagger.annotations.ApiModel; | ||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@ApiModel(description = "유저의 대한 상세정보를 전달하기위한 객체") | ||
@Builder | ||
public class UserDetailResponse { | ||
|
||
private String userId; | ||
private String userName; | ||
private String userEmail; | ||
private String userProfileImg; | ||
|
||
private int followSize; | ||
private int followerSize; | ||
|
||
private Long boardNum; | ||
|
||
public static UserDetailResponse from(User user , int followSize , int followerSize , Board board) { | ||
return UserDetailResponse.builder() | ||
.userId(user.getUserId()) | ||
.userName(user.getUserName()) | ||
.userEmail(user.getUserEmail()) | ||
.userProfileImg(user.getUserProfileImg()) | ||
.followerSize(followerSize) | ||
.followSize(followSize) | ||
.boardNum(board.getBoardNum()).build(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.