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

[BE] 관리자 페이지 로컬 사용 및 인증 방식 변경 #493

Merged
merged 5 commits into from
Sep 25, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/be-merge-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

pull_request:
branches: [ develop-BE ]
branches: [ develop-BE-2 ]
types: [ closed ]
paths: backend/**

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/be-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:

pull_request:
branches: [ main, develop-BE ]
branches: [ main, develop-BE-2 ]
paths: backend/**

permissions:
Expand Down
58 changes: 29 additions & 29 deletions backend/src/docs/asciidoc/admin.adoc
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
== 관리자 기능

=== 전체 회원 조회

operation::admin-controller-test/find-all-member-details[snippets='http-request,http-response']

=== 회원 상세 조회

operation::admin-controller-test/find-member[snippets='http-request,http-response']

=== 회원 차단(삭제)

operation::admin-controller-test/delete-member[snippets='http-request,http-response']

=== 토픽 삭제

operation::admin-controller-test/delete-topic[snippets='http-request,http-response']

=== 토픽 이미지 삭제

operation::admin-controller-test/delete-topic-image[snippets='http-request,http-response']

=== 핀 삭제

operation::admin-controller-test/delete-pin[snippets='http-request,http-response']

=== 핀 이미지 삭제

operation::admin-controller-test/delete-pin-image[snippets='http-request,http-response']
// == 관리자 기능
//
// === 전체 회원 조회
//
// operation::admin-controller-test/find-all-member-details[snippets='http-request,http-response']
//
// === 회원 상세 조회
//
// operation::admin-controller-test/find-member[snippets='http-request,http-response']
//
// === 회원 차단(삭제)
//
// operation::admin-controller-test/delete-member[snippets='http-request,http-response']
//
// === 토픽 삭제
//
// operation::admin-controller-test/delete-topic[snippets='http-request,http-response']
//
// === 토픽 이미지 삭제
//
// operation::admin-controller-test/delete-topic-image[snippets='http-request,http-response']
//
// === 핀 삭제
//
// operation::admin-controller-test/delete-pin[snippets='http-request,http-response']
//
// === 핀 이미지 삭제
//
// operation::admin-controller-test/delete-pin-image[snippets='http-request,http-response']
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
package com.mapbefine.mapbefine.admin.application;

import static com.mapbefine.mapbefine.permission.exception.PermissionErrorCode.PERMISSION_FORBIDDEN_BY_NOT_ADMIN;
import static com.mapbefine.mapbefine.topic.exception.TopicErrorCode.TOPIC_NOT_FOUND;

import com.mapbefine.mapbefine.atlas.domain.AtlasRepository;
import com.mapbefine.mapbefine.auth.domain.AuthMember;
import com.mapbefine.mapbefine.bookmark.domain.BookmarkRepository;
import com.mapbefine.mapbefine.member.domain.Member;
import com.mapbefine.mapbefine.member.domain.MemberRepository;
import com.mapbefine.mapbefine.member.domain.Role;
import com.mapbefine.mapbefine.member.domain.Status;
import com.mapbefine.mapbefine.permission.domain.PermissionRepository;
import com.mapbefine.mapbefine.permission.exception.PermissionException.PermissionForbiddenException;
import com.mapbefine.mapbefine.pin.domain.Pin;
import com.mapbefine.mapbefine.pin.domain.PinImageRepository;
import com.mapbefine.mapbefine.pin.domain.PinRepository;
import com.mapbefine.mapbefine.topic.domain.Topic;
import com.mapbefine.mapbefine.topic.domain.TopicRepository;
import com.mapbefine.mapbefine.topic.exception.TopicException;
import java.util.List;
import java.util.NoSuchElementException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.NoSuchElementException;

@Service
@Transactional
public class AdminCommandService {
Expand Down Expand Up @@ -53,9 +50,7 @@ public AdminCommandService(
this.bookmarkRepository = bookmarkRepository;
}

public void blockMember(AuthMember authMember, Long memberId) {
validateAdminPermission(authMember);

public void blockMember(Long memberId) {
Member member = findMemberById(memberId);
member.updateStatus(Status.BLOCKED);

Expand All @@ -79,30 +74,18 @@ private Member findMemberById(Long id) {
.orElseThrow(() -> new NoSuchElementException("findMemberByAuthMember; member not found; id=" + id));
}

private void validateAdminPermission(AuthMember authMember) {
if (authMember.isRole(Role.ADMIN)) {
return;
}

throw new PermissionForbiddenException(PERMISSION_FORBIDDEN_BY_NOT_ADMIN);
}

private List<Long> extractPinIdsByMember(Member member) {
return member.getCreatedPins()
.stream()
.map(Pin::getId)
.toList();
}

public void deleteTopic(AuthMember authMember, Long topicId) {
validateAdminPermission(authMember);

public void deleteTopic(Long topicId) {
topicRepository.deleteById(topicId);
}

public void deleteTopicImage(AuthMember authMember, Long topicId) {
validateAdminPermission(authMember);

public void deleteTopicImage(Long topicId) {
Topic topic = findTopicById(topicId);
topic.removeImage();
}
Expand All @@ -112,15 +95,11 @@ private Topic findTopicById(Long topicId) {
.orElseThrow(() -> new TopicException.TopicNotFoundException(TOPIC_NOT_FOUND, List.of(topicId)));
}

public void deletePin(AuthMember authMember, Long pinId) {
validateAdminPermission(authMember);

public void deletePin(Long pinId) {
pinRepository.deleteById(pinId);
}

public void deletePinImage(AuthMember authMember, Long pinImageId) {
validateAdminPermission(authMember);

public void deletePinImage(Long pinImageId) {
pinImageRepository.deleteById(pinImageId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

import com.mapbefine.mapbefine.admin.dto.AdminMemberDetailResponse;
import com.mapbefine.mapbefine.admin.dto.AdminMemberResponse;
import com.mapbefine.mapbefine.auth.domain.AuthMember;
import com.mapbefine.mapbefine.member.domain.Member;
import com.mapbefine.mapbefine.member.domain.MemberRepository;
import com.mapbefine.mapbefine.member.domain.Role;
import com.mapbefine.mapbefine.permission.exception.PermissionErrorCode;
import com.mapbefine.mapbefine.permission.exception.PermissionException.PermissionForbiddenException;
import com.mapbefine.mapbefine.pin.domain.Pin;
import com.mapbefine.mapbefine.topic.domain.Topic;
import java.util.List;
import java.util.NoSuchElementException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.NoSuchElementException;

@Service
@Transactional(readOnly = true)
public class AdminQueryService {
Expand All @@ -25,9 +23,7 @@ public AdminQueryService(MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}

public List<AdminMemberResponse> findAllMemberDetails(AuthMember authMember) {
validateAdminPermission(authMember);

public List<AdminMemberResponse> findAllMemberDetails() {
List<Member> members = memberRepository.findAllByMemberInfoRole(Role.USER);

return members.stream()
Expand All @@ -40,17 +36,7 @@ private Member findMemberById(Long id) {
.orElseThrow(() -> new NoSuchElementException("findMemberByAuthMember; member not found; id=" + id));
}

private void validateAdminPermission(AuthMember authMember) {
if (authMember.isRole(Role.ADMIN)) {
return;
}

throw new PermissionForbiddenException(PermissionErrorCode.PERMISSION_FORBIDDEN_BY_NOT_ADMIN);
}

public AdminMemberDetailResponse findMemberDetail(AuthMember authMember, Long memberId) {
validateAdminPermission(authMember);

public AdminMemberDetailResponse findMemberDetail(Long memberId) {
Member findMember = findMemberById(memberId);
List<Topic> topics = findMember.getCreatedTopics();
List<Pin> pins = findMember.getCreatedPins();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mapbefine.mapbefine.pin.dto.response.PinResponse;
import com.mapbefine.mapbefine.topic.domain.Topic;
import com.mapbefine.mapbefine.topic.dto.response.TopicResponse;

import java.time.LocalDateTime;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mapbefine.mapbefine.member.domain.Member;
import com.mapbefine.mapbefine.member.domain.MemberInfo;

import java.time.LocalDateTime;

public record AdminMemberResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import com.mapbefine.mapbefine.admin.application.AdminQueryService;
import com.mapbefine.mapbefine.admin.dto.AdminMemberDetailResponse;
import com.mapbefine.mapbefine.admin.dto.AdminMemberResponse;
import com.mapbefine.mapbefine.auth.domain.AuthMember;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {
Expand All @@ -27,50 +27,50 @@ public AdminController(AdminQueryService adminQueryService, AdminCommandService
}

@GetMapping("/members")
public ResponseEntity<List<AdminMemberResponse>> findAllMembers(AuthMember authMember) {
List<AdminMemberResponse> responses = adminQueryService.findAllMemberDetails(authMember);
public ResponseEntity<List<AdminMemberResponse>> findAllMembers() {
List<AdminMemberResponse> responses = adminQueryService.findAllMemberDetails();

return ResponseEntity.ok(responses);
}

@DeleteMapping("/members/{memberId}")
public ResponseEntity<Void> deleteMember(AuthMember authMember, @PathVariable Long memberId) {
adminCommandService.blockMember(authMember, memberId);
public ResponseEntity<Void> deleteMember(@PathVariable Long memberId) {
adminCommandService.blockMember(memberId);

return ResponseEntity.noContent().build();
}

@GetMapping("/members/{memberId}")
public ResponseEntity<AdminMemberDetailResponse> findMember(AuthMember authMember, @PathVariable Long memberId) {
AdminMemberDetailResponse response = adminQueryService.findMemberDetail(authMember, memberId);
public ResponseEntity<AdminMemberDetailResponse> findMember(@PathVariable Long memberId) {
AdminMemberDetailResponse response = adminQueryService.findMemberDetail(memberId);

return ResponseEntity.ok(response);
}

@DeleteMapping("/topics/{topicId}")
public ResponseEntity<Void> deleteTopic(AuthMember authMember, @PathVariable Long topicId) {
adminCommandService.deleteTopic(authMember, topicId);
public ResponseEntity<Void> deleteTopic(@PathVariable Long topicId) {
adminCommandService.deleteTopic(topicId);

return ResponseEntity.noContent().build();
}

@DeleteMapping("/topics/{topicId}/images")
public ResponseEntity<Void> deleteTopicImage(AuthMember authMember, @PathVariable Long topicId) {
adminCommandService.deleteTopicImage(authMember, topicId);
public ResponseEntity<Void> deleteTopicImage(@PathVariable Long topicId) {
adminCommandService.deleteTopicImage(topicId);

return ResponseEntity.noContent().build();
}

@DeleteMapping("/pins/{pinId}")
public ResponseEntity<Void> deletePin(AuthMember authMember, @PathVariable Long pinId) {
adminCommandService.deletePin(authMember, pinId);
public ResponseEntity<Void> deletePin(@PathVariable Long pinId) {
adminCommandService.deletePin(pinId);

return ResponseEntity.noContent().build();
}

@DeleteMapping("/pins/images/{imageId}")
public ResponseEntity<Void> deletePinImage(AuthMember authMember, @PathVariable Long imageId) {
adminCommandService.deletePinImage(authMember, imageId);
public ResponseEntity<Void> deletePinImage(@PathVariable Long imageId) {
adminCommandService.deletePinImage(imageId);

return ResponseEntity.noContent().build();
}
Expand Down

This file was deleted.

Loading
Loading