Skip to content

Commit

Permalink
Merge pull request #88 from miinyeong/main
Browse files Browse the repository at this point in the history
Feat: 가족 구성원 확인 API 생성
  • Loading branch information
miinyeong authored Nov 15, 2023
2 parents 6009471 + f2fcfaa commit f026615
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.onestep.server.controller.user;

import com.onestep.server.entity.User;
import com.onestep.server.entity.user.UserInfoDTO;
import com.onestep.server.service.user.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class UserController {
Expand All @@ -17,4 +20,8 @@ public class UserController {
public User getUserInfo(@PathVariable String userId){
return userService.getUserInfo(userId);
}

// 가족id로 가족 구성원 확인
@GetMapping(value = "/user/userInfoByFamId/{family_id}")
public List<UserInfoDTO> getUserInfoByFamId(@PathVariable String family_id){return userService.getUserInfoByFamId(family_id);}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.onestep.server.entity.quiz;

import com.onestep.server.entity.User;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Date;

@Getter
@Setter
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/onestep/server/entity/user/UserInfoDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.onestep.server.entity.user;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Date;

@Getter
@Setter
@NoArgsConstructor
public class UserInfoDTO {
private String user_id;
private String user_name;
private String user_nickname;
private String user_role;
private String user_phone_number;
private Date user_birth;
private String profile_path;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

public interface IUserRepository extends JpaRepository<User, String> {

//가족 아이디로 가족 구성원 확인
//가족 객체로 가족 구성원 확인
@Query("select u from User u where u.family =:family")
List<User> findUserByFamily(@Param("family")Family family);

//가족 아이디로 가족 구성원 확인
@Query("select u from User u where u.family.fam_id =:family_id")
List<User> findUserByFamId(@Param("family_id")String family_id);
}
25 changes: 25 additions & 0 deletions src/main/java/com/onestep/server/service/user/UserService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.onestep.server.service.user;

import com.onestep.server.entity.User;
import com.onestep.server.entity.user.UserInfoDTO;
import com.onestep.server.repository.IUserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
public class UserService {
Expand All @@ -13,4 +17,25 @@ public class UserService {
public User getUserInfo(String userInfo){
return iUserRepository.findById(userInfo).get();
}

//가족 id로 구성원 정보 확인

public List<UserInfoDTO> getUserInfoByFamId(String family_id){
List<User> users = iUserRepository.findUserByFamId(family_id);
List<UserInfoDTO> userInfos = new ArrayList<>();
for(User u : users){
UserInfoDTO userInfoDTO = new UserInfoDTO();
userInfoDTO.setUser_id(u.getUser_id());
userInfoDTO.setUser_name(u.getUser_name());
userInfoDTO.setUser_nickname(u.getUser_nickname());
userInfoDTO.setUser_birth(u.getUser_birth());
userInfoDTO.setUser_role(u.getUser_role());
userInfoDTO.setUser_birth(u.getUser_birth());
userInfoDTO.setUser_phone_number(u.getUser_phone_number());

userInfos.add(userInfoDTO);
}

return userInfos;
}
}

0 comments on commit f026615

Please sign in to comment.