Skip to content

Commit

Permalink
Merge pull request #195 from sharemindteam/feature/194-customer-ban
Browse files Browse the repository at this point in the history
feat: 특정 사용자 로그인 제재 기능 구현
  • Loading branch information
letskuku authored Jun 25, 2024
2 parents 9ac61bf + bdb3934 commit e3c293e
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.sharemind.admin.application;

import com.example.sharemind.admin.dto.response.ConsultGetUnpaidResponse;
import com.example.sharemind.admin.dto.response.CustomerGetByNicknameOrEmailResponse;
import com.example.sharemind.admin.dto.response.PaymentGetRefundWaitingResponse;
import com.example.sharemind.admin.dto.response.PaymentGetSettlementOngoingResponse;
import com.example.sharemind.admin.dto.response.PostGetUnpaidPrivateResponse;
Expand Down Expand Up @@ -28,4 +29,8 @@ public interface AdminService {
List<PostGetUnpaidPrivateResponse> getUnpaidPrivatePosts();

void updatePostIsPaid(Long postId);

List<CustomerGetByNicknameOrEmailResponse> getCustomersByNicknameOrEmail(String keyword);

void updateCustomerIsBanned(Long customerId, Boolean isBanned);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.sharemind.admin.application;

import com.example.sharemind.admin.dto.response.ConsultGetUnpaidResponse;
import com.example.sharemind.admin.dto.response.CustomerGetByNicknameOrEmailResponse;
import com.example.sharemind.admin.dto.response.PaymentGetRefundWaitingResponse;
import com.example.sharemind.admin.dto.response.PaymentGetSettlementOngoingResponse;
import com.example.sharemind.admin.dto.response.PostGetUnpaidPrivateResponse;
Expand Down Expand Up @@ -164,4 +165,19 @@ public void updatePostIsPaid(Long postId) {

post.updateIsPaid();
}

@Override
public List<CustomerGetByNicknameOrEmailResponse> getCustomersByNicknameOrEmail(
String keyword) {
return customerService.getCustomersByNicknameOrEmail(keyword).stream()
.map(CustomerGetByNicknameOrEmailResponse::of)
.toList();
}

@Transactional
@Override
public void updateCustomerIsBanned(Long customerId, Boolean isBanned) {
Customer customer = customerService.getCustomerByCustomerId(customerId);
customer.updateIsBanned(isBanned);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.sharemind.admin.dto.response;

import com.example.sharemind.customer.domain.Customer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;

@Getter
public class CustomerGetByNicknameOrEmailResponse {

@Schema(description = "사용자 아이디")
private final Long customerId;

@Schema(description = "닉네임")
private final String nickname;

@Schema(description = "이메일")
private final String email;

@Schema(description = "로그인 제재 여부")
private final Boolean isBanned;

@Builder
public CustomerGetByNicknameOrEmailResponse(Long customerId, String nickname, String email,
Boolean isBanned) {
this.customerId = customerId;
this.nickname = nickname;
this.email = email;
this.isBanned = isBanned;
}

public static CustomerGetByNicknameOrEmailResponse of(Customer customer) {
return CustomerGetByNicknameOrEmailResponse.builder()
.customerId(customer.getCustomerId())
.nickname(customer.getNickname())
.email(customer.getEmail())
.isBanned(customer.getIsBanned())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.sharemind.admin.application.AdminService;
import com.example.sharemind.admin.dto.response.ConsultGetUnpaidResponse;
import com.example.sharemind.admin.dto.response.CustomerGetByNicknameOrEmailResponse;
import com.example.sharemind.admin.dto.response.PaymentGetRefundWaitingResponse;
import com.example.sharemind.admin.dto.response.PaymentGetSettlementOngoingResponse;
import com.example.sharemind.admin.dto.response.PostGetUnpaidPrivateResponse;
Expand Down Expand Up @@ -42,11 +43,11 @@ public ResponseEntity<List<ConsultGetUnpaidResponse>> getUnpaidConsults() {
@ApiResponses({
@ApiResponse(responseCode = "200", description = "수정 성공"),
@ApiResponse(responseCode = "400", description = "이미 결제 완료된 상담",
content = @Content(mediaType = "application/json",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
),
@ApiResponse(responseCode = "404", description = "존재하지 않는 상담 아이디로 요청됨",
content = @Content(mediaType = "application/json",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
)
})
Expand Down Expand Up @@ -87,7 +88,8 @@ public ResponseEntity<List<CounselorGetProfileResponse>> getPendingCounselors()
@Parameter(name = "isPassed", description = "심사 통과 여부")
})
@PatchMapping("/pending-profiles/{counselorId}")
public ResponseEntity<Void> updateProfileStatus(@PathVariable Long counselorId, @RequestParam Boolean isPassed) {
public ResponseEntity<Void> updateProfileStatus(@PathVariable Long counselorId,
@RequestParam Boolean isPassed) {
adminService.updateProfileStatus(counselorId, isPassed);
return ResponseEntity.ok().build();
}
Expand Down Expand Up @@ -183,4 +185,36 @@ public ResponseEntity<Void> updatePostIsPaid(@PathVariable Long postId) {
adminService.updatePostIsPaid(postId);
return ResponseEntity.ok().build();
}

@Operation(summary = "닉네임, 이메일로 셰어 조회", description = "닉네임, 이메일로 셰어 조회")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "조회 성공")
})
@Parameters({
@Parameter(name = "keyword", description = "조회할 사용자의 닉네임 또는 이메일")
})
@GetMapping("/customers")
public ResponseEntity<List<CustomerGetByNicknameOrEmailResponse>> getCustomersByNicknameOrEmail(
@RequestParam String keyword) {
return ResponseEntity.ok(adminService.getCustomersByNicknameOrEmail(keyword));
}

@Operation(summary = "특정 셰어 로그인 제재 여부 수정", description = "특정 셰어 로그인 제재 여부 수정")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "수정 성공"),
@ApiResponse(responseCode = "400", description = "존재하지 않는 사용자 아이디로 요청",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
)
})
@Parameters({
@Parameter(name = "postId", description = "일대다 상담 아이디"),
@Parameter(name = "isBanned", description = "제재 설정 시 true, 제재 해제 시 false")
})
@PatchMapping("/customers/{customerId}")
public ResponseEntity<Void> updateCustomerIsBanned(@PathVariable Long customerId,
@RequestParam Boolean isBanned) {
adminService.updateCustomerIsBanned(customerId, isBanned);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public TokenDto signIn(AuthSignInRequest authSignInRequest) {
throw new AuthException(AuthErrorCode.INVALID_PASSWORD);
}

if (customer.getIsBanned()) {
throw new AuthException(AuthErrorCode.CUSTOMER_BANNED);
}

String accessToken = tokenProvider.createAccessToken(customer.getEmail(),
customer.getRoles());
String refreshToken = tokenProvider.createRefreshToken(customer.getEmail());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum AuthErrorCode {

EMAIL_ALREADY_EXIST(HttpStatus.CONFLICT, "이미 회원으로 등록된 이메일입니다."),
INVALID_PASSWORD(HttpStatus.BAD_REQUEST, "비밀번호가 일치하지 않습니다."),
CUSTOMER_BANNED(HttpStatus.FORBIDDEN, "로그인이 제한된 사용자입니다."),
DUPLICATE_PASSWORD(HttpStatus.BAD_REQUEST, "새 비밀번호가 현재 비밀번호와 동일합니다."),
INVALID_QUIT_CONSULT(HttpStatus.BAD_REQUEST, "미완료 상담이 있어 탈퇴할 수 없습니다."),
INVALID_QUIT_PAYMENT(HttpStatus.BAD_REQUEST, "처리되지 않은 환불금 또는 정산금이 있어 탈퇴할 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public ResponseEntity<Void> signUp(@Valid @RequestBody AuthSignUpRequest authSig
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
),
@ApiResponse(responseCode = "403", description = "로그인이 제한된 사용자로 요청됨",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
),
@ApiResponse(responseCode = "404", description = "존재하지 않는 이메일로 요청됨",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = CustomExceptionResponse.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.example.sharemind.counselor.domain.Counselor;
import com.example.sharemind.customer.domain.Customer;
import java.util.List;

public interface CustomerService {
Customer getCustomerByCustomerId(Long customerId);

Customer getCustomerByCounselor(Counselor counselor);

String getCustomerNickname(Long customerId);

List<Customer> getCustomersByNicknameOrEmail(String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.example.sharemind.customer.exception.CustomerErrorCode;
import com.example.sharemind.customer.exception.CustomerException;
import com.example.sharemind.customer.repository.CustomerRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -33,4 +34,9 @@ public Customer getCustomerByCounselor(Counselor counselor) {
public String getCustomerNickname(Long customerId) {
return getCustomerByCustomerId(customerId).getNickname();
}

@Override
public List<Customer> getCustomersByNicknameOrEmail(String keyword) {
return customerRepository.findAllByNicknameOrEmail(keyword);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class Customer extends BaseEntity {
@Column(nullable = false)
private String password;

@Column(nullable = false)
private Boolean isBanned;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "counselor_id", unique = true)
private Counselor counselor;
Expand All @@ -47,6 +50,7 @@ public Customer(String email, String password) {
this.nickname = "셰어" + new Random().nextInt(999999);
this.email = email;
this.password = password;
this.isBanned = false;

this.roles = new ArrayList<>() {{
add(Role.ROLE_CUSTOMER);
Expand All @@ -57,6 +61,10 @@ public void updatePassword(String password) {
this.password = password;
}

public void updateIsBanned(Boolean isBanned) {
this.isBanned = isBanned;
}

public void setCounselor(Counselor counselor) {
this.counselor = counselor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.example.sharemind.counselor.domain.Counselor;
import com.example.sharemind.customer.domain.Customer;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Optional;
Expand All @@ -16,4 +18,9 @@ public interface CustomerRepository extends JpaRepository<Customer, Long> {
Optional<Customer> findByCustomerIdAndIsActivatedIsTrue(Long id);

Optional<Customer> findByCounselorAndIsActivatedIsTrue(Counselor counselor);

@Query(value = "SELECT * FROM customer "
+ "WHERE (nickname LIKE %:keyword% OR email LIKE %:keyword%) "
+ "AND is_activated = true", nativeQuery = true)
List<Customer> findAllByNicknameOrEmail(String keyword);
}

0 comments on commit e3c293e

Please sign in to comment.