Skip to content

Commit

Permalink
✨ FEAT. 사용자 마이페이지 데이터 조회 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
junhaa committed Jun 14, 2024
1 parent 5f08aa4 commit 738e2ae
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Optional;

import fairytale.tbd.domain.user.entity.User;
import fairytale.tbd.domain.user.web.dto.UserResponseDTO;

public interface UserQueryService {

Expand All @@ -11,4 +12,6 @@ public interface UserQueryService {
void updateRefreshToken(User user, String reIssuedRefreshToken);

Optional<User> getUserWithUserId(Long userId);

UserResponseDTO.MyPageGetResultDto getUserMyPage(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import fairytale.tbd.domain.user.entity.User;
import fairytale.tbd.domain.user.repository.UserRepository;
import fairytale.tbd.domain.user.web.dto.UserResponseDTO;
import lombok.RequiredArgsConstructor;

@Service
Expand Down Expand Up @@ -41,4 +42,12 @@ public Optional<User> getUserWithUserId(Long userId) {
return userRepository.findById(userId);
}

@Override
public UserResponseDTO.MyPageGetResultDto getUserMyPage(User user) {
return UserResponseDTO.MyPageGetResultDto.builder()
.userName(user.getUsername())
.imageUrl(user.getFaceImageUrl())
.uploadedVoice(user.getVoice() != null)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -10,8 +11,10 @@
import fairytale.tbd.domain.user.converter.UserConverter;
import fairytale.tbd.domain.user.entity.User;
import fairytale.tbd.domain.user.service.UserCommandService;
import fairytale.tbd.domain.user.service.UserQueryService;
import fairytale.tbd.domain.user.web.dto.UserRequestDTO;
import fairytale.tbd.domain.user.web.dto.UserResponseDTO;
import fairytale.tbd.global.annotation.LoginUser;
import fairytale.tbd.global.response.ApiResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,6 +25,7 @@
public class UserRestController {

private final UserCommandService userCommandService;
private final UserQueryService userQueryService;
private static final Logger LOGGER = LogManager.getLogger(UserRestController.class);

/**
Expand All @@ -33,4 +37,14 @@ public ApiResponse<UserResponseDTO.AddUserResultDTO> join(@Valid @RequestBody Us
User user = userCommandService.addUser(request);
return ApiResponse.onSuccess(UserConverter.toAddUserResultDTO(user));
}

/**
* 사용자 마이페이지 데이터 조회
*/

@GetMapping("")
public ApiResponse<UserResponseDTO.MyPageGetResultDto> getMyPage(@LoginUser User user) {
UserResponseDTO.MyPageGetResultDto result = userQueryService.getUserMyPage(user);
return ApiResponse.onSuccess(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@ public class UserResponseDTO {
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class AddUserResultDTO{
public static class AddUserResultDTO {
private Long userId;
private LocalDateTime createdAt;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class MyPageGetResultDto {
private String imageUrl;
private String userName;

private Boolean uploadedVoice;
}
}

0 comments on commit 738e2ae

Please sign in to comment.