diff --git a/4Week_Mission/src/main/java/com/mutbook/week4_mission/app/base/initData/InitDataBefore.java b/4Week_Mission/src/main/java/com/mutbook/week4_mission/app/base/initData/InitDataBefore.java index 95dcdbe..a2de601 100644 --- a/4Week_Mission/src/main/java/com/mutbook/week4_mission/app/base/initData/InitDataBefore.java +++ b/4Week_Mission/src/main/java/com/mutbook/week4_mission/app/base/initData/InitDataBefore.java @@ -62,6 +62,7 @@ default void before(MemberService memberService, PostService postService, Produc memberService.addCash(member1, -5_000L, "출금__일반"); memberService.addCash(member1, 1_000_000L, "충전__무통장입금"); memberService.addCash(member2, 2_000_000L, "충전__무통장입금"); + memberService.addCash(admin, 2_000_000L, "충전__무통장입금"); withdrawService.apply(member1,"123412341234","카카오뱅크",10000L); withdrawService.apply(member2,"987098709870","신협",8000L); diff --git a/4Week_Mission/src/main/java/com/mutbook/week4_mission/app/domain/member/controller/ApiV1MemberController.java b/4Week_Mission/src/main/java/com/mutbook/week4_mission/app/domain/member/controller/ApiV1MemberController.java new file mode 100644 index 0000000..05e17ca --- /dev/null +++ b/4Week_Mission/src/main/java/com/mutbook/week4_mission/app/domain/member/controller/ApiV1MemberController.java @@ -0,0 +1,56 @@ +package com.mutbook.week4_mission.app.domain.member.controller; + +import com.mutbook.week4_mission.app.base.dto.RsData; +import com.mutbook.week4_mission.app.domain.member.dto.LoginDto; +import com.mutbook.week4_mission.app.domain.member.entity.Member; +import com.mutbook.week4_mission.app.domain.member.service.MemberService; +import com.mutbook.week4_mission.util.Util; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.validation.Valid; + +@RestController +@RequestMapping("api/v1/member") +@RequiredArgsConstructor +@Slf4j +@Tag(name = "ApiV1MemberController", description = "로그인 기능과 로그인 된 회원의 정보를 제공 기능을 담당하는 컨트롤러") +public class ApiV1MemberController { + private final MemberService memberService; + private final PasswordEncoder passwordEncoder; + + @PostMapping("/login") + public ResponseEntity login(@Valid @RequestBody LoginDto loginDto) { + Member member = memberService.findByUsername(loginDto.getUsername()).orElse(null); + + if (member == null) { + return Util.spring.responseEntityOf(RsData.of("F-2", "일치하는 회원이 존재하지 않습니다.")); + } + + if (passwordEncoder.matches(loginDto.getPassword(), member.getPassword()) == false) { + return Util.spring.responseEntityOf(RsData.of("F-3", "비밀번호가 일치하지 않습니다.")); + } + + log.debug("Util.json.toStr(member.getAccessTokenClaims()) : " + Util.json.toStr(member.getAccessTokenClaims())); + + String accessToken = memberService.genAccessToken(member); + + return Util.spring.responseEntityOf( + RsData.of( + "S-1", + "로그인 성공, Access Token을 발급합니다.", + Util.mapOf( + "accessToken", accessToken + ) + ), + Util.spring.httpHeadersOf("Authentication", accessToken) + ); + } +}