Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 회원 전체 조회 기능 추가 #25

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.programmers.signalbuddy.domain.bookmark.entity.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.locationtech.jts.geom.Point;


@Getter
@AllArgsConstructor
@Builder
public class AdminBookmarkResponse {
private Long bookmarkId;

private String address;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.programmers.signalbuddy.domain.bookmark.entity.dto;

import java.util.List;
import java.util.stream.Collectors;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import org.programmers.signalbuddy.domain.bookmark.entity.Bookmark;

@Mapper
public interface BookmarkMapper {
BookmarkMapper INSTANCE = Mappers.getMapper(BookmarkMapper.class);


BookmarkResponse toDto(Bookmark bookmark);

List<AdminBookmarkResponse> toAdminDto(List<Bookmark> bookmarks);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.programmers.signalbuddy.domain.bookmark.entity.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.locationtech.jts.geom.Point;

@Getter
@AllArgsConstructor
@Builder
public class BookmarkResponse {

private Long bookmarkId;

private Point coordinate;

private String address;

private Long MemberId;

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.programmers.signalbuddy.domain.bookmark.repository;

import java.util.List;
import org.programmers.signalbuddy.domain.bookmark.entity.Bookmark;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface BookmarkRepository extends JpaRepository<Bookmark, Long>,

BookmarkRepositoryCustom {
List<Bookmark> findAllByMember_MemberId(Long id);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.programmers.signalbuddy.domain.member;

import lombok.Getter;

@Getter
public enum MemberRole {
ADMIN("관리자"), USER("사용자");

private final String role;

MemberRole(String role) {
this.role = role;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.programmers.signalbuddy.domain.member.dto.MemberResponse;
import org.programmers.signalbuddy.domain.member.dto.MemberUpdateRequest;
import org.programmers.signalbuddy.domain.member.entity.dto.AdminMemberResponse;
import org.programmers.signalbuddy.domain.member.service.AdminMemberService;
import org.programmers.signalbuddy.domain.member.service.MemberService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -27,6 +30,7 @@
public class MemberController {

private final MemberService memberService;
private final AdminMemberService adminMemberService;


@Operation(summary = "사용자 조회 API")
Expand Down Expand Up @@ -55,4 +59,10 @@ public ResponseEntity<MemberResponse> deleteMember(@PathVariable Long id) {
final MemberResponse deleted = memberService.deleteMember(id);
return ResponseEntity.status(HttpStatus.OK).body(deleted);
}

@GetMapping("admin")
public ResponseEntity<List<AdminMemberResponse>> getMembers(){
final List<AdminMemberResponse> members = adminMemberService.getAllMembers();
return ResponseEntity.ok(members);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.programmers.signalbuddy.domain.basetime.BaseTimeEntity;
import org.programmers.signalbuddy.domain.member.MemberRole;
import org.programmers.signalbuddy.domain.member.dto.MemberUpdateRequest;
import org.programmers.signalbuddy.domain.member.entity.enums.MemberStatus;

Expand All @@ -40,7 +41,8 @@ public class Member extends BaseTimeEntity {
private String profileImageUrl;

@Column(nullable = false)
private String role; // TODO: (USER, ADMIN) Enum 으로 변경
@Enumerated(EnumType.STRING)
private MemberRole role;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.programmers.signalbuddy.domain.member.entity.dto;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.programmers.signalbuddy.domain.bookmark.entity.dto.AdminBookmarkResponse;
import org.programmers.signalbuddy.domain.bookmark.entity.dto.BookmarkResponse;
import org.programmers.signalbuddy.domain.member.MemberRole;
import org.programmers.signalbuddy.domain.member.entity.enums.MemberStatus;

@Getter
@NoArgsConstructor
@Builder
@AllArgsConstructor
public class AdminMemberResponse {

private Long memberId;

private String email;

private String nickname;

private String profileImageUrl;

private MemberRole role;

private MemberStatus memberStatus;

private List<AdminBookmarkResponse> bookmarkResponses;

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package org.programmers.signalbuddy.domain.member.mapper;

import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.programmers.signalbuddy.domain.member.entity.Member;
import org.programmers.signalbuddy.domain.member.dto.MemberResponse;
import org.programmers.signalbuddy.domain.member.entity.dto.AdminMemberResponse;

@Mapper
public interface MemberMapper {

MemberMapper INSTANCE = Mappers.getMapper(MemberMapper.class);

MemberResponse toDto(Member member);
AdminMemberResponse toAdminDto(Member member);
List<AdminMemberResponse> toAdminMembersDto(List<Member> member);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.programmers.signalbuddy.domain.member.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.programmers.signalbuddy.domain.bookmark.entity.Bookmark;
import org.programmers.signalbuddy.domain.bookmark.entity.dto.AdminBookmarkResponse;
import org.programmers.signalbuddy.domain.bookmark.entity.dto.BookmarkMapper;
import org.programmers.signalbuddy.domain.bookmark.entity.dto.BookmarkResponse;
import org.programmers.signalbuddy.domain.bookmark.repository.BookmarkRepository;
import org.programmers.signalbuddy.domain.member.entity.Member;
import org.programmers.signalbuddy.domain.member.entity.dto.AdminMemberResponse;
import org.programmers.signalbuddy.domain.member.repository.MemberRepository;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

@Service
@RequiredArgsConstructor
@Slf4j
public class AdminMemberService {

private final MemberRepository memberRepository;
private final BookmarkRepository bookmarkRepository;

public List<AdminMemberResponse> getAllMembers() {
List<Member> lists = memberRepository.findAll();
List<AdminMemberResponse> responses = new ArrayList<>();

for (Member member : lists) {
List<Bookmark> bookmarks = bookmarkRepository.findAllByMember_MemberId(member.getMemberId());
List<AdminBookmarkResponse> adminBookmarkResponses = BookmarkMapper.INSTANCE.toAdminDto(bookmarks);


AdminMemberResponse adminMemberResponse = AdminMemberResponse.builder()
.memberId(member.getMemberId())
.email(member.getEmail())
.nickname(member.getNickname())
.profileImageUrl(member.getProfileImageUrl())
.role(member.getRole())
.memberStatus(member.getMemberStatus())
.bookmarkResponses(adminBookmarkResponses)
.build();

responses.add(adminMemberResponse);
}
return responses;
}

}
Loading