-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from Try-AngIe/feat/product
feat: 상품을 수정 및 삭제할 수 있다.
- Loading branch information
Showing
11 changed files
with
219 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 43 additions & 43 deletions
86
...src/main/java/kr/or/kosa/cmsplusmain/domain/messaging/controller/MessagingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
package kr.or.kosa.cmsplusmain.domain.messaging.controller; | ||
|
||
import org.springframework.http.HttpStatus; | ||
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 kr.or.kosa.cmsplusmain.domain.messaging.dto.SmsVerifyDto; | ||
import kr.or.kosa.cmsplusmain.domain.messaging.service.SmsService; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/vendor/auth") | ||
public class MessagingController { | ||
|
||
private final SmsService smsService; | ||
|
||
// SMS 인증번호 요청 | ||
@PostMapping("/sms/sending") | ||
public ResponseEntity<String> sendSms(@RequestBody SmsVerifyDto smsVerifyDto) { | ||
try { | ||
smsService.sendSmsCode(smsVerifyDto); | ||
return ResponseEntity.ok("[SMS] 인증코드 전송 성공"); | ||
} catch (Exception e) { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); | ||
} | ||
} | ||
|
||
// SMS 인증번호 검사 | ||
@PostMapping("/sms/verification") | ||
public ResponseEntity<String> SmsVerification(@RequestBody SmsVerifyDto smsVerifyDto) { | ||
try { | ||
smsService.verifySmsCode(smsVerifyDto); | ||
return ResponseEntity.ok("[SMS] 인증 성공"); | ||
} catch (Exception e) { | ||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); | ||
} | ||
} | ||
|
||
} | ||
//package kr.or.kosa.cmsplusmain.domain.messaging.controller; | ||
// | ||
//import org.springframework.http.HttpStatus; | ||
//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 kr.or.kosa.cmsplusmain.domain.messaging.dto.SmsVerifyDto; | ||
//import kr.or.kosa.cmsplusmain.domain.messaging.service.SmsService; | ||
//import lombok.RequiredArgsConstructor; | ||
// | ||
//@RestController | ||
//@RequiredArgsConstructor | ||
//@RequestMapping("/api/v1/vendor/auth") | ||
//public class MessagingController { | ||
// | ||
// private final SmsService smsService; | ||
// | ||
// // SMS 인증번호 요청 | ||
// @PostMapping("/sms/sending") | ||
// public ResponseEntity<String> sendSms(@RequestBody SmsVerifyDto smsVerifyDto) { | ||
// try { | ||
// smsService.sendSmsCode(smsVerifyDto); | ||
// return ResponseEntity.ok("[SMS] 인증코드 전송 성공"); | ||
// } catch (Exception e) { | ||
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); | ||
// } | ||
// } | ||
// | ||
// // SMS 인증번호 검사 | ||
// @PostMapping("/sms/verification") | ||
// public ResponseEntity<String> SmsVerification(@RequestBody SmsVerifyDto smsVerifyDto) { | ||
// try { | ||
// smsService.verifySmsCode(smsVerifyDto); | ||
// return ResponseEntity.ok("[SMS] 인증 성공"); | ||
// } catch (Exception e) { | ||
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage()); | ||
// } | ||
// } | ||
// | ||
//} |
74 changes: 37 additions & 37 deletions
74
server/src/main/java/kr/or/kosa/cmsplusmain/domain/messaging/repository/SmsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
package kr.or.kosa.cmsplusmain.domain.messaging.repository; | ||
|
||
import java.time.Duration; | ||
|
||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class SmsRepository { | ||
|
||
// Redis 데이터 설정 | ||
private final String PREFIX = "SMS-"; // 저장되는 키 값은 "SMS-01011111111" 형태 | ||
private final int LIMIT_TIME = 5 * 60; // 300초(5분)동안 캐싱 | ||
|
||
private final StringRedisTemplate redisTemplate; | ||
|
||
public void createSmsVerification(String phone, String certificationNumber) { | ||
redisTemplate.opsForValue() | ||
.set(PREFIX + phone, certificationNumber, Duration.ofSeconds(LIMIT_TIME)); | ||
} | ||
|
||
public String getSmsVerification(String phone) { | ||
return redisTemplate.opsForValue().get(PREFIX + phone); | ||
} | ||
|
||
public void removeSmsCertification(String phone) { | ||
redisTemplate.delete(PREFIX + phone); | ||
} | ||
|
||
public boolean hasKey(String phone) { | ||
return redisTemplate.hasKey(PREFIX + phone); | ||
} | ||
|
||
} | ||
//package kr.or.kosa.cmsplusmain.domain.messaging.repository; | ||
// | ||
//import java.time.Duration; | ||
// | ||
//import org.springframework.data.redis.core.StringRedisTemplate; | ||
//import org.springframework.stereotype.Repository; | ||
// | ||
//import lombok.RequiredArgsConstructor; | ||
// | ||
//@Repository | ||
//@RequiredArgsConstructor | ||
//public class SmsRepository { | ||
// | ||
// // Redis 데이터 설정 | ||
// private final String PREFIX = "SMS-"; // 저장되는 키 값은 "SMS-01011111111" 형태 | ||
// private final int LIMIT_TIME = 5 * 60; // 300초(5분)동안 캐싱 | ||
// | ||
// private final StringRedisTemplate redisTemplate; | ||
// | ||
// public void createSmsVerification(String phone, String certificationNumber) { | ||
// redisTemplate.opsForValue() | ||
// .set(PREFIX + phone, certificationNumber, Duration.ofSeconds(LIMIT_TIME)); | ||
// } | ||
// | ||
// public String getSmsVerification(String phone) { | ||
// return redisTemplate.opsForValue().get(PREFIX + phone); | ||
// } | ||
// | ||
// public void removeSmsCertification(String phone) { | ||
// redisTemplate.delete(PREFIX + phone); | ||
// } | ||
// | ||
// public boolean hasKey(String phone) { | ||
// return redisTemplate.hasKey(PREFIX + phone); | ||
// } | ||
// | ||
//} |
80 changes: 40 additions & 40 deletions
80
server/src/main/java/kr/or/kosa/cmsplusmain/domain/messaging/service/SmsServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
package kr.or.kosa.cmsplusmain.domain.messaging.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import kr.or.kosa.cmsplusmain.domain.messaging.dto.SmsVerifyDto; | ||
import kr.or.kosa.cmsplusmain.domain.messaging.repository.SmsRepository; | ||
import kr.or.kosa.cmsplusmain.util.SmsUtil; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class SmsServiceImpl implements SmsService { | ||
|
||
private final SmsUtil smsUtil; | ||
private final SmsRepository smsRepository; | ||
|
||
public void sendSmsCode(SmsVerifyDto smsVerifyDto) { | ||
String to = smsVerifyDto.getPhone(); | ||
int randomNumber = (int)(Math.random() * 9000) + 1000; | ||
String certificationNumber = String.valueOf(randomNumber); | ||
smsUtil.sendSms(to, certificationNumber); | ||
smsRepository.createSmsVerification(to, certificationNumber); | ||
} | ||
|
||
public void verifySmsCode(SmsVerifyDto smsVerifyDto) { | ||
if (!isVerify(smsVerifyDto)) { | ||
throw new IllegalArgumentException("[SMS] 인증번호 불일치"); | ||
} | ||
smsRepository.removeSmsCertification(smsVerifyDto.getPhone()); | ||
} | ||
|
||
public boolean isVerify(SmsVerifyDto smsVerifyDto) { | ||
return smsRepository.hasKey(smsVerifyDto.getPhone()) && | ||
smsRepository.getSmsVerification(smsVerifyDto.getPhone()) | ||
.equals(smsVerifyDto.getSmsVerifyCode()); | ||
} | ||
|
||
} | ||
//package kr.or.kosa.cmsplusmain.domain.messaging.service; | ||
// | ||
//import org.springframework.stereotype.Service; | ||
//import org.springframework.transaction.annotation.Transactional; | ||
// | ||
//import kr.or.kosa.cmsplusmain.domain.messaging.dto.SmsVerifyDto; | ||
//import kr.or.kosa.cmsplusmain.domain.messaging.repository.SmsRepository; | ||
//import kr.or.kosa.cmsplusmain.util.SmsUtil; | ||
//import lombok.RequiredArgsConstructor; | ||
// | ||
//@Service | ||
//@Transactional | ||
//@RequiredArgsConstructor | ||
//public class SmsServiceImpl implements SmsService { | ||
// | ||
// private final SmsUtil smsUtil; | ||
// private final SmsRepository smsRepository; | ||
// | ||
// public void sendSmsCode(SmsVerifyDto smsVerifyDto) { | ||
// String to = smsVerifyDto.getPhone(); | ||
// int randomNumber = (int)(Math.random() * 9000) + 1000; | ||
// String certificationNumber = String.valueOf(randomNumber); | ||
// smsUtil.sendSms(to, certificationNumber); | ||
// smsRepository.createSmsVerification(to, certificationNumber); | ||
// } | ||
// | ||
// public void verifySmsCode(SmsVerifyDto smsVerifyDto) { | ||
// if (!isVerify(smsVerifyDto)) { | ||
// throw new IllegalArgumentException("[SMS] 인증번호 불일치"); | ||
// } | ||
// smsRepository.removeSmsCertification(smsVerifyDto.getPhone()); | ||
// } | ||
// | ||
// public boolean isVerify(SmsVerifyDto smsVerifyDto) { | ||
// return smsRepository.hasKey(smsVerifyDto.getPhone()) && | ||
// smsRepository.getSmsVerification(smsVerifyDto.getPhone()) | ||
// .equals(smsVerifyDto.getSmsVerifyCode()); | ||
// } | ||
// | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.