diff --git a/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java b/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java index 975d0b5..032e367 100644 --- a/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java +++ b/src/main/java/com/hanaro/hanafun/account/controller/AccountController.java @@ -1,12 +1,15 @@ package com.hanaro.hanafun.account.controller; import com.hanaro.hanafun.account.dto.AccountResDto; +import com.hanaro.hanafun.account.dto.PwReqDto; +import com.hanaro.hanafun.account.dto.PwResDto; import com.hanaro.hanafun.account.service.impl.AccountServiceImpl; import com.hanaro.hanafun.common.dto.ApiResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -23,4 +26,10 @@ ResponseEntity readAccountList(@AuthenticationPrincipal Long userId List accountResDtoList = accountService.readAccountList(userId); return ResponseEntity.ok(new ApiResponse(true, "ok", accountResDtoList)); } + + @GetMapping("/pw") + ResponseEntity checkAccountPw(@RequestBody PwReqDto pwReqDto){ + PwResDto pwResDto = accountService.checkAccountPw(pwReqDto); + return ResponseEntity.ok(new ApiResponse(true, "ok", pwResDto)); + } } diff --git a/src/main/java/com/hanaro/hanafun/account/dto/PwReqDto.java b/src/main/java/com/hanaro/hanafun/account/dto/PwReqDto.java new file mode 100644 index 0000000..70ec194 --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/account/dto/PwReqDto.java @@ -0,0 +1,15 @@ +package com.hanaro.hanafun.account.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class PwReqDto { + private long accountId; + private String password; +} diff --git a/src/main/java/com/hanaro/hanafun/account/dto/PwResDto.java b/src/main/java/com/hanaro/hanafun/account/dto/PwResDto.java new file mode 100644 index 0000000..f9a751a --- /dev/null +++ b/src/main/java/com/hanaro/hanafun/account/dto/PwResDto.java @@ -0,0 +1,14 @@ +package com.hanaro.hanafun.account.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class PwResDto { + private boolean check; +} diff --git a/src/main/java/com/hanaro/hanafun/account/service/AccountService.java b/src/main/java/com/hanaro/hanafun/account/service/AccountService.java index 4e306c6..1d79887 100644 --- a/src/main/java/com/hanaro/hanafun/account/service/AccountService.java +++ b/src/main/java/com/hanaro/hanafun/account/service/AccountService.java @@ -1,9 +1,12 @@ package com.hanaro.hanafun.account.service; import com.hanaro.hanafun.account.dto.AccountResDto; +import com.hanaro.hanafun.account.dto.PwReqDto; +import com.hanaro.hanafun.account.dto.PwResDto; import java.util.List; public interface AccountService { List readAccountList(Long userId); + PwResDto checkAccountPw(PwReqDto pwReqDto); } diff --git a/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java b/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java index 1d7fcdb..70f0c19 100644 --- a/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/hanaro/hanafun/account/service/impl/AccountServiceImpl.java @@ -3,6 +3,8 @@ import com.hanaro.hanafun.account.domain.AccountEntity; import com.hanaro.hanafun.account.domain.AccountRepository; import com.hanaro.hanafun.account.dto.AccountResDto; +import com.hanaro.hanafun.account.dto.PwReqDto; +import com.hanaro.hanafun.account.dto.PwResDto; import com.hanaro.hanafun.account.exception.AccountNotFoundException; import com.hanaro.hanafun.account.mapper.AccountMapper; import com.hanaro.hanafun.account.service.AccountService; @@ -10,6 +12,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; @Service @RequiredArgsConstructor @@ -25,4 +28,18 @@ public List readAccountList(Long userId) { return accountEntityList.stream().map(AccountMapper::entityToAccountResDto).toList(); } + + @Override + public PwResDto checkAccountPw(PwReqDto pwReqDto) { + AccountEntity accountEntity = accountRepository.findById(pwReqDto.getAccountId()).orElseThrow(() -> new AccountNotFoundException()); + boolean check; + if(accountEntity.getPassword().equals(pwReqDto.getPassword())){ + check = true; + } else{ + check = false; + } + return new PwResDto().builder() + .check(check) + .build(); + } }