๊ฐœ๋ฐœ์ผ์ง€-5 [๐Ÿ‘จโ€๐ŸณํŒ๋งค์ž ๋„๋ฉ”์ธ: ํšŒ์›๊ฐ€์ž… ์‹œ ๋ณธ์ธ์ธ์ฆ]

๊น€์„ฑ์ธยท2023๋…„ 9์›” 4์ผ
0

ํŒ๋งค์ž ๋„๋ฉ”์ธ ๊ธฐ๋Šฅ ์ •์˜ ํฌ์ŠคํŒ…


๋ณธ์ธ์ธ์ฆ ํ™”๋ฉด ๋ทฐ


1. [POST] /jat/sellers/authy

ํšŒ์›๊ฐ€์ž… ํ•˜๊ธฐ ์ „ ๋ณธ์ธ ํ™•์ธ ์ธ์ฆ๋ฒˆํ˜ธ ์š”์ฒญ

  • ์›๋ž˜๋Š” IamPort๋ผ๋Š” ๊ฒฐ์ œ ๋Œ€ํ–‰์‚ฌ์˜ API๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ณธ์ธ์ธ์ฆ์„ PASS๋“ฑ์œผ๋กœ ํ•˜๋ ค๊ณ  ํ–ˆ์œผ๋‚˜.. ๊ฐœ์ธ์ •๋ณด๋ฅผ ๋‹ค๋ฃจ๋Š” API์ด๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์—…์ž ๋“ฑ๋ก์ฆ์„ ํ†ตํ•ด์„œ ํ•ด๋‹น ํšŒ์‚ฌ์™€ ๊ณ„์•ฝ์„ ํ•ด์•ผ API๊ฐ€ ์‚ฌ์šฉ๊ฐ€๋Šฅ ํ•˜์˜€๋‹ค..
  • ๊ทธ๋ž˜์„œ ์ƒ๊ฐํ•œ ๋ฐฉ๋ฒ•์€ ํŒ๋งค์ž์˜ ํ•ธ๋“œํฐ์œผ๋กœ SMS ๋ฌธ์ž ๋ฐœ์†ก์„ ํ†ตํ•ด์„œ ๋ณธ์ธ์ธ์ฆ์„ ํ•˜๋Š” ๊ฒƒ์„ ๋ชฉํ‘œ๋กœ ํ•˜์˜€๋‹ค.. (coolSMS API)
  • ํ•˜์ง€๋งŒ ์ด ๋ฐฉ๋ฒ•์€ ํฐ๋ฒˆํ˜ธ๋ฅผ ํ†ตํ•œ ์ธ์ฆ์ผ ๋ฟ ํŒ๋งค์ž์˜ ์‹ค์ œ ๊ฐœ์ธ์ •๋ณด์™€ ์ผ์น˜ํ•˜๋Š”์ง€๋Š” ๊ตฌํ˜„ํ•˜์ง€ ๋ชปํ•˜์˜€๋‹ค.. (ํœด๋Œ€ํฐ์€ ํ›„ ์•Œ๋ฆผ ๊ธฐ๋Šฅ ๋„ฃ๊ธฐ ์œ„ํ•จ)
  • ๊ทธ๋ž˜๋„ ๊ณ ๊ฐ ์ •๋ณด๋Š” ์œ ์ง€ํ•ด์•ผํ•˜๋‹ˆ, ์„œ๋ฒ„์— ๊ฐ’์„ ์ €์žฅํ•˜๊ธฐ๋กœ ํ•จ.

(1) SMS ํ…Œ์ด๋ธ”

Redis๋ฅผ ํ†ตํ•œ ์ž„์‹œ ๊ฐ’์œผ๋กœ ์šด์˜ํ•˜๋ ค ํ–ˆ์œผ๋‚˜, ๊ฐ„๋‹จํ•˜๊ณ  ๋น ๋ฅด๊ฒŒ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด DBํ…Œ์ด๋ธ”์„ ๋งŒ๋“ค์—ˆ๋‹ค.

(2) ๋กœ์ง ํ”Œ๋กœ์šฐ

1. ์ด๋ฆ„, ์ƒ๋…„์›”์ผ, ํฐ๋ฒˆํ˜ธ๋ฅผ POST๋กœ ์š”์ฒญ ๋ฐ›์Œ.
2. ํ•ด๋‹น ํšŒ์› ์ •๋ณด๋ฅผ ์ด์šฉํ•ด ์ด๋ฏธ ๊ฐ€์ž…ํ•œ ํšŒ์›์ธ์ง€ ํ™•์ธ.
3. ๋žœ๋ค ์ธ์ฆ๋ฒˆํ˜ธ ์ƒ์„ฑ
4. SMS ์ธ์ฆ ๋ฉ”์‹œ์ง€ ์ƒ์„ฑ ๋ฐ coolSMS๋ฅผ ์ด์šฉํ•œ ๋ฌธ์ž ๋ฉ”์‹œ์ง€ ์ „์†ก API ์š”์ฒญ
5. SMS ์ธ์ฆ ๋ฉ”์‹œ์ง€ ์ •๋ณด ์„œ๋ฒ„ DB์ €์žฅ

(๋ฌธ์ž์ธ์ฆ ๊ตฌํ˜„ ํฌ์ŠคํŒ…)

  • ์š”์ฒญ ๋ฐ”๋”” [PostSignUpAuthyReq.java]
  • SellerController.java
  • SellerService.java
@Transactional(rollbackFor = BaseException.class)
    public PostSignUpAuthyRes userAuthy(PostSignUpAuthyReq signUpAuthy) throws BaseException {
        // 1) ํšŒ์›๊ฐ€์ž… ๊ฐ€๋Šฅํ•œ์ง€?? ์ด๋ฏธ ๋“ฑ๋ก๋œ ํšŒ์›์ธ์ง€??
        int duplicateUser;
        try{
            duplicateUser = sellerDao.userAuthy(signUpAuthy);
        }catch(Exception exception){
            throw new BaseException(POST_USERS_NOT_FOUND); // 2021 : ๊ฐ€์ž…ํ•˜์ง€ ์•Š์€ ํšŒ์›์ž…๋‹ˆ๋‹ค.
        }

        if (duplicateUser == 1){
            try{
                // 2) ๋žœ๋ค ์ธ์ฆ๋ฒˆํ˜ธ ์ƒ์„ฑ (๋ฒˆํ˜ธ)
                Random rand  = new Random();
                String certificationNum = "";
                for(int i=0; i<6; i++) {
                    String ran = Integer.toString(rand.nextInt(10));
                    certificationNum+=ran;
                }

                // 3) ์ธ์ฆ ๋ฉ”์‹œ์ง€ ์ƒ์„ฑ
                Message message = new Message();
                message.setFrom("01043753181");
                message.setTo(signUpAuthy.getPhoneNum());
                message.setText("ํšŒ์›๊ฐ€์ž… ๋ณธ์ธ์ธ์ฆ ํ™•์ธ์ž…๋‹ˆ๋‹ค.\n["+certificationNum+"]");

                // 4) coolSMS API ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž ํ•ธ๋“œํฐ์— ์ „์†ก
                SingleMessageSentResponse response = this.messageService.sendOne(new SingleMessageSendingRequest(message));
                log.info("coolSMS API์š”์ฒญ :{}", response);

                // 5) DB์— ์ „์†ก ์ธ์ฆ์ •๋ณด ์ €์žฅ
                int smsSendRes = smsDao.smsAuthy(signUpAuthy, certificationNum, "S");
                return new PostSignUpAuthyRes(smsSendRes);

            }catch(Exception exception){
                throw new BaseException(COOLSMS_API_ERROR); //  5010 : SMS ์ธ์ฆ๋ฒˆํ˜ธ ๋ฐœ์†ก์„ ์‹คํŒจํ•˜์˜€์Šต๋‹ˆ๋‹ค.
            }
        }
        else{
            throw new BaseException(POST_USERS_ALREADY_EXISTS); // 2016 : ์ด๋ฏธ ๊ฐ€์ž…ํ•œ ํšŒ์›์ž…๋‹ˆ๋‹ค.
        }
    }
  • SellerDao.java
    ํŒ๋งค์ž ํ…Œ์ด๋ธ”์— ํ•ด๋‹น ์ด๋ฆ„๊ณผ ์ƒ๋…„์›”์ผ, ํฐ๋ฒˆํ˜ธ๋กœ ๊ฐ€์ž…๋˜์–ด ์žˆ๋Š” ์œ ์ € ์กฐํšŒ.
public int userAuthy(PostSignUpAuthyReq signUpAuthy) {
        String query = "SELECT NOT EXISTS(\n" +
                "    SELECT * FROM Merchandisers\n" +
                "             WHERE name = ? AND\n" +
                "                   birthday = ? AND\n" +
                "                   phone = ? AND \n" +
                "                   status = 'A'\n" +
                ")";

        Object[] params = new Object[]{
                signUpAuthy.getName(),
                signUpAuthy.getBirth(),
                signUpAuthy.getPhoneNum()
        };
        return this.jdbcTemplate.queryForObject(query, int.class, params);
    }

2. [POST] /jat/sellers/authy-pass

๋ณธ์ธ ์ธ์ฆ ๋ฒˆํ˜ธ ํ™•์ธ

  • ํ•ธ๋“œํฐ์„ ํ†ตํ•ด ์ „์†ก๋œ ๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ๋ณธ์ธํ™•์ธ์„ ์ง„ํ–‰ํ•œ๋‹ค.
  • ๋ณธ์ธ์ธ์ฆ ๋ฒˆํ˜ธ์˜ ์œ ํšจ๊ธฐ๊ฐ„์€ 3๋ถ„, DB์—์„œ ํ˜„์‹œ๊ฐ„์œผ๋กœ๋ถ€ํ„ฐ 3๋ถ„์ด ์ง€๋‚œ ๊ธฐ๋ก์€ ์ƒํƒœ๋ฅผ 'D'๋กœ ๋ฐ”๊ฟ”์„œ ์œ ํšจํ•˜์ง€ ์•Š๊ฒŒํ•ด์•ผํ•จ.
  • ๋ฐฐ์น˜๋ฅผ ์•„์ง ์™„์„ฑํ•˜์ง€ ๋ชปํ•ด์„œ ์กฐํšŒ์‹œ์— DB์— created(์ƒ์„ฑ๋œ ์‹œ๊ฐ„)๊ฐ€ 3๋ถ„ ์ด๋‚ด์ธ ๋งˆ์ง€๋ง‰ ์ธ์ฆ์š”์ฒญ ๋ฒˆํ˜ธ๋ฅผ ์กฐํšŒํ•˜๊ธฐ๋กœ ํ•˜์˜€๋‹ค.

(1) ๋กœ์ง ํ”Œ๋กœ์šฐ
1. ๋ณธ์ธ์ธ์ฆ ์š”์ฒญ์— ์‚ฌ์šฉํ–ˆ๋˜ ์ •๋ณด + ํฐ์œผ๋กœ ์ˆ˜์‹ ๋ฐ›์€ ๋ณธ์ธ์ธ์ฆ ๋ฒˆํ˜ธ๋ฅผ ๋ฐ”๋””์— ๋‹ด์•„ POST๋กœ ์š”์ฒญ
2. ํ•ด๋‹น ํšŒ์›์˜ ์ธ์ฆ ์š”์ฒญ์— ๋Œ€ํ•œ ์ •๋ณด๊ฐ€ ๋ณด๋‚ธ์ง€ 3๋ถ„ ์ด๋‚ด์ด๊ณ , ๋งˆ์ง€๋ง‰์— ๋ณด๋‚ธ ์ธ์ฆ๋ฒˆํ˜ธ๋ฅผ ํ™•์ธ
3. ๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•œ๋‹ค๋ฉด ๋ณธ์ธ์ธ์ฆ ์™„๋ฃŒ.

  • ์š”์ฒญ๋ฐ”๋””
  • SellerController.java
  • SellerService.java
 public PostSignUpAuthyRes userAuthyPass(PostSignUpAuthyReq passReq) throws BaseException{
        try{
            int userPass = smsDao.smsAuthyPass(passReq);

            return new PostSignUpAuthyRes(userPass);
        }catch(Exception exception){
            throw new BaseException(COOLSMS_API_ERROR); // 5010 : SMS ์ธ์ฆ๋ฒˆํ˜ธ ๋ฐœ์†ก์„ ์‹คํŒจํ•˜์˜€์Šต๋‹ˆ๋‹ค.
        }
    }
  • SellerDao.java
public int smsAuthyPass(PostSignUpAuthyReq signUPValid){
        String query = "SELECT EXISTS(\n" +
                "    SELECT\n" +
                "        *\n" +
                "    FROM Sms\n" +
                "    WHERE phone = ? AND\n" +
                "          name = ? AND\n" +
                "          uid = ? AND\n" +
                "          certification_num = ? AND\n" +
                "          status = 'S' AND\n" +
                "          created >= DATE_ADD(NOW(), INTERVAL -3 MINUTE)\n" +
                "    ORDER BY created DESC LIMIT 1)";

        Object[] params = new Object[]{
                signUPValid.getPhoneNum(),
                signUPValid.getName(),
                signUPValid.getBirth(),
                signUPValid.getCertificationNum(),
        };

        return this.jdbcTemplate.queryForObject(query, int.class, params);
    }

๋‹ค์Œ์€ ๋ณธ์ธ ์ธ์ฆ ํ›„ ํšŒ์›๊ฐ€์ž…์„ ํ•˜๋Š” ์ ˆ์ฐจ์— ๋Œ€ํ•ด ํฌ์ŠคํŒ…ํ•˜๋„๋ก ํ•˜๊ฒ ๋‹ค.

profile
๊ฐœ๋ฐœ์ž๊ฐ€ ๊ฟˆ์ธ 25์‚ด ๋Œ€ํ•™์ƒ์ž…๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€