Skip to content

Commit

Permalink
[FEATURE] 사용자 정보 조회 API 스펙 변경 (#85)
Browse files Browse the repository at this point in the history
* refactor: dto 명 변경 (#83)

* feat: 사용자 정보 조회 API 스펙 변경 (#83)

* feat: 전체 사용자 정보 조회 API 스펙 변경 (#83)
  • Loading branch information
hyunmin0317 authored Oct 9, 2024
1 parent 75ebec4 commit 87d0b37
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.smunity.server.domain.member.dto.ChangePasswordRequestDto;
import com.smunity.server.domain.member.dto.MemberInfoResponseDto;
import com.smunity.server.domain.member.dto.MemberResponseDto;
import com.smunity.server.domain.member.service.MemberCommandService;
import com.smunity.server.domain.member.service.MemberQueryService;
import com.smunity.server.global.security.annotation.AuthMember;
Expand All @@ -23,8 +24,8 @@ public class MemberController {
private final MemberCommandService memberCommandService;

@GetMapping
public ResponseEntity<Page<MemberInfoResponseDto>> readMembers(@ParameterObject Pageable pageable) {
Page<MemberInfoResponseDto> responseDtoPage = memberQueryService.readMembers(pageable);
public ResponseEntity<Page<MemberResponseDto>> readMembers(@ParameterObject Pageable pageable) {
Page<MemberResponseDto> responseDtoPage = memberQueryService.readMembers(pageable);
return ResponseEntity.ok(responseDtoPage);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
package com.smunity.server.domain.member.dto;

import com.smunity.server.global.common.entity.Member;
import com.smunity.server.global.common.entity.enums.MemberRole;
import lombok.Builder;
import org.springframework.data.domain.Page;

import java.time.LocalDateTime;

@Builder
public record MemberInfoResponseDto(
Long id,
String username,
MemberRole memberRole,
LocalDateTime createdAt,
LocalDateTime updatedAt
String name,
String department,
String email
) {

public static MemberInfoResponseDto from(Member member) {
return MemberInfoResponseDto.builder()
.id(member.getId())
.username(member.getUsername())
.memberRole(member.getRole())
.createdAt(member.getCreatedAt())
.updatedAt(member.getUpdatedAt())
.name(member.getName())
.department(member.getDepartment().getName())
.email(member.getEmail())
.build();
}

public static Page<MemberInfoResponseDto> from(Page<Member> memberPage) {
return memberPage.map(MemberInfoResponseDto::from);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.smunity.server.domain.member.dto;

import com.smunity.server.global.common.entity.Member;
import com.smunity.server.global.common.entity.enums.MemberRole;
import lombok.Builder;
import org.springframework.data.domain.Page;

import java.time.LocalDateTime;

@Builder
public record MemberResponseDto(
Long id,
String username,
String name,
String department,
String email,
MemberRole memberRole,
LocalDateTime createdAt,
LocalDateTime updatedAt
) {

public static MemberResponseDto from(Member member) {
return MemberResponseDto.builder()
.id(member.getId())
.username(member.getUsername())
.name(member.getName())
.department(member.getDepartment().getName())
.email(member.getEmail())
.memberRole(member.getRole())
.createdAt(member.getCreatedAt())
.updatedAt(member.getUpdatedAt())
.build();
}

public static Page<MemberResponseDto> from(Page<Member> memberPage) {
return memberPage.map(MemberResponseDto::from);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.smunity.server.domain.member.service;

import com.smunity.server.domain.member.dto.MemberInfoResponseDto;
import com.smunity.server.domain.member.dto.MemberResponseDto;
import com.smunity.server.global.common.entity.Member;
import com.smunity.server.global.common.repository.MemberRepository;
import com.smunity.server.global.exception.GeneralException;
Expand All @@ -18,9 +19,9 @@ public class MemberQueryService {

private final MemberRepository memberRepository;

public Page<MemberInfoResponseDto> readMembers(Pageable pageable) {
public Page<MemberResponseDto> readMembers(Pageable pageable) {
Page<Member> memberPage = memberRepository.findAll(pageable);
return MemberInfoResponseDto.from(memberPage);
return MemberResponseDto.from(memberPage);
}

public MemberInfoResponseDto readMember(Long memberId) {
Expand Down

0 comments on commit 87d0b37

Please sign in to comment.