From bbfe88102f55ca58b389de31cc5d9ef379cd7fe4 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 14:35:35 +0900 Subject: [PATCH 01/24] =?UTF-8?q?[FEAT]=20=EA=B3=84=EC=A2=8C=20=EC=97=B0?= =?UTF-8?q?=EB=8F=99=20=EC=8B=A4=ED=8C=A8=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EC=84=A4=EA=B3=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makeawish/domain/abuse/AbuseLog.java | 27 +++++++++++++++++++ .../makeawish/domain/abuse/AbuseUser.java | 27 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java create mode 100644 src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java diff --git a/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java new file mode 100644 index 0000000..f6571eb --- /dev/null +++ b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java @@ -0,0 +1,27 @@ +package com.sopterm.makeawish.domain.abuse; + +import com.sopterm.makeawish.domain.user.User; +import jakarta.persistence.*; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; + +import java.time.LocalDateTime; + +import static jakarta.persistence.FetchType.LAZY; +import static jakarta.persistence.GenerationType.IDENTITY; + +@Entity +@Getter +public class AbuseLog { + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "abuse_log_id") + private Long id; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "user_id") + private User user; + + @CreatedDate + protected LocalDateTime createdAt; +} diff --git a/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java new file mode 100644 index 0000000..f0adf01 --- /dev/null +++ b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java @@ -0,0 +1,27 @@ +package com.sopterm.makeawish.domain.abuse; + +import com.sopterm.makeawish.domain.user.User; +import jakarta.persistence.*; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; + +import java.time.LocalDateTime; + +import static jakarta.persistence.FetchType.LAZY; +import static jakarta.persistence.GenerationType.IDENTITY; + +@Entity +@Getter +public class AbuseUser { + @Id + @GeneratedValue(strategy = IDENTITY) + @Column(name = "abuse_user_id") + private Long id; + + @ManyToOne(fetch = LAZY) + @JoinColumn(name = "user_id") + private User user; + + @CreatedDate + protected LocalDateTime createdAt; +} From ee610036685a2326f54cf961347cc9c033fe92f8 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 14:56:12 +0900 Subject: [PATCH 02/24] =?UTF-8?q?[FEAT]=20=EC=96=B4=EB=B7=B0=EC=A7=95=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EB=A0=88=ED=8F=AC=EC=A7=80=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makeawish/repository/abuse/AbuseLogRepository.java | 7 +++++++ .../repository/abuse/AbuseUserRepository.java | 10 ++++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/main/java/com/sopterm/makeawish/repository/abuse/AbuseLogRepository.java create mode 100644 src/main/java/com/sopterm/makeawish/repository/abuse/AbuseUserRepository.java diff --git a/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseLogRepository.java b/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseLogRepository.java new file mode 100644 index 0000000..4511c59 --- /dev/null +++ b/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseLogRepository.java @@ -0,0 +1,7 @@ +package com.sopterm.makeawish.repository.abuse; + +import com.sopterm.makeawish.domain.abuse.AbuseLog; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AbuseLogRepository extends JpaRepository { +} diff --git a/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseUserRepository.java b/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseUserRepository.java new file mode 100644 index 0000000..c64cafb --- /dev/null +++ b/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseUserRepository.java @@ -0,0 +1,10 @@ +package com.sopterm.makeawish.repository.abuse; + +import com.sopterm.makeawish.domain.abuse.AbuseUser; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface AbuseUserRepository extends JpaRepository { + Optional findAbuseUserByUserId(Long userId); +} From 63836c6d21e6690d5bdb68b97ff34d3cb5860da1 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 15:04:29 +0900 Subject: [PATCH 03/24] =?UTF-8?q?[FEAT]=20=EC=96=B4=EB=B7=B0=EC=A7=95=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopterm/makeawish/common/AbuseException.java | 11 +++++++++++ .../com/sopterm/makeawish/common/ErrorHandler.java | 6 ++++++ 2 files changed, 17 insertions(+) create mode 100644 src/main/java/com/sopterm/makeawish/common/AbuseException.java diff --git a/src/main/java/com/sopterm/makeawish/common/AbuseException.java b/src/main/java/com/sopterm/makeawish/common/AbuseException.java new file mode 100644 index 0000000..2e4933f --- /dev/null +++ b/src/main/java/com/sopterm/makeawish/common/AbuseException.java @@ -0,0 +1,11 @@ +package com.sopterm.makeawish.common; + +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +public class AbuseException extends RuntimeException { + public AbuseException(String message) { + super(message); + } +} diff --git a/src/main/java/com/sopterm/makeawish/common/ErrorHandler.java b/src/main/java/com/sopterm/makeawish/common/ErrorHandler.java index 5c06db6..c48d874 100644 --- a/src/main/java/com/sopterm/makeawish/common/ErrorHandler.java +++ b/src/main/java/com/sopterm/makeawish/common/ErrorHandler.java @@ -82,4 +82,10 @@ public ResponseEntity popbillException(PopbillException exception){ val response = ApiResponse.fail(exception.getMessage()); return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); } + + @ExceptionHandler(AbuseException.class) + public ResponseEntity abuseException(AbuseException exception){ + val response = ApiResponse.fail(exception.getMessage()); + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); + } } From 89895fcdf765f3d67976b351c40ef0d6346de32d Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 15:04:36 +0900 Subject: [PATCH 04/24] =?UTF-8?q?[FEAT]=20=EC=96=B4=EB=B7=B0=EC=A7=95=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sopterm/makeawish/common/message/ErrorMessage.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/sopterm/makeawish/common/message/ErrorMessage.java b/src/main/java/com/sopterm/makeawish/common/message/ErrorMessage.java index f9d4c3a..ab4f565 100644 --- a/src/main/java/com/sopterm/makeawish/common/message/ErrorMessage.java +++ b/src/main/java/com/sopterm/makeawish/common/message/ErrorMessage.java @@ -25,6 +25,7 @@ public enum ErrorMessage { NULL_PRINCIPAL("principal 이 null 일 수 없습니다."), NO_EXIST_USER_ACCOUNT("유저의 계좌정보가 없습니다."), NOT_VALID_USER_ACCOUNT("유저의 계좌번호가 아닙니다."), + IS_ABUSE_USER("어뷰징 유저로 이용 불가합니다."), /** cake **/ INVALID_CAKE("존재하지 않는 케이크입니다."), From 8ef0b74d5b34bdc59a5cbc3abdabd015d3649343 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 15:06:15 +0900 Subject: [PATCH 05/24] =?UTF-8?q?[FEAT]=20=EC=96=B4=EB=B7=B0=EC=A7=95=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makeawish/controller/UserController.java | 14 ++++++++++++++ .../com/sopterm/makeawish/service/UserService.java | 11 ++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sopterm/makeawish/controller/UserController.java b/src/main/java/com/sopterm/makeawish/controller/UserController.java index 1a83e93..b907918 100644 --- a/src/main/java/com/sopterm/makeawish/controller/UserController.java +++ b/src/main/java/com/sopterm/makeawish/controller/UserController.java @@ -1,6 +1,7 @@ package com.sopterm.makeawish.controller; import com.popbill.api.PopbillException; +import com.popbill.api.Response; import com.sopterm.makeawish.common.ApiResponse; import com.sopterm.makeawish.domain.user.InternalMemberDetails; import com.sopterm.makeawish.dto.user.UserAccountRequestDTO; @@ -15,6 +16,10 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import javax.swing.text.html.parser.Entity; + +import java.net.http.HttpResponse; + import static com.sopterm.makeawish.common.message.ErrorMessage.NO_EXIST_USER_ACCOUNT; import static com.sopterm.makeawish.common.message.SuccessMessage.*; import static java.util.Objects.nonNull; @@ -66,4 +71,13 @@ public ResponseEntity checkAccountInformation( userService.verifyUserAccount(name, BankCode, AccountNumber); return ResponseEntity.ok(ApiResponse.success(SUCCESS_VERIFY_USER_ACCOUNT.getMessage())); } + + @Operation(summary = "어뷰징 유저 확인") + @GetMapping("") + public ResponseEntity checkAbuseUser( + @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails + ){ + userService.checkAbuseUser(memberDetails.getId()); + return ResponseEntity.ok(ApiResponse.success("어뷰징 유저가 아닙니다.")); + } } diff --git a/src/main/java/com/sopterm/makeawish/service/UserService.java b/src/main/java/com/sopterm/makeawish/service/UserService.java index 2c1d8fb..d617397 100644 --- a/src/main/java/com/sopterm/makeawish/service/UserService.java +++ b/src/main/java/com/sopterm/makeawish/service/UserService.java @@ -1,13 +1,14 @@ package com.sopterm.makeawish.service; -import com.popbill.api.AccountCheckInfo; import com.popbill.api.AccountCheckService; import com.popbill.api.PopbillException; +import com.sopterm.makeawish.common.AbuseException; import com.sopterm.makeawish.domain.user.User; import com.sopterm.makeawish.dto.user.UserAccountRequestDTO; import com.sopterm.makeawish.dto.user.UserAccountResponseDTO; import com.sopterm.makeawish.repository.PresentRepository; import com.sopterm.makeawish.repository.UserRepository; +import com.sopterm.makeawish.repository.abuse.AbuseUserRepository; import com.sopterm.makeawish.repository.wish.WishRepository; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; @@ -29,6 +30,7 @@ public class UserService { private final WishRepository wishRepository; private final PresentRepository presentRepository; private final AccountCheckService accountCheckService; + private final AbuseUserRepository abuseUserRepository; @Value("${popbill.businessNumber}") private String corpNum; @@ -77,4 +79,11 @@ public void verifyUserAccount(String name, String BankCode, String AccountNumber throw new PopbillException(e.getCode(), e.getMessage()); } } + + public void checkAbuseUser(Long userId){ + abuseUserRepository.findAbuseUserByUserId(userId) + .ifPresent(abuseUser -> { + throw new AbuseException(IS_ABUSE_USER.getMessage()); + }); + } } From b0840622b28787e5f023789c4edaedef48983a1a Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 15:07:21 +0900 Subject: [PATCH 06/24] =?UTF-8?q?[FEAT]=20=EC=96=B4=EB=B7=B0=EC=A7=95=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EA=B0=80=20=EC=95=84=EB=8B=8C=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=9D=91=EB=8B=B5=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopterm/makeawish/common/message/SuccessMessage.java | 1 + .../java/com/sopterm/makeawish/controller/UserController.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sopterm/makeawish/common/message/SuccessMessage.java b/src/main/java/com/sopterm/makeawish/common/message/SuccessMessage.java index 244ebf3..a039ae2 100644 --- a/src/main/java/com/sopterm/makeawish/common/message/SuccessMessage.java +++ b/src/main/java/com/sopterm/makeawish/common/message/SuccessMessage.java @@ -18,6 +18,7 @@ public enum SuccessMessage { SUCCESS_UPDATE_USER_ACCOUNT_INFO("유저 계좌정보 수정 성공"), SUCCESS_DELETE_USER("회원 탈퇴 성공"), SUCCESS_VERIFY_USER_ACCOUNT("유저 계좌정보 인증 성공"), + IS_NOT_ABUSE_USER("어뷰징 유저가 아닙니다."), /** wish **/ SUCCESS_CREATE_WISH("소원 링크 생성 성공"), diff --git a/src/main/java/com/sopterm/makeawish/controller/UserController.java b/src/main/java/com/sopterm/makeawish/controller/UserController.java index b907918..b053b0b 100644 --- a/src/main/java/com/sopterm/makeawish/controller/UserController.java +++ b/src/main/java/com/sopterm/makeawish/controller/UserController.java @@ -78,6 +78,6 @@ public ResponseEntity checkAbuseUser( @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails ){ userService.checkAbuseUser(memberDetails.getId()); - return ResponseEntity.ok(ApiResponse.success("어뷰징 유저가 아닙니다.")); + return ResponseEntity.ok(ApiResponse.success(IS_NOT_ABUSE_USER.getMessage())); } } From 0cb81b8ea4d8f73ae367433e27518fafabda3f66 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 15:55:08 +0900 Subject: [PATCH 07/24] =?UTF-8?q?[FEAT]=20=EC=96=B4=EB=B7=B0=EC=A7=95=20?= =?UTF-8?q?=EB=B9=8C=EB=8D=94=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/sopterm/makeawish/domain/abuse/AbuseLog.java | 8 ++++++++ .../com/sopterm/makeawish/domain/abuse/AbuseUser.java | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java index f6571eb..df28922 100644 --- a/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java +++ b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java @@ -2,7 +2,9 @@ import com.sopterm.makeawish.domain.user.User; import jakarta.persistence.*; +import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import org.springframework.data.annotation.CreatedDate; import java.time.LocalDateTime; @@ -12,6 +14,7 @@ @Entity @Getter +@NoArgsConstructor public class AbuseLog { @Id @GeneratedValue(strategy = IDENTITY) @@ -24,4 +27,9 @@ public class AbuseLog { @CreatedDate protected LocalDateTime createdAt; + + @Builder + public AbuseLog(User user){ + this.user = user; + } } diff --git a/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java index f0adf01..9e8b8b0 100644 --- a/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java +++ b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java @@ -2,7 +2,9 @@ import com.sopterm.makeawish.domain.user.User; import jakarta.persistence.*; +import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import org.springframework.data.annotation.CreatedDate; import java.time.LocalDateTime; @@ -12,6 +14,8 @@ @Entity @Getter +@Builder +@NoArgsConstructor public class AbuseUser { @Id @GeneratedValue(strategy = IDENTITY) @@ -24,4 +28,9 @@ public class AbuseUser { @CreatedDate protected LocalDateTime createdAt; + + @Builder + public AbuseUser(User user){ + this.user = user; + } } From d04e86d78a7ef5b0b31b16a85f1da4bf59d5d785 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 16:23:41 +0900 Subject: [PATCH 08/24] =?UTF-8?q?[FEAT]=20=EC=96=B4=EB=B7=B0=EC=A7=95=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=84=B8=EA=B8=B0=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makeawish/controller/UserController.java | 8 +++++--- .../repository/abuse/AbuseLogRepository.java | 4 ++++ .../sopterm/makeawish/service/UserService.java | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/sopterm/makeawish/controller/UserController.java b/src/main/java/com/sopterm/makeawish/controller/UserController.java index b053b0b..43f59ea 100644 --- a/src/main/java/com/sopterm/makeawish/controller/UserController.java +++ b/src/main/java/com/sopterm/makeawish/controller/UserController.java @@ -65,10 +65,11 @@ public ResponseEntity deleteUser( } @Operation(summary = "계좌 실명 조회") - @GetMapping("/verify-account") + @PostMapping("/verify-account") public ResponseEntity checkAccountInformation( + @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails, @RequestParam String name, @RequestParam String BankCode, @RequestParam String AccountNumber) throws Exception { - userService.verifyUserAccount(name, BankCode, AccountNumber); + userService.verifyUserAccount(memberDetails.getId(), name, BankCode, AccountNumber); return ResponseEntity.ok(ApiResponse.success(SUCCESS_VERIFY_USER_ACCOUNT.getMessage())); } @@ -78,6 +79,7 @@ public ResponseEntity checkAbuseUser( @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails ){ userService.checkAbuseUser(memberDetails.getId()); - return ResponseEntity.ok(ApiResponse.success(IS_NOT_ABUSE_USER.getMessage())); + val response = userService.countAbuseLogByUser(memberDetails.getId()); + return ResponseEntity.ok(ApiResponse.success(IS_NOT_ABUSE_USER.getMessage(), response)); } } diff --git a/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseLogRepository.java b/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseLogRepository.java index 4511c59..5768d9a 100644 --- a/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseLogRepository.java +++ b/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseLogRepository.java @@ -2,6 +2,10 @@ import com.sopterm.makeawish.domain.abuse.AbuseLog; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface AbuseLogRepository extends JpaRepository { + @Query(value = "SELECT COUNT(AL) FROM AbuseLog AL WHERE AL.user = :userId and AL.createdAt >= (now() - interval '7 days')", nativeQuery = true) + Integer countAbuseLogByUserIdDuringWeekend(@Param("userId") Long userId); } diff --git a/src/main/java/com/sopterm/makeawish/service/UserService.java b/src/main/java/com/sopterm/makeawish/service/UserService.java index d617397..e570332 100644 --- a/src/main/java/com/sopterm/makeawish/service/UserService.java +++ b/src/main/java/com/sopterm/makeawish/service/UserService.java @@ -3,11 +3,13 @@ import com.popbill.api.AccountCheckService; import com.popbill.api.PopbillException; import com.sopterm.makeawish.common.AbuseException; +import com.sopterm.makeawish.domain.abuse.AbuseLog; import com.sopterm.makeawish.domain.user.User; import com.sopterm.makeawish.dto.user.UserAccountRequestDTO; import com.sopterm.makeawish.dto.user.UserAccountResponseDTO; import com.sopterm.makeawish.repository.PresentRepository; import com.sopterm.makeawish.repository.UserRepository; +import com.sopterm.makeawish.repository.abuse.AbuseLogRepository; import com.sopterm.makeawish.repository.abuse.AbuseUserRepository; import com.sopterm.makeawish.repository.wish.WishRepository; import jakarta.persistence.EntityNotFoundException; @@ -31,6 +33,7 @@ public class UserService { private final PresentRepository presentRepository; private final AccountCheckService accountCheckService; private final AbuseUserRepository abuseUserRepository; + private final AbuseLogRepository abuseLogRepository; @Value("${popbill.businessNumber}") private String corpNum; @@ -69,12 +72,14 @@ private User getUser(Long userId) { .orElseThrow(() -> new EntityNotFoundException(INVALID_USER.getMessage())); } - public void verifyUserAccount(String name, String BankCode, String AccountNumber) throws PopbillException { + public void verifyUserAccount(Long userId, String name, String BankCode, String AccountNumber) throws PopbillException { try { val accountInfo = accountCheckService.CheckAccountInfo(corpNum, BankCode, AccountNumber); - - if(!name.equals(accountInfo.getAccountName())) + val user = getUser(userId); + if(!name.equals(accountInfo.getAccountName())){ + abuseLogRepository.save(new AbuseLog(user)); throw new IllegalArgumentException(NOT_VALID_USER_ACCOUNT.getMessage()); + } } catch (PopbillException e) { throw new PopbillException(e.getCode(), e.getMessage()); } @@ -86,4 +91,8 @@ public void checkAbuseUser(Long userId){ throw new AbuseException(IS_ABUSE_USER.getMessage()); }); } + + public Integer countAbuseLogByUser(Long userId){ + return abuseLogRepository.countAbuseLogByUserIdDuringWeekend(userId); + } } From 9e0a071d0cacfdfad5b880c3c983bc952e595c38 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 21:00:25 +0900 Subject: [PATCH 09/24] =?UTF-8?q?[FEAT]=20=EB=B9=8C=EB=8D=94=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java index 9e8b8b0..234a04f 100644 --- a/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java +++ b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java @@ -14,7 +14,6 @@ @Entity @Getter -@Builder @NoArgsConstructor public class AbuseUser { @Id From 03701513c4f8c4278869a2d08c5320846a41d591 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 21:04:29 +0900 Subject: [PATCH 10/24] =?UTF-8?q?[FEAT]=20=EC=96=B4=EB=B7=B0=EC=A7=95=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=A1=B0=ED=9A=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makeawish/controller/UserController.java | 5 +++-- .../makeawish/service/UserService.java | 21 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sopterm/makeawish/controller/UserController.java b/src/main/java/com/sopterm/makeawish/controller/UserController.java index 43f59ea..a3fbd4a 100644 --- a/src/main/java/com/sopterm/makeawish/controller/UserController.java +++ b/src/main/java/com/sopterm/makeawish/controller/UserController.java @@ -70,11 +70,12 @@ public ResponseEntity checkAccountInformation( @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails, @RequestParam String name, @RequestParam String BankCode, @RequestParam String AccountNumber) throws Exception { userService.verifyUserAccount(memberDetails.getId(), name, BankCode, AccountNumber); - return ResponseEntity.ok(ApiResponse.success(SUCCESS_VERIFY_USER_ACCOUNT.getMessage())); + val response = userService.countAbuseLogByUser(memberDetails.getId()); + return ResponseEntity.ok(ApiResponse.success(SUCCESS_VERIFY_USER_ACCOUNT.getMessage(), response)); } @Operation(summary = "어뷰징 유저 확인") - @GetMapping("") + @GetMapping("/abuse") public ResponseEntity checkAbuseUser( @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails ){ diff --git a/src/main/java/com/sopterm/makeawish/service/UserService.java b/src/main/java/com/sopterm/makeawish/service/UserService.java index e570332..f585706 100644 --- a/src/main/java/com/sopterm/makeawish/service/UserService.java +++ b/src/main/java/com/sopterm/makeawish/service/UserService.java @@ -4,6 +4,7 @@ import com.popbill.api.PopbillException; import com.sopterm.makeawish.common.AbuseException; import com.sopterm.makeawish.domain.abuse.AbuseLog; +import com.sopterm.makeawish.domain.abuse.AbuseUser; import com.sopterm.makeawish.domain.user.User; import com.sopterm.makeawish.dto.user.UserAccountRequestDTO; import com.sopterm.makeawish.dto.user.UserAccountResponseDTO; @@ -15,6 +16,7 @@ import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import lombok.val; +import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -72,12 +74,12 @@ private User getUser(Long userId) { .orElseThrow(() -> new EntityNotFoundException(INVALID_USER.getMessage())); } - public void verifyUserAccount(Long userId, String name, String BankCode, String AccountNumber) throws PopbillException { + public void verifyUserAccount(Long userId, String name, String bankCode, String AccountNumber) throws PopbillException { + checkAbuseUser(userId); try { - val accountInfo = accountCheckService.CheckAccountInfo(corpNum, BankCode, AccountNumber); - val user = getUser(userId); + val accountInfo = accountCheckService.CheckAccountInfo(corpNum, bankCode, AccountNumber); if(!name.equals(accountInfo.getAccountName())){ - abuseLogRepository.save(new AbuseLog(user)); + abuseLogRepository.save(new AbuseLog(getUser(userId))); throw new IllegalArgumentException(NOT_VALID_USER_ACCOUNT.getMessage()); } } catch (PopbillException e) { @@ -93,6 +95,15 @@ public void checkAbuseUser(Long userId){ } public Integer countAbuseLogByUser(Long userId){ - return abuseLogRepository.countAbuseLogByUserIdDuringWeekend(userId); + val abuseLogCount = abuseLogRepository.countAbuseLogByUserIdDuringWeekend(userId); + if(abuseLogCount >= 4){ + abuseUserRepository.save(new AbuseUser(getUser(userId))); + throw new AbuseException(IS_ABUSE_USER.getMessage()); + } + return abuseLogCount; + } + + public void createAbuseUser(Long userId){ + abuseUserRepository.save(new AbuseUser(getUser(userId))); } } From f3e36cfb5a1398da4f56e84be7f67fa308e69d84 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 21:04:44 +0900 Subject: [PATCH 11/24] =?UTF-8?q?[FIX]=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sopterm/makeawish/service/UserServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/sopterm/makeawish/service/UserServiceTest.java b/src/test/java/com/sopterm/makeawish/service/UserServiceTest.java index 2d96a0a..b843254 100644 --- a/src/test/java/com/sopterm/makeawish/service/UserServiceTest.java +++ b/src/test/java/com/sopterm/makeawish/service/UserServiceTest.java @@ -32,7 +32,7 @@ class UserServiceTest { String AccountNumber = "1234567890"; // when - then - assertThatThrownBy(() -> userService.verifyUserAccount("홍길동",BankCode, AccountNumber)) + assertThatThrownBy(() -> userService.verifyUserAccount(1L,"홍길동",BankCode, AccountNumber)) .isInstanceOf(PopbillException.class); } } \ No newline at end of file From f5cb9b89661c78dde5fd7bad40c7bbd1dfc29c29 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 21:12:31 +0900 Subject: [PATCH 12/24] =?UTF-8?q?[FIX]=20=EC=BF=BC=EB=A6=AC=20=EC=B9=BC?= =?UTF-8?q?=EB=9F=BC=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopterm/makeawish/repository/abuse/AbuseLogRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseLogRepository.java b/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseLogRepository.java index 5768d9a..458c73f 100644 --- a/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseLogRepository.java +++ b/src/main/java/com/sopterm/makeawish/repository/abuse/AbuseLogRepository.java @@ -6,6 +6,6 @@ import org.springframework.data.repository.query.Param; public interface AbuseLogRepository extends JpaRepository { - @Query(value = "SELECT COUNT(AL) FROM AbuseLog AL WHERE AL.user = :userId and AL.createdAt >= (now() - interval '7 days')", nativeQuery = true) + @Query(value = "SELECT COUNT(AL) FROM ABUSE_LOG AL WHERE AL.user_id = :userId and AL.created_at >= (now() - interval '7 days')", nativeQuery = true) Integer countAbuseLogByUserIdDuringWeekend(@Param("userId") Long userId); } From c3362aa78e24b976f74f5e4d965d98b15bb9d4aa Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 21:29:09 +0900 Subject: [PATCH 13/24] =?UTF-8?q?[FIX]=20request=20body=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopterm/makeawish/controller/UserController.java | 5 +++-- .../dto/user/UserAccountVerifyRequestDTO.java | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/sopterm/makeawish/dto/user/UserAccountVerifyRequestDTO.java diff --git a/src/main/java/com/sopterm/makeawish/controller/UserController.java b/src/main/java/com/sopterm/makeawish/controller/UserController.java index a3fbd4a..e97eb25 100644 --- a/src/main/java/com/sopterm/makeawish/controller/UserController.java +++ b/src/main/java/com/sopterm/makeawish/controller/UserController.java @@ -5,6 +5,7 @@ import com.sopterm.makeawish.common.ApiResponse; import com.sopterm.makeawish.domain.user.InternalMemberDetails; import com.sopterm.makeawish.dto.user.UserAccountRequestDTO; +import com.sopterm.makeawish.dto.user.UserAccountVerifyRequestDTO; import com.sopterm.makeawish.service.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -68,8 +69,8 @@ public ResponseEntity deleteUser( @PostMapping("/verify-account") public ResponseEntity checkAccountInformation( @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails, - @RequestParam String name, @RequestParam String BankCode, @RequestParam String AccountNumber) throws Exception { - userService.verifyUserAccount(memberDetails.getId(), name, BankCode, AccountNumber); + @RequestBody UserAccountVerifyRequestDTO verifyRequestDTO) throws Exception { + userService.verifyUserAccount(memberDetails.getId(), verifyRequestDTO); val response = userService.countAbuseLogByUser(memberDetails.getId()); return ResponseEntity.ok(ApiResponse.success(SUCCESS_VERIFY_USER_ACCOUNT.getMessage(), response)); } diff --git a/src/main/java/com/sopterm/makeawish/dto/user/UserAccountVerifyRequestDTO.java b/src/main/java/com/sopterm/makeawish/dto/user/UserAccountVerifyRequestDTO.java new file mode 100644 index 0000000..fa796ed --- /dev/null +++ b/src/main/java/com/sopterm/makeawish/dto/user/UserAccountVerifyRequestDTO.java @@ -0,0 +1,11 @@ +package com.sopterm.makeawish.dto.user; + +import lombok.Builder; + +@Builder +public record UserAccountVerifyRequestDTO( + String name + , String BankCode + , String AccountNumber +) { +} From a6ed9e2f6454a02d161f30add6cb92d2e6e15048 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Mon, 11 Dec 2023 21:29:22 +0900 Subject: [PATCH 14/24] =?UTF-8?q?[FIX]=20transactional=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sopterm/makeawish/service/UserService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sopterm/makeawish/service/UserService.java b/src/main/java/com/sopterm/makeawish/service/UserService.java index f585706..f237794 100644 --- a/src/main/java/com/sopterm/makeawish/service/UserService.java +++ b/src/main/java/com/sopterm/makeawish/service/UserService.java @@ -8,6 +8,7 @@ import com.sopterm.makeawish.domain.user.User; import com.sopterm.makeawish.dto.user.UserAccountRequestDTO; import com.sopterm.makeawish.dto.user.UserAccountResponseDTO; +import com.sopterm.makeawish.dto.user.UserAccountVerifyRequestDTO; import com.sopterm.makeawish.repository.PresentRepository; import com.sopterm.makeawish.repository.UserRepository; import com.sopterm.makeawish.repository.abuse.AbuseLogRepository; @@ -74,11 +75,12 @@ private User getUser(Long userId) { .orElseThrow(() -> new EntityNotFoundException(INVALID_USER.getMessage())); } - public void verifyUserAccount(Long userId, String name, String bankCode, String AccountNumber) throws PopbillException { + @Transactional + public void verifyUserAccount(Long userId, UserAccountVerifyRequestDTO verifyRequestDTO) throws PopbillException { checkAbuseUser(userId); try { - val accountInfo = accountCheckService.CheckAccountInfo(corpNum, bankCode, AccountNumber); - if(!name.equals(accountInfo.getAccountName())){ + val accountInfo = accountCheckService.CheckAccountInfo(corpNum, verifyRequestDTO.BankCode(), verifyRequestDTO.AccountNumber()); + if(!verifyRequestDTO.name().equals(accountInfo.getAccountName())){ abuseLogRepository.save(new AbuseLog(getUser(userId))); throw new IllegalArgumentException(NOT_VALID_USER_ACCOUNT.getMessage()); } @@ -94,6 +96,7 @@ public void checkAbuseUser(Long userId){ }); } + @Transactional public Integer countAbuseLogByUser(Long userId){ val abuseLogCount = abuseLogRepository.countAbuseLogByUserIdDuringWeekend(userId); if(abuseLogCount >= 4){ From 15ce47700e830df770c6e69ed1ffe5ec038d0962 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Wed, 13 Dec 2023 18:12:46 +0900 Subject: [PATCH 15/24] =?UTF-8?q?[ADD]=20=EC=8B=A4=ED=8C=A8=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=EC=97=90=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sopterm/makeawish/common/ApiResponse.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/sopterm/makeawish/common/ApiResponse.java b/src/main/java/com/sopterm/makeawish/common/ApiResponse.java index d7d5619..ae3b241 100644 --- a/src/main/java/com/sopterm/makeawish/common/ApiResponse.java +++ b/src/main/java/com/sopterm/makeawish/common/ApiResponse.java @@ -27,4 +27,12 @@ public static ApiResponse fail(String message) { .message(message) .build(); } + + public static ApiResponse fail(String message, Object data) { + return ApiResponse.builder() + .success(false) + .message(message) + .data(data) + .build(); + } } From 3e1e93693c5700073d50e452efa28fd6794df570 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Wed, 13 Dec 2023 18:16:16 +0900 Subject: [PATCH 16/24] =?UTF-8?q?[ADD]=20entitylistener=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java | 2 ++ src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java index df28922..a933579 100644 --- a/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java +++ b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseLog.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDateTime; @@ -15,6 +16,7 @@ @Entity @Getter @NoArgsConstructor +@EntityListeners(AuditingEntityListener.class) public class AbuseLog { @Id @GeneratedValue(strategy = IDENTITY) diff --git a/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java index 234a04f..b7a0f3b 100644 --- a/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java +++ b/src/main/java/com/sopterm/makeawish/domain/abuse/AbuseUser.java @@ -6,6 +6,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDateTime; @@ -15,6 +16,7 @@ @Entity @Getter @NoArgsConstructor +@EntityListeners(AuditingEntityListener.class) public class AbuseUser { @Id @GeneratedValue(strategy = IDENTITY) From 2b259e62624da3e6f057fa069fb8da301ad7df61 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Wed, 13 Dec 2023 18:26:40 +0900 Subject: [PATCH 17/24] =?UTF-8?q?[ADD]=20=EC=96=B4=EB=B7=B0=EC=A7=95=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EB=8A=94=20=EC=86=8C=EC=9B=90=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B6=88=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makeawish/controller/UserController.java | 17 +++++++---------- .../makeawish/controller/WishController.java | 3 +++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/sopterm/makeawish/controller/UserController.java b/src/main/java/com/sopterm/makeawish/controller/UserController.java index e97eb25..5fabccb 100644 --- a/src/main/java/com/sopterm/makeawish/controller/UserController.java +++ b/src/main/java/com/sopterm/makeawish/controller/UserController.java @@ -1,7 +1,5 @@ package com.sopterm.makeawish.controller; -import com.popbill.api.PopbillException; -import com.popbill.api.Response; import com.sopterm.makeawish.common.ApiResponse; import com.sopterm.makeawish.domain.user.InternalMemberDetails; import com.sopterm.makeawish.dto.user.UserAccountRequestDTO; @@ -17,10 +15,7 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import javax.swing.text.html.parser.Entity; - -import java.net.http.HttpResponse; - +import static com.sopterm.makeawish.common.message.ErrorMessage.NOT_VALID_USER_ACCOUNT; import static com.sopterm.makeawish.common.message.ErrorMessage.NO_EXIST_USER_ACCOUNT; import static com.sopterm.makeawish.common.message.SuccessMessage.*; import static java.util.Objects.nonNull; @@ -33,6 +28,7 @@ public class UserController { private final UserService userService; + private static final int VERIFY_ACCOUNT_SUCCESS = 0; @Operation(summary = "유저 계좌 정보 가져오기") @GetMapping("/account") @@ -70,16 +66,17 @@ public ResponseEntity deleteUser( public ResponseEntity checkAccountInformation( @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails, @RequestBody UserAccountVerifyRequestDTO verifyRequestDTO) throws Exception { - userService.verifyUserAccount(memberDetails.getId(), verifyRequestDTO); - val response = userService.countAbuseLogByUser(memberDetails.getId()); - return ResponseEntity.ok(ApiResponse.success(SUCCESS_VERIFY_USER_ACCOUNT.getMessage(), response)); + val response = userService.verifyUserAccount(memberDetails.getId(), verifyRequestDTO); + return response == VERIFY_ACCOUNT_SUCCESS + ? ResponseEntity.ok(ApiResponse.success(SUCCESS_VERIFY_USER_ACCOUNT.getMessage())) + : ResponseEntity.ok(ApiResponse.fail(NOT_VALID_USER_ACCOUNT.getMessage(), response)); } @Operation(summary = "어뷰징 유저 확인") @GetMapping("/abuse") public ResponseEntity checkAbuseUser( @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails - ){ + ) { userService.checkAbuseUser(memberDetails.getId()); val response = userService.countAbuseLogByUser(memberDetails.getId()); return ResponseEntity.ok(ApiResponse.success(IS_NOT_ABUSE_USER.getMessage(), response)); diff --git a/src/main/java/com/sopterm/makeawish/controller/WishController.java b/src/main/java/com/sopterm/makeawish/controller/WishController.java index 862f41d..55375e8 100644 --- a/src/main/java/com/sopterm/makeawish/controller/WishController.java +++ b/src/main/java/com/sopterm/makeawish/controller/WishController.java @@ -5,6 +5,7 @@ import com.sopterm.makeawish.dto.wish.UserWishUpdateRequestDTO; import com.sopterm.makeawish.dto.wish.WishIdRequestDTO; import com.sopterm.makeawish.dto.wish.WishRequestDTO; +import com.sopterm.makeawish.service.UserService; import com.sopterm.makeawish.service.WishService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -35,6 +36,7 @@ public class WishController { private final WishService wishService; + private final UserService userService; @Operation(summary = "소원 링크 생성") @PostMapping @@ -42,6 +44,7 @@ public ResponseEntity createWish( @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails, @RequestBody WishRequestDTO requestDTO ) { + userService.checkAbuseUser(memberDetails.getId()); val wishId = wishService.createWish(memberDetails.getId(), requestDTO); return ResponseEntity .created(getURI(wishId)) From 80553c52ba90f46ec51825423183f39acfe7ea08 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Wed, 13 Dec 2023 18:51:20 +0900 Subject: [PATCH 18/24] =?UTF-8?q?[FIX]=20=EA=B3=84=EC=A2=8C=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makeawish/service/UserService.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/sopterm/makeawish/service/UserService.java b/src/main/java/com/sopterm/makeawish/service/UserService.java index f237794..8f856cc 100644 --- a/src/main/java/com/sopterm/makeawish/service/UserService.java +++ b/src/main/java/com/sopterm/makeawish/service/UserService.java @@ -1,5 +1,6 @@ package com.sopterm.makeawish.service; +import com.popbill.api.AccountCheckInfo; import com.popbill.api.AccountCheckService; import com.popbill.api.PopbillException; import com.sopterm.makeawish.common.AbuseException; @@ -40,6 +41,7 @@ public class UserService { @Value("${popbill.businessNumber}") private String corpNum; + private static final int ABUSE_CAUTION_COUNT = 4; public UserAccountResponseDTO getUserAccount(Long userId) { val wisher = getUser(userId); @@ -76,17 +78,22 @@ private User getUser(Long userId) { } @Transactional - public void verifyUserAccount(Long userId, UserAccountVerifyRequestDTO verifyRequestDTO) throws PopbillException { + public Integer verifyUserAccount(Long userId, UserAccountVerifyRequestDTO verifyRequestDTO) throws PopbillException { checkAbuseUser(userId); + var response = 0; try { - val accountInfo = accountCheckService.CheckAccountInfo(corpNum, verifyRequestDTO.BankCode(), verifyRequestDTO.AccountNumber()); - if(!verifyRequestDTO.name().equals(accountInfo.getAccountName())){ - abuseLogRepository.save(new AbuseLog(getUser(userId))); - throw new IllegalArgumentException(NOT_VALID_USER_ACCOUNT.getMessage()); + val accountInfo = accountCheckService.CheckAccountInfo(corpNum, verifyRequestDTO.BankCode(), verifyRequestDTO.AccountNumber()); + if (!verifyRequestDTO.name().equals(accountInfo.getAccountName())) { + val abuseLog = AbuseLog.builder() + .user(getUser(userId)) + .build(); + abuseLogRepository.save(abuseLog); + response = countAbuseLogByUser(userId); } - } catch (PopbillException e) { + } catch (PopbillException e){ throw new PopbillException(e.getCode(), e.getMessage()); } + return response; } public void checkAbuseUser(Long userId){ @@ -99,13 +106,13 @@ public void checkAbuseUser(Long userId){ @Transactional public Integer countAbuseLogByUser(Long userId){ val abuseLogCount = abuseLogRepository.countAbuseLogByUserIdDuringWeekend(userId); - if(abuseLogCount >= 4){ - abuseUserRepository.save(new AbuseUser(getUser(userId))); - throw new AbuseException(IS_ABUSE_USER.getMessage()); + if(abuseLogCount >= ABUSE_CAUTION_COUNT){ + createAbuseUser(userId); } return abuseLogCount; } + @Transactional public void createAbuseUser(Long userId){ abuseUserRepository.save(new AbuseUser(getUser(userId))); } From e99253e599e2f6d9ad748ef41eb7879abbacdea1 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Wed, 13 Dec 2023 19:05:52 +0900 Subject: [PATCH 19/24] =?UTF-8?q?[TEST]=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makeawish/service/UserServiceTest.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/sopterm/makeawish/service/UserServiceTest.java b/src/test/java/com/sopterm/makeawish/service/UserServiceTest.java index b843254..7a3b8b3 100644 --- a/src/test/java/com/sopterm/makeawish/service/UserServiceTest.java +++ b/src/test/java/com/sopterm/makeawish/service/UserServiceTest.java @@ -1,9 +1,8 @@ package com.sopterm.makeawish.service; -import com.popbill.api.AccountCheckInfo; import com.popbill.api.AccountCheckService; import com.popbill.api.PopbillException; -import org.checkerframework.checker.units.qual.A; +import com.sopterm.makeawish.dto.user.UserAccountVerifyRequestDTO; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -11,7 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertThrows; @SpringBootTest @@ -26,13 +25,16 @@ class UserServiceTest { @Test @DisplayName("유효하지 않은 기관코드인 경우 예외 발생") - void 계좌_연동_실패(){ + void 계좌_연동_실패() throws PopbillException { // given - String BankCode = "0000"; - String AccountNumber = "1234567890"; - - // when - then - assertThatThrownBy(() -> userService.verifyUserAccount(1L,"홍길동",BankCode, AccountNumber)) - .isInstanceOf(PopbillException.class); + String corpNum = "0123456789"; + UserAccountVerifyRequestDTO requestDTO = UserAccountVerifyRequestDTO.builder() + .BankCode("0000") + .name("홍길동") + .AccountNumber("1234567890") + .build(); + assertThrows(PopbillException.class, () -> { + accountCheckService.CheckAccountInfo(corpNum, requestDTO.BankCode(), requestDTO.AccountNumber()); + }); } } \ No newline at end of file From 15cd79e9b6569dce0cb07fe35fe84c65797824e5 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Wed, 13 Dec 2023 19:29:35 +0900 Subject: [PATCH 20/24] =?UTF-8?q?[ADD]=20dto=20jsonproperty=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makeawish/dto/user/UserAccountVerifyRequestDTO.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sopterm/makeawish/dto/user/UserAccountVerifyRequestDTO.java b/src/main/java/com/sopterm/makeawish/dto/user/UserAccountVerifyRequestDTO.java index fa796ed..47ccd6f 100644 --- a/src/main/java/com/sopterm/makeawish/dto/user/UserAccountVerifyRequestDTO.java +++ b/src/main/java/com/sopterm/makeawish/dto/user/UserAccountVerifyRequestDTO.java @@ -1,11 +1,14 @@ package com.sopterm.makeawish.dto.user; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Builder; @Builder public record UserAccountVerifyRequestDTO( - String name - , String BankCode - , String AccountNumber + String name, + @JsonProperty("bankCode") + String BankCode, + @JsonProperty("accountNumber") + String AccountNumber ) { } From 179122e43762e0236130e8628b6ca79e8375d041 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Wed, 13 Dec 2023 19:54:04 +0900 Subject: [PATCH 21/24] =?UTF-8?q?[CHORE]=20=EC=BD=94=EB=93=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makeawish/service/UserService.java | 150 +++++++++--------- 1 file changed, 74 insertions(+), 76 deletions(-) diff --git a/src/main/java/com/sopterm/makeawish/service/UserService.java b/src/main/java/com/sopterm/makeawish/service/UserService.java index 8f856cc..0b83dc5 100644 --- a/src/main/java/com/sopterm/makeawish/service/UserService.java +++ b/src/main/java/com/sopterm/makeawish/service/UserService.java @@ -1,6 +1,5 @@ package com.sopterm.makeawish.service; -import com.popbill.api.AccountCheckInfo; import com.popbill.api.AccountCheckService; import com.popbill.api.PopbillException; import com.sopterm.makeawish.common.AbuseException; @@ -18,7 +17,6 @@ import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import lombok.val; -import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -32,88 +30,88 @@ @Transactional(readOnly = true) public class UserService { - private final UserRepository userRepository; - private final WishRepository wishRepository; - private final PresentRepository presentRepository; - private final AccountCheckService accountCheckService; - private final AbuseUserRepository abuseUserRepository; - private final AbuseLogRepository abuseLogRepository; + private final UserRepository userRepository; + private final WishRepository wishRepository; + private final PresentRepository presentRepository; + private final AccountCheckService accountCheckService; + private final AbuseUserRepository abuseUserRepository; + private final AbuseLogRepository abuseLogRepository; - @Value("${popbill.businessNumber}") - private String corpNum; - private static final int ABUSE_CAUTION_COUNT = 4; + @Value("${popbill.businessNumber}") + private String corpNum; + private static final int ABUSE_CAUTION_COUNT = 4; - public UserAccountResponseDTO getUserAccount(Long userId) { - val wisher = getUser(userId); - return nonNull(wisher.getAccount()) ? UserAccountResponseDTO.of(wisher) : null; - } + public UserAccountResponseDTO getUserAccount(Long userId) { + val wisher = getUser(userId); + return nonNull(wisher.getAccount()) ? UserAccountResponseDTO.of(wisher) : null; + } - @Transactional - public UserAccountResponseDTO updateUserAccount(Long userId, UserAccountRequestDTO requestDTO) { - val wisher = getUser(userId); - if (isNull(requestDTO.accountInfo())) { - throw new IllegalArgumentException(NO_EXIST_USER_ACCOUNT.getMessage()); - } - wisher.updateAccount( - requestDTO.accountInfo().getName(), - requestDTO.accountInfo().getBank(), - requestDTO.accountInfo().getAccount()); - wisher.updatePhoneNumber(requestDTO.phone()); - return UserAccountResponseDTO.of(wisher); - } + @Transactional + public UserAccountResponseDTO updateUserAccount(Long userId, UserAccountRequestDTO requestDTO) { + val wisher = getUser(userId); + if (isNull(requestDTO.accountInfo())) { + throw new IllegalArgumentException(NO_EXIST_USER_ACCOUNT.getMessage()); + } + wisher.updateAccount( + requestDTO.accountInfo().getName(), + requestDTO.accountInfo().getBank(), + requestDTO.accountInfo().getAccount()); + wisher.updatePhoneNumber(requestDTO.phone()); + return UserAccountResponseDTO.of(wisher); + } - @Transactional - public void deleteUser(Long userId) { - val user = getUser(userId); - user.getWishes().forEach(wish -> { - wish.getPresents().forEach(presentRepository::delete); - wishRepository.delete(wish); - }); - userRepository.delete(user); - } + @Transactional + public void deleteUser(Long userId) { + val user = getUser(userId); + user.getWishes().forEach(wish -> { + wish.getPresents().forEach(presentRepository::delete); + wishRepository.delete(wish); + }); + userRepository.delete(user); + } - private User getUser(Long userId) { - return userRepository.findById(userId) - .orElseThrow(() -> new EntityNotFoundException(INVALID_USER.getMessage())); - } + private User getUser(Long userId) { + return userRepository.findById(userId) + .orElseThrow(() -> new EntityNotFoundException(INVALID_USER.getMessage())); + } - @Transactional - public Integer verifyUserAccount(Long userId, UserAccountVerifyRequestDTO verifyRequestDTO) throws PopbillException { - checkAbuseUser(userId); - var response = 0; - try { - val accountInfo = accountCheckService.CheckAccountInfo(corpNum, verifyRequestDTO.BankCode(), verifyRequestDTO.AccountNumber()); - if (!verifyRequestDTO.name().equals(accountInfo.getAccountName())) { - val abuseLog = AbuseLog.builder() - .user(getUser(userId)) - .build(); - abuseLogRepository.save(abuseLog); - response = countAbuseLogByUser(userId); - } - } catch (PopbillException e){ - throw new PopbillException(e.getCode(), e.getMessage()); - } - return response; - } + @Transactional + public Integer verifyUserAccount(Long userId, UserAccountVerifyRequestDTO verifyRequestDTO) throws PopbillException { + checkAbuseUser(userId); + var response = 0; + try { + val accountInfo = accountCheckService.CheckAccountInfo(corpNum, verifyRequestDTO.BankCode(), verifyRequestDTO.AccountNumber()); + if (!verifyRequestDTO.name().equals(accountInfo.getAccountName())) { + val abuseLog = AbuseLog.builder() + .user(getUser(userId)) + .build(); + abuseLogRepository.save(abuseLog); + response = countAbuseLogByUser(userId); + } + } catch (PopbillException e) { + throw new PopbillException(e.getCode(), e.getMessage()); + } + return response; + } - public void checkAbuseUser(Long userId){ - abuseUserRepository.findAbuseUserByUserId(userId) - .ifPresent(abuseUser -> { - throw new AbuseException(IS_ABUSE_USER.getMessage()); + public void checkAbuseUser(Long userId) { + abuseUserRepository.findAbuseUserByUserId(userId) + .ifPresent(abuseUser -> { + throw new AbuseException(IS_ABUSE_USER.getMessage()); }); - } + } - @Transactional - public Integer countAbuseLogByUser(Long userId){ - val abuseLogCount = abuseLogRepository.countAbuseLogByUserIdDuringWeekend(userId); - if(abuseLogCount >= ABUSE_CAUTION_COUNT){ - createAbuseUser(userId); - } - return abuseLogCount; - } + @Transactional + public Integer countAbuseLogByUser(Long userId) { + val abuseLogCount = abuseLogRepository.countAbuseLogByUserIdDuringWeekend(userId); + if (abuseLogCount >= ABUSE_CAUTION_COUNT) { + createAbuseUser(userId); + } + return abuseLogCount; + } - @Transactional - public void createAbuseUser(Long userId){ - abuseUserRepository.save(new AbuseUser(getUser(userId))); - } + @Transactional + public void createAbuseUser(Long userId) { + abuseUserRepository.save(new AbuseUser(getUser(userId))); + } } From 0becd8c5544e0364b96a5632bc1882bf408b1950 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Wed, 13 Dec 2023 20:05:10 +0900 Subject: [PATCH 22/24] =?UTF-8?q?[FIX]=20=EC=BD=94=EB=93=9C=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makeawish/controller/UserController.java | 6 ++- .../makeawish/controller/WishController.java | 5 +- .../makeawish/service/AbuseService.java | 49 +++++++++++++++++++ .../makeawish/service/UserService.java | 39 +++------------ .../makeawish/service/UserServiceTest.java | 2 +- 5 files changed, 64 insertions(+), 37 deletions(-) create mode 100644 src/main/java/com/sopterm/makeawish/service/AbuseService.java diff --git a/src/main/java/com/sopterm/makeawish/controller/UserController.java b/src/main/java/com/sopterm/makeawish/controller/UserController.java index 5fabccb..89d6bbf 100644 --- a/src/main/java/com/sopterm/makeawish/controller/UserController.java +++ b/src/main/java/com/sopterm/makeawish/controller/UserController.java @@ -4,6 +4,7 @@ import com.sopterm.makeawish.domain.user.InternalMemberDetails; import com.sopterm.makeawish.dto.user.UserAccountRequestDTO; import com.sopterm.makeawish.dto.user.UserAccountVerifyRequestDTO; +import com.sopterm.makeawish.service.AbuseService; import com.sopterm.makeawish.service.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -28,6 +29,7 @@ public class UserController { private final UserService userService; + private final AbuseService abuseService; private static final int VERIFY_ACCOUNT_SUCCESS = 0; @Operation(summary = "유저 계좌 정보 가져오기") @@ -77,8 +79,8 @@ public ResponseEntity checkAccountInformation( public ResponseEntity checkAbuseUser( @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails ) { - userService.checkAbuseUser(memberDetails.getId()); - val response = userService.countAbuseLogByUser(memberDetails.getId()); + abuseService.checkAbuseUser(memberDetails.getId()); + val response = abuseService.countAbuseLogByUser(memberDetails.getId()); return ResponseEntity.ok(ApiResponse.success(IS_NOT_ABUSE_USER.getMessage(), response)); } } diff --git a/src/main/java/com/sopterm/makeawish/controller/WishController.java b/src/main/java/com/sopterm/makeawish/controller/WishController.java index 55375e8..9c67283 100644 --- a/src/main/java/com/sopterm/makeawish/controller/WishController.java +++ b/src/main/java/com/sopterm/makeawish/controller/WishController.java @@ -5,6 +5,7 @@ import com.sopterm.makeawish.dto.wish.UserWishUpdateRequestDTO; import com.sopterm.makeawish.dto.wish.WishIdRequestDTO; import com.sopterm.makeawish.dto.wish.WishRequestDTO; +import com.sopterm.makeawish.service.AbuseService; import com.sopterm.makeawish.service.UserService; import com.sopterm.makeawish.service.WishService; import io.swagger.v3.oas.annotations.Operation; @@ -36,7 +37,7 @@ public class WishController { private final WishService wishService; - private final UserService userService; + private final AbuseService abuseService; @Operation(summary = "소원 링크 생성") @PostMapping @@ -44,7 +45,7 @@ public ResponseEntity createWish( @Parameter(hidden = true) @AuthenticationPrincipal InternalMemberDetails memberDetails, @RequestBody WishRequestDTO requestDTO ) { - userService.checkAbuseUser(memberDetails.getId()); + abuseService.checkAbuseUser(memberDetails.getId()); val wishId = wishService.createWish(memberDetails.getId(), requestDTO); return ResponseEntity .created(getURI(wishId)) diff --git a/src/main/java/com/sopterm/makeawish/service/AbuseService.java b/src/main/java/com/sopterm/makeawish/service/AbuseService.java new file mode 100644 index 0000000..8d20c90 --- /dev/null +++ b/src/main/java/com/sopterm/makeawish/service/AbuseService.java @@ -0,0 +1,49 @@ +package com.sopterm.makeawish.service; + +import com.sopterm.makeawish.common.AbuseException; +import com.sopterm.makeawish.domain.abuse.AbuseLog; +import com.sopterm.makeawish.domain.abuse.AbuseUser; +import com.sopterm.makeawish.repository.abuse.AbuseLogRepository; +import com.sopterm.makeawish.repository.abuse.AbuseUserRepository; +import lombok.RequiredArgsConstructor; +import lombok.val; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import static com.sopterm.makeawish.common.message.ErrorMessage.IS_ABUSE_USER; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class AbuseService { + private final AbuseLogRepository abuseLogRepository; + private final AbuseUserRepository abuseUserRepository; + private final UserService userService; + + private static final int ABUSE_CAUTION_COUNT = 4; + + @Transactional + public void createAbuseUser(Long userId) { + abuseUserRepository.save(new AbuseUser(userService.getUser(userId))); + } + + public void checkAbuseUser(Long userId) { + abuseUserRepository.findAbuseUserByUserId(userId) + .ifPresent(abuseUser -> { + throw new AbuseException(IS_ABUSE_USER.getMessage()); + }); + } + + @Transactional + public Integer countAbuseLogByUser(Long userId) { + val abuseLogCount = abuseLogRepository.countAbuseLogByUserIdDuringWeekend(userId); + if (abuseLogCount >= ABUSE_CAUTION_COUNT) { + createAbuseUser(userId); + } + return abuseLogCount; + } + + public void createAbuseLog(AbuseLog abuseLog){ + abuseLogRepository.save(abuseLog); + } +} diff --git a/src/main/java/com/sopterm/makeawish/service/UserService.java b/src/main/java/com/sopterm/makeawish/service/UserService.java index 0b83dc5..3def780 100644 --- a/src/main/java/com/sopterm/makeawish/service/UserService.java +++ b/src/main/java/com/sopterm/makeawish/service/UserService.java @@ -2,17 +2,13 @@ import com.popbill.api.AccountCheckService; import com.popbill.api.PopbillException; -import com.sopterm.makeawish.common.AbuseException; import com.sopterm.makeawish.domain.abuse.AbuseLog; -import com.sopterm.makeawish.domain.abuse.AbuseUser; import com.sopterm.makeawish.domain.user.User; import com.sopterm.makeawish.dto.user.UserAccountRequestDTO; import com.sopterm.makeawish.dto.user.UserAccountResponseDTO; import com.sopterm.makeawish.dto.user.UserAccountVerifyRequestDTO; import com.sopterm.makeawish.repository.PresentRepository; import com.sopterm.makeawish.repository.UserRepository; -import com.sopterm.makeawish.repository.abuse.AbuseLogRepository; -import com.sopterm.makeawish.repository.abuse.AbuseUserRepository; import com.sopterm.makeawish.repository.wish.WishRepository; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; @@ -21,7 +17,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import static com.sopterm.makeawish.common.message.ErrorMessage.*; +import static com.sopterm.makeawish.common.message.ErrorMessage.INVALID_USER; +import static com.sopterm.makeawish.common.message.ErrorMessage.NO_EXIST_USER_ACCOUNT; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; @@ -34,8 +31,7 @@ public class UserService { private final WishRepository wishRepository; private final PresentRepository presentRepository; private final AccountCheckService accountCheckService; - private final AbuseUserRepository abuseUserRepository; - private final AbuseLogRepository abuseLogRepository; + private final AbuseService abuseService; @Value("${popbill.businessNumber}") private String corpNum; @@ -70,14 +66,14 @@ public void deleteUser(Long userId) { userRepository.delete(user); } - private User getUser(Long userId) { + public User getUser(Long userId) { return userRepository.findById(userId) .orElseThrow(() -> new EntityNotFoundException(INVALID_USER.getMessage())); } @Transactional public Integer verifyUserAccount(Long userId, UserAccountVerifyRequestDTO verifyRequestDTO) throws PopbillException { - checkAbuseUser(userId); + abuseService.checkAbuseUser(userId); var response = 0; try { val accountInfo = accountCheckService.CheckAccountInfo(corpNum, verifyRequestDTO.BankCode(), verifyRequestDTO.AccountNumber()); @@ -85,33 +81,12 @@ public Integer verifyUserAccount(Long userId, UserAccountVerifyRequestDTO verify val abuseLog = AbuseLog.builder() .user(getUser(userId)) .build(); - abuseLogRepository.save(abuseLog); - response = countAbuseLogByUser(userId); + abuseService.createAbuseLog(abuseLog); + response = abuseService.countAbuseLogByUser(userId); } } catch (PopbillException e) { throw new PopbillException(e.getCode(), e.getMessage()); } return response; } - - public void checkAbuseUser(Long userId) { - abuseUserRepository.findAbuseUserByUserId(userId) - .ifPresent(abuseUser -> { - throw new AbuseException(IS_ABUSE_USER.getMessage()); - }); - } - - @Transactional - public Integer countAbuseLogByUser(Long userId) { - val abuseLogCount = abuseLogRepository.countAbuseLogByUserIdDuringWeekend(userId); - if (abuseLogCount >= ABUSE_CAUTION_COUNT) { - createAbuseUser(userId); - } - return abuseLogCount; - } - - @Transactional - public void createAbuseUser(Long userId) { - abuseUserRepository.save(new AbuseUser(getUser(userId))); - } } diff --git a/src/test/java/com/sopterm/makeawish/service/UserServiceTest.java b/src/test/java/com/sopterm/makeawish/service/UserServiceTest.java index 7a3b8b3..8a97ff8 100644 --- a/src/test/java/com/sopterm/makeawish/service/UserServiceTest.java +++ b/src/test/java/com/sopterm/makeawish/service/UserServiceTest.java @@ -25,7 +25,7 @@ class UserServiceTest { @Test @DisplayName("유효하지 않은 기관코드인 경우 예외 발생") - void 계좌_연동_실패() throws PopbillException { + void failCheckAcountInfo() throws PopbillException { // given String corpNum = "0123456789"; UserAccountVerifyRequestDTO requestDTO = UserAccountVerifyRequestDTO.builder() From a4109a742263be8eada152d8bc7918c7763a5f51 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Wed, 13 Dec 2023 20:09:47 +0900 Subject: [PATCH 23/24] =?UTF-8?q?[FIX]=20=EC=88=9C=ED=99=98=EC=B0=B8?= =?UTF-8?q?=EC=A1=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopterm/makeawish/service/AbuseService.java | 14 +++++++++++--- .../com/sopterm/makeawish/service/UserService.java | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sopterm/makeawish/service/AbuseService.java b/src/main/java/com/sopterm/makeawish/service/AbuseService.java index 8d20c90..10a0ef8 100644 --- a/src/main/java/com/sopterm/makeawish/service/AbuseService.java +++ b/src/main/java/com/sopterm/makeawish/service/AbuseService.java @@ -3,13 +3,17 @@ import com.sopterm.makeawish.common.AbuseException; import com.sopterm.makeawish.domain.abuse.AbuseLog; import com.sopterm.makeawish.domain.abuse.AbuseUser; +import com.sopterm.makeawish.domain.user.User; +import com.sopterm.makeawish.repository.UserRepository; import com.sopterm.makeawish.repository.abuse.AbuseLogRepository; import com.sopterm.makeawish.repository.abuse.AbuseUserRepository; +import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import lombok.val; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import static com.sopterm.makeawish.common.message.ErrorMessage.INVALID_USER; import static com.sopterm.makeawish.common.message.ErrorMessage.IS_ABUSE_USER; @Service @@ -18,13 +22,12 @@ public class AbuseService { private final AbuseLogRepository abuseLogRepository; private final AbuseUserRepository abuseUserRepository; - private final UserService userService; - + private final UserRepository userRepository; private static final int ABUSE_CAUTION_COUNT = 4; @Transactional public void createAbuseUser(Long userId) { - abuseUserRepository.save(new AbuseUser(userService.getUser(userId))); + abuseUserRepository.save(new AbuseUser(getUser(userId))); } public void checkAbuseUser(Long userId) { @@ -46,4 +49,9 @@ public Integer countAbuseLogByUser(Long userId) { public void createAbuseLog(AbuseLog abuseLog){ abuseLogRepository.save(abuseLog); } + + private User getUser(Long userId) { + return userRepository.findById(userId) + .orElseThrow(() -> new EntityNotFoundException(INVALID_USER.getMessage())); + } } diff --git a/src/main/java/com/sopterm/makeawish/service/UserService.java b/src/main/java/com/sopterm/makeawish/service/UserService.java index 3def780..a17cc69 100644 --- a/src/main/java/com/sopterm/makeawish/service/UserService.java +++ b/src/main/java/com/sopterm/makeawish/service/UserService.java @@ -66,7 +66,7 @@ public void deleteUser(Long userId) { userRepository.delete(user); } - public User getUser(Long userId) { + private User getUser(Long userId) { return userRepository.findById(userId) .orElseThrow(() -> new EntityNotFoundException(INVALID_USER.getMessage())); } From 1a212cc186cd2df5e2d230de1a3fbe513b4f6023 Mon Sep 17 00:00:00 2001 From: yang Jiyoung <0112jyoung@naver.com> Date: Wed, 13 Dec 2023 20:11:59 +0900 Subject: [PATCH 24/24] =?UTF-8?q?[CHORE]=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20import=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/sopterm/makeawish/common/AbuseException.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/sopterm/makeawish/common/AbuseException.java b/src/main/java/com/sopterm/makeawish/common/AbuseException.java index 2e4933f..699e68e 100644 --- a/src/main/java/com/sopterm/makeawish/common/AbuseException.java +++ b/src/main/java/com/sopterm/makeawish/common/AbuseException.java @@ -1,7 +1,6 @@ package com.sopterm.makeawish.common; import lombok.Getter; -import org.springframework.http.HttpStatus; @Getter public class AbuseException extends RuntimeException {