프로젝트 정리/경조사 가계부 프로젝트

9. 회원가입 토큰 인증

@GetMapping("/check-email-token")
    public String checkEmailToken(String token, String email, Model model) {
        Account account =  accountService.findMembersByEmail(email);
        //accountRepository.findByEmail(email);
        String view = "account/checked-email";

        if (account == null){
            model.addAttribute("error","wrong email");
            return view;
        }
        if(!account.isValidToken(token)){
            model.addAttribute("error","wrong email");
            return view;
        }
        File file;
        ZipEntry entry = null;

        accountService.completeSignUp(account);
        model.addAttribute("numberOfUser", accountService.count()); // <- n번째 가입임을 알려주기 위함
        model.addAttribute("nickname", account.getNickname());
        return view;
    }

=>

public static final String COUNT =
            '''
            SELECT COUNT(*) FROM account
            '''
accountRepository.count()
->
AccountRepository accountRepository;
->
AccountRepository extends JpaRepository<Account, Long>

JpaRepository의 내장 기능

Repository -> CrudRepository -> PagingAndSortingRepository -> JpRepository 순으로 상속 된다.

CrudRepsitory에서 count() 함수는 다음과 같이 정의되어 있다.
long count()
Returns the number of entities available.
Returns:
the number of entities.

https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/repository/CrudRepository.html

 

CrudRepository (Spring Data Core 2.7.0 API)

Returns all instances of the type T with the given IDs. If some or all ids are not found, no entities are returned for these IDs. Note that the order of elements in the result is not guaranteed.

docs.spring.io

 

결과 화면