-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor API Response and Other Classes (#21)
- Add creator class for `APIResponse`. - Rename package `aspect` to `log`.
- Loading branch information
1 parent
1fd07ce
commit e07fab3
Showing
15 changed files
with
147 additions
and
174 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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/ittovative/otpservice/controller/OTPController.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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.ittovative.otpservice.controller; | ||
|
||
import com.ittovative.otpservice.config.SwaggerConfig; | ||
import com.ittovative.otpservice.constant.APIResponseConstant; | ||
import com.ittovative.otpservice.constant.SwaggerConstant; | ||
import com.ittovative.otpservice.dto.OTPRequestDTO; | ||
import com.ittovative.otpservice.dto.TokenDTO; | ||
import com.ittovative.otpservice.service.OTPService; | ||
import com.ittovative.otpservice.util.APIResponse; | ||
import com.ittovative.otpservice.util.ResponseUtil; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import org.apache.coyote.BadRequestException; | ||
import org.springframework.http.HttpStatus; | ||
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; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/sms") | ||
@Tag(name = SwaggerConstant.CONTROLLER_NAME, description = SwaggerConstant.CONTROLLER_DESCRIPTION) | ||
public class OTPController implements SwaggerConfig { | ||
private final OTPService otpService; | ||
|
||
public OTPController(OTPService otpService) { | ||
this.otpService = otpService; | ||
} | ||
|
||
/** | ||
* Send message response entity. | ||
* | ||
* @param otpRequestDto the otp request dto | ||
* @return the response entity | ||
*/ | ||
@Override | ||
@PostMapping | ||
public APIResponse<String> sendMessage(@RequestBody @Valid OTPRequestDTO otpRequestDto) { | ||
otpService.send(otpRequestDto); | ||
return ResponseUtil.createUnifiedResponse(HttpStatus.CREATED.value(), APIResponseConstant.OTP_SENT, null); | ||
} | ||
|
||
/** | ||
* Verify response entity. | ||
* | ||
* @param tokenDto the verify otp request dto | ||
* @return the response entity | ||
* @throws BadRequestException the bad request exception | ||
*/ | ||
@Override | ||
@PostMapping("/verify") | ||
public APIResponse<String> verify(@RequestBody @Valid TokenDTO tokenDto) | ||
throws BadRequestException { | ||
otpService.verifyToken(tokenDto); | ||
return ResponseUtil.createUnifiedResponse(HttpStatus.OK.value(), APIResponseConstant.TOKEN_VERIFIED, null); | ||
} | ||
} |
62 changes: 0 additions & 62 deletions
62
src/main/java/com/ittovative/otpservice/controller/OtpController.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.