Skip to content

Commit

Permalink
Merge pull request #118 from 22caps/dev
Browse files Browse the repository at this point in the history
병합
  • Loading branch information
GiHoo authored Nov 5, 2024
2 parents db620ea + c1567fc commit 8230f92
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.syu.capsbe.domain.auth.application;

import com.syu.capsbe.domain.auth.dto.request.SignInEmailRequestDto;
import com.syu.capsbe.domain.auth.dto.response.SignInEmailResponseDto;
import com.syu.capsbe.domain.auth.dto.request.SignInRequestDto;
import com.syu.capsbe.domain.auth.dto.request.SignUpRequestDto;
import com.syu.capsbe.domain.auth.dto.response.SignInResponseDto;
Expand All @@ -12,5 +13,5 @@ public interface AuthService {

SignInResponseDto signIn(SignInRequestDto signInRequestDto);

SignInResponseDto signInWithEmail(SignInEmailRequestDto signInRequestDto);
SignInEmailResponseDto signInWithEmail(SignInEmailRequestDto signInRequestDto);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.syu.capsbe.domain.auth.application;

import com.syu.capsbe.domain.auth.dto.request.SignInEmailRequestDto;
import com.syu.capsbe.domain.auth.dto.response.SignInEmailResponseDto;
import com.syu.capsbe.domain.auth.dto.request.SignInRequestDto;
import com.syu.capsbe.domain.auth.dto.request.SignUpRequestDto;
import com.syu.capsbe.domain.auth.dto.response.SignInResponseDto;
Expand All @@ -9,6 +10,7 @@
import com.syu.capsbe.domain.member.application.MemberService;
import com.syu.capsbe.global.jwt.JwtProvider;
import com.syu.capsbe.global.jwt.dto.JwtResponseDto;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -51,12 +53,21 @@ public SignInResponseDto signIn(SignInRequestDto signInRequestDto) {
}

@Override
public SignInResponseDto signInWithEmail(SignInEmailRequestDto signInRequestDto) {
Member member = memberService.findByEmail(signInRequestDto.getEmail());
@Transactional
public SignInEmailResponseDto signInWithEmail(SignInEmailRequestDto signInRequestDto) {
Optional<Member> findMember = memberService.findByEmail(signInRequestDto.getEmail());

JwtResponseDto jwtResponseDto = jwtProvider.generateToken(member.getUsername(),
member.getRoles());
// member 없을 시 회원가입 후 반환
// 있을 경우 그냥 반환

return SignInResponseDto.of(jwtResponseDto.getAccessToken(), jwtResponseDto.getExpiresAt());
if (findMember.isEmpty()) {
Member member = Member.builder()
.email(signInRequestDto.getEmail())
.build();

memberService.save(member);
}

return SignInEmailResponseDto.of(signInRequestDto.getEmail());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.syu.capsbe.domain.auth.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Schema(description = "로그인 요청 정보")
@AllArgsConstructor
@NoArgsConstructor
public class SignInEmailResponseDto {

@Schema(description = "회원 Email", example = "[email protected]")
private String email;

public static SignInEmailResponseDto of(String email) {
return new SignInEmailResponseDto(email);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@

import com.syu.capsbe.domain.auth.application.AuthService;
import com.syu.capsbe.domain.auth.dto.request.SignInEmailRequestDto;
import com.syu.capsbe.domain.auth.dto.response.SignInEmailResponseDto;
import com.syu.capsbe.domain.auth.dto.request.SignInRequestDto;
import com.syu.capsbe.domain.auth.dto.request.SignUpRequestDto;
import com.syu.capsbe.domain.auth.dto.response.SignInResponseDto;
import com.syu.capsbe.domain.auth.dto.response.SignUpResponseDto;
import com.syu.capsbe.domain.member.Member;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -41,10 +37,10 @@ public SignUpResponseDto signUp(@RequestBody @Valid SignUpRequestDto signUpReque
}

@PostMapping("/sign-in-email")
@Operation(summary = "로그인", description = "Email을 통해 로그인을 진행합니다.")
@Operation(summary = "로그인", description = "Email을 통해 로그인을 진행합니다. 존재하지 않는 회원일 경우 회원가입 후 로그인을 진행합니다.")
@ApiResponse(responseCode = "200", description = "로그인 성공")
@ApiResponse(responseCode = "E1002", description = "존재하지 않는 회원입니다.", content = @Content)
public SignInResponseDto signInWithEmail(@RequestBody @Valid SignInEmailRequestDto signInRequestDto) {
public SignInEmailResponseDto signInWithEmail(@RequestBody @Valid SignInEmailRequestDto signInRequestDto) {
return this.authService.signInWithEmail(signInRequestDto);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.syu.capsbe.domain.member.dto.response.CorrectResponseDto;
import com.syu.capsbe.domain.member.dto.response.MemberInfoResponseDto;
import java.util.List;
import java.util.Optional;

public interface MemberService {

Expand All @@ -16,7 +17,7 @@ public interface MemberService {

Member findByUuid(String uuid);

Member findByEmail(String email);
Optional<Member> findByEmail(String email);

MemberInfoResponseDto getMemberInfo(Long memberId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -53,9 +54,9 @@ public Member findByUuid(String uuid) {
}

@Override
public Member findByEmail(String email) {
return memberRepository.findByEmail(new EmailVo(email))
.orElseThrow(() -> MemberExistsException.of(MemberErrorCode.MEMBER_IS_NOT_EXIST));
public Optional<Member> findByEmail(String email) {
return Optional.ofNullable(memberRepository.findByEmail(new EmailVo(email))
.orElseThrow(() -> MemberExistsException.of(MemberErrorCode.MEMBER_IS_NOT_EXIST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public SolveHistorySetUpResponseDto setSolveHistory(SolveHistorySetUpRequestDto
@Override
public SolveHistorySetUpResponseDto setSolveHistoryWithEmail(
SolveHistorySetUpEmailRequestDto request) {
Member member = memberService.findByEmail(request.getEmail());
Member member = memberService.findByEmail(request.getEmail()).orElseThrow();

SolveHistory solveHistory = solveHistoryRepository.save(
new SolveHistory(member, ProblemType.valueOf(request.getProblemType()), LocalDateTime.now())
Expand Down

0 comments on commit 8230f92

Please sign in to comment.