Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: account pw api #48

Merged
merged 3 commits into from
Jul 2, 2024
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
16 changes: 8 additions & 8 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI/CD with Gradle

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

permissions:
contents: read
Expand All @@ -19,14 +19,14 @@ jobs:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
java-version: "17"
distribution: "temurin"

- name: make application yml
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml
mkdir -p src/main/resources
echo "${{ secrets.APPLICATION_YML }}" | base64 --decode > src/main/resources/application.yml
find src
shell: bash

- name: Build with Gradle
Expand All @@ -52,4 +52,4 @@ jobs:
sudo docker stop hanafun
sudo docker rm hanafun
sudo docker run -d -p 8080:8080 --name hanafun "${{ secrets.DOCKER_USERNAME_YUB }}/hanafun:latest"
sudo docker image prune -f
sudo docker image prune -f
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -23,4 +26,10 @@ ResponseEntity<ApiResponse> readAccountList(@AuthenticationPrincipal Long userId
List<AccountResDto> accountResDtoList = accountService.readAccountList(userId);
return ResponseEntity.ok(new ApiResponse(true, "ok", accountResDtoList));
}

@GetMapping("/pw")
ResponseEntity<ApiResponse> checkAccountPw(@RequestBody PwReqDto pwReqDto){
PwResDto pwResDto = accountService.checkAccountPw(pwReqDto);
return ResponseEntity.ok(new ApiResponse(true, "ok", pwResDto));
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/hanaro/hanafun/account/dto/PwReqDto.java
Original file line number Diff line number Diff line change
@@ -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;
}
14 changes: 14 additions & 0 deletions src/main/java/com/hanaro/hanafun/account/dto/PwResDto.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<AccountResDto> readAccountList(Long userId);
PwResDto checkAccountPw(PwReqDto pwReqDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
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;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand All @@ -25,4 +28,18 @@ public List<AccountResDto> 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();
}
}
Loading