forked from codesquad-members-2024/be-airdnb
-
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.
feat: 코멘트에 필요한 유저의 이름과 호스트의 이름 평점을 반환하는 기능 구현 #4
- Loading branch information
1 parent
7365d57
commit 2745dc9
Showing
3 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
23 changes: 21 additions & 2 deletions
23
BE/airdnb/src/main/java/com/team01/airdnb/user/UserService.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,16 +1,35 @@ | ||
package com.team01.airdnb.user; | ||
|
||
import com.team01.airdnb.comment.CommentRepository; | ||
import com.team01.airdnb.user.dto.UserCommentResponse; | ||
import com.team01.airdnb.user.dto.UserHostResponse; | ||
import java.util.NoSuchElementException; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class UserService { | ||
UserRepository userRepository; | ||
CommentRepository commentRepository; | ||
|
||
public UserService(UserRepository userRepository){ | ||
public UserService(UserRepository userRepository, CommentRepository commentRepository){ | ||
this. userRepository = userRepository; | ||
this.commentRepository = commentRepository; | ||
|
||
} | ||
|
||
public User FindUserById(String userId){ | ||
return userRepository.findById(userId).orElseThrow(); | ||
return userRepository.findById(userId) | ||
.orElseThrow(() -> new NoSuchElementException("해당하는 유저가 존재하지 않습니다")); | ||
} | ||
|
||
public UserHostResponse getHostResponse(User user){ | ||
return UserHostResponse.builder() | ||
.username(user.username) | ||
.score(commentRepository.findAverageScoreByUser(user)) | ||
.build(); | ||
} | ||
|
||
public UserCommentResponse getCommentResponse(User user){ | ||
return UserCommentResponse.builder().username(user.getUsername()).build(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
BE/airdnb/src/main/java/com/team01/airdnb/user/dto/UserCommentResponse.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,9 @@ | ||
package com.team01.airdnb.user.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record UserCommentResponse( | ||
String username | ||
) { | ||
} |
10 changes: 10 additions & 0 deletions
10
BE/airdnb/src/main/java/com/team01/airdnb/user/dto/UserHostResponse.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,10 @@ | ||
package com.team01.airdnb.user.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record UserHostResponse( | ||
String username, | ||
Double score | ||
) { | ||
} |