-
Notifications
You must be signed in to change notification settings - Fork 54
Twilio service call #692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Twilio service call #692
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6c51695
twilio call service
noxxspring 1653195
updated my db and endpoints
noxxspring 1259365
updated my errorresponse and web config
noxxspring 42d62c5
updated my errorresponse
noxxspring 7daeba5
deleted errorresponse class and renamed calllogs to entity
noxxspring ccacc9f
updated Entity
noxxspring 9e4e7f1
resolving conflict
noxxspring afd9fa3
Merge branch 'dev' into twilioServiceCall
noxxspring File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
27 changes: 27 additions & 0 deletions
27
src/main/java/hng_java_boilerplate/twilio/CallLogs/Entity.java
This file contains hidden or 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,27 @@ | ||
| package hng_java_boilerplate.twilio.CallLogs; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @jakarta.persistence.Entity | ||
| @Table(name = "call_logs") | ||
| @Data | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Builder | ||
| public class Entity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| private String toNumber; | ||
| private String fromNumber; | ||
| private String callSid; | ||
| private LocalDateTime timestamp; | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/main/java/hng_java_boilerplate/twilio/Controller/TwillioCallController.java
This file contains hidden or 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,39 @@ | ||
| package hng_java_boilerplate.twilio.Controller; | ||
|
|
||
| import com.twilio.exception.TwilioException; | ||
| import hng_java_boilerplate.comment.dto.ErrorResponse; | ||
| import hng_java_boilerplate.exception.BadRequestException; | ||
| import hng_java_boilerplate.exception.CustomError; | ||
| import hng_java_boilerplate.exception.NotFoundException; | ||
| import hng_java_boilerplate.twilio.RequestAndResponse.CallRequest; | ||
| import hng_java_boilerplate.twilio.RequestAndResponse.CallResponse; | ||
| import hng_java_boilerplate.twilio.Service.TwilioCallService; | ||
| import lombok.RequiredArgsConstructor; | ||
| 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; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api") | ||
| @RequiredArgsConstructor | ||
| public class TwillioCallController { | ||
|
|
||
| private final TwilioCallService twilioCallService; | ||
|
|
||
| @PostMapping("/call") | ||
| public CallResponse makecall(@RequestBody CallRequest callRequest) { | ||
| if (callRequest == null || callRequest.getToNumber() == null || callRequest.getFromNumber() == null) { | ||
| throw new BadRequestException("Invalid request: Phone number is required"); | ||
| } | ||
|
|
||
| CallResponse response = twilioCallService.makeCall(callRequest); | ||
|
|
||
| if (response == null) { | ||
| throw new NotFoundException("Twilio service error: Service not found/available"); | ||
| } | ||
| return response; | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/hng_java_boilerplate/twilio/Repository/TwilioCallRepo.java
This file contains hidden or 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,10 @@ | ||
| package hng_java_boilerplate.twilio.Repository; | ||
|
|
||
| import hng_java_boilerplate.twilio.CallLogs.Entity; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| public interface TwilioCallRepo extends JpaRepository<Entity,Long> { | ||
|
|
||
| } |
31 changes: 31 additions & 0 deletions
31
src/main/java/hng_java_boilerplate/twilio/RequestAndResponse/CallRequest.java
This file contains hidden or 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,31 @@ | ||
| package hng_java_boilerplate.twilio.RequestAndResponse; | ||
|
|
||
| public class CallRequest { | ||
| private String toNumber; | ||
| private String fromNumber; | ||
| private String messageUrl; | ||
|
|
||
| public String getFromNumber() { | ||
| return fromNumber; | ||
| } | ||
|
|
||
| public void setFromNumber(String fromNumber) { | ||
| this.fromNumber = fromNumber; | ||
| } | ||
|
|
||
| public String getToNumber() { | ||
| return toNumber; | ||
| } | ||
|
|
||
| public void setToNumber(String toNumber) { | ||
| this.toNumber = toNumber; | ||
| } | ||
|
|
||
| public String getMessageUrl() { | ||
| return messageUrl; | ||
| } | ||
|
|
||
| public void setMessageUrl(String messageUrl) { | ||
| this.messageUrl = messageUrl; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a exception directory that manages exceptions, all you have to do is just throw the specified exception with a message..