Skip to content

Commit

Permalink
[Test] : 이메일 인증 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
wellbeing-dough committed Jan 22, 2024
1 parent 4ff2ee7 commit ec4903f
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.co.studyhubinu.studyhubserver.email.service;

import kr.co.studyhubinu.studyhubserver.common.timer.Timer;
import kr.co.studyhubinu.studyhubserver.email.dto.data.MailInfo;
import kr.co.studyhubinu.studyhubserver.email.dto.data.ValidDuplicationInfo;
import kr.co.studyhubinu.studyhubserver.email.dto.data.ValidMailInfo;
Expand Down Expand Up @@ -68,7 +69,7 @@ public String setContext(String code) {
return templateEngine.process("mail", context); //mail.html
}


@Timer
public boolean validEmail(ValidMailInfo info) {
String cachedAuthCode = redisTemplate.opsForValue().get(info.getEmail()); // 캐시된 인증 코드 가져오기
log.info("**************************캐싱된 인증 코드" + cachedAuthCode);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kr.co.studyhubinu.studyhubserver.emailTest;

import kr.co.studyhubinu.studyhubserver.email.dto.request.MailValidRequest;
import kr.co.studyhubinu.studyhubserver.email.dto.response.ValidEmailResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
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
@RequiredArgsConstructor
@RequestMapping("/api")
public class EmailTestController {

private final EmailTestService emailTestService;

@PostMapping("/v1/email/verify-test")
public ResponseEntity<ValidEmailResponse> validEmail(@Valid @RequestBody MailValidRequest request) {
boolean auth = emailTestService.validEmail(request.toService());
return ResponseEntity.ok(new ValidEmailResponse(auth));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package kr.co.studyhubinu.studyhubserver.emailTest;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "email")
public class EmailTestEntity {

@Id
@Column(name = "email_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String email;
private String code;

@Builder
public EmailTestEntity(Long id, String email, String code) {
this.id = id;
this.email = email;
this.code = code;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kr.co.studyhubinu.studyhubserver.emailTest;

import org.springframework.data.jpa.repository.JpaRepository;

public interface EmailTestRepository extends JpaRepository<EmailTestEntity, Long> {
String findByEmail(String email);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kr.co.studyhubinu.studyhubserver.emailTest;

import kr.co.studyhubinu.studyhubserver.common.timer.Timer;
import kr.co.studyhubinu.studyhubserver.email.dto.data.ValidMailInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class EmailTestService {

private final EmailTestRepository emailTestRepository;

@Timer
public boolean validEmail(ValidMailInfo info) {
String authCode = emailTestRepository.findByEmail(info.getEmail());
log.info("**************************저장된 인증 코드" + authCode);
log.info("**************************입력된 인증 코드" + info.getAuthCode());
return authCode != null && authCode.equals(info.getAuthCode());
}
}
7 changes: 7 additions & 0 deletions src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,11 @@ CREATE TABLE fcm_token (
user_id BIGINT NOT NULL,
token VARCHAR(255) NOT NULL,
PRIMARY KEY (fcm_token_id)
);

CREATE TABLE email (
email_id BIGINT NOT NULL AUTO_INCREMENT,
email VARCHAR(100) NOT NULL,
code VARCHAR(100) NOT NULL,
PRIMARY KEY (email_id)
);

0 comments on commit ec4903f

Please sign in to comment.