Working API to spring NO JPA link yet

This commit is contained in:
MathewFrancis 2025-04-04 13:16:20 +05:30
parent 211c39089e
commit 9f036e3d0e
23 changed files with 342 additions and 19 deletions

View File

@ -0,0 +1,39 @@
{
"info": {
"_postman_id": "721d5504-301f-488d-a25b-5e78769eac5a",
"name": "CezenPBX_API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "29498098"
},
"item": [
{
"name": "create a new endpoint",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"id\": \"1001\",\n \"transport\": \"transport-udp\",\n \"aors\": \"1001\",\n \"auth\": \"1001\",\n \"context\": \"from-internal\",\n \"disallow\": \"all\",\n \"allow\": \"ulaw\",\n \"directMedia\": \"no\",\n \"connectedLineMethod\": \"invite\",\n \"callerid\": \"User <1001>\",\n \"dtmfMode\": \"rfc4733\",\n \"mohsuggest\": \"default\",\n \"mailboxes\": \"1001@default\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8081/cezen/add_user",
"protocol": "http",
"host": [
"localhost"
],
"port": "8081",
"path": [
"cezen",
"add_user"
]
}
},
"response": []
}
]
}

View File

@ -43,10 +43,10 @@ services:
volumes: volumes:
- ./springCezenPBX:/app # Mount your Spring Boot project - ./springCezenPBX:/app # Mount your Spring Boot project
- maven_repo:/root/.m2 # Store Maven dependencies - maven_repo:/root/.m2 # Store Maven dependencies
# environment: environment:
# SPRING_DATASOURCE_URL: jdbc:mariadb://host.docker.internal:3308/asterisk_db # Use host.docker.internal SPRING_DATASOURCE_URL: jdbc:mariadb://localhost:3308/asterisk_db # Use host.docker.internal
# SPRING_DATASOURCE_USERNAME: asterisk_user # ${DB_USER} SPRING_DATASOURCE_USERNAME: ${DB_USER}
# SPRING_DATASOURCE_PASSWORD: 12345 # ${DB_PASS} SPRING_DATASOURCE_PASSWORD: ${DB_PASS}
network_mode: "host" # Run in host mode network_mode: "host" # Run in host mode
volumes: volumes:

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -30,10 +30,10 @@
<java.version>21</java.version> <java.version>21</java.version>
</properties> </properties>
<dependencies> <dependencies>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework.boot</groupId>--> <groupId>org.springframework.boot</groupId>
<!-- <artifactId>spring-boot-starter-data-jpa</artifactId>--> <artifactId>spring-boot-starter-data-jpa</artifactId>
<!-- </dependency>--> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
@ -45,17 +45,11 @@
<scope>runtime</scope> <scope>runtime</scope>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- <dependency>--> <dependency>
<!-- <groupId>org.springframework.boot</groupId>--> <groupId>org.mariadb.jdbc</groupId>
<!-- <artifactId>spring-boot-docker-compose</artifactId>--> <artifactId>mariadb-java-client</artifactId>
<!-- <scope>runtime</scope>--> <scope>runtime</scope>
<!-- <optional>true</optional>--> </dependency>
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.mariadb.jdbc</groupId>-->
<!-- <artifactId>mariadb-java-client</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>

View File

@ -11,3 +11,4 @@ public class CezenPbxApplication {
} }
} }

View File

@ -0,0 +1,28 @@
package com.example.cezenPBX.DAO;
import com.example.cezenPBX.entity.PsEndPoints;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@Repository
public class BasicAsteriskOpsDAO implements CezenPbxOpsDAO {
@Autowired
private EntityManager entityManager;
// takes the required data from the service class and persists the entity to the database
// returns true if operation was carried out without an exception
@Override
public boolean addNewEndPoint(PsEndPoints psEndPoints) {
try{
this.entityManager.persist(psEndPoints);
}catch (Exception e){
return false;
}
return true;
}
}

View File

@ -0,0 +1,8 @@
package com.example.cezenPBX.DAO;
import com.example.cezenPBX.entity.PsEndPoints;
public interface CezenPbxOpsDAO {
boolean addNewEndPoint(PsEndPoints psEndPoints);
}

View File

@ -0,0 +1,7 @@
package com.example.cezenPBX.DTO;
public record PsEndPointsDTO
(String id, String transport, String aors, String auth, String context,
String disallow, String allow, String directMedia, String connectedLineMethod,
String callerid, String dtmfMode, String mohsuggest, String mailboxes) {
}

View File

@ -0,0 +1,27 @@
package com.example.cezenPBX.controller;
import com.example.cezenPBX.DTO.PsEndPointsDTO;
import com.example.cezenPBX.service.BasicPbxServiceInterface;
import org.springframework.beans.factory.annotation.Autowired;
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("/cezen")
public class CezenPbxController {
@Autowired
private BasicPbxServiceInterface basicPbxServiceInterface;
@PostMapping("/add_user")
// this method will accept json input fields, process them using jackson then pass them to the service
public boolean createNewEndPointController(@RequestBody PsEndPointsDTO psEndPointsRecordDTO){
System.out.println(psEndPointsRecordDTO);
return false;
}
}

View File

@ -0,0 +1,170 @@
package com.example.cezenPBX.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Table(name = "ps_endpoints")
public class PsEndPoints {
@Id
@Column(name = "id")
String id;
@Column(name = "transport")
String transport;
@Column(name = "aors")
String aors;
@Column(name = "auth")
String auth;
@Column(name = "context")
String context;
@Column(name = "disallow")
String disallow;
@Column(name = "allow")
String allow;
@Column(name = "direct_media")
String directMedia;
@Column(name = "connected_line_method")
String connectedLineMethod;
@Column(name = "callerid")
String callerid;
@Column(name = "dtmf_mode")
String dtmfMode;
@Column(name = "mohsuggest")
String mohsuggest;
@Column(name = "mailboxes")
String mailboxes;
public PsEndPoints(String id, String transport, String aors, String auth, String context,
String disallow, String allow, String directMedia, String connectedLineMethod,
String callerid, String dtmfMode, String mohsuggest, String mailboxes) {
this.id = id;
this.transport = transport;
this.aors = aors;
this.auth = auth;
this.context = context;
this.disallow = disallow;
this.allow = allow;
this.directMedia = directMedia;
this.connectedLineMethod = connectedLineMethod;
this.callerid = callerid;
this.dtmfMode = dtmfMode;
this.mohsuggest = mohsuggest;
this.mailboxes = mailboxes;
}
public PsEndPoints() {
}
public String getId() {
return id;
}
public String getTransport() {
return transport;
}
public void setTransport(String transport) {
this.transport = transport;
}
public String getAors() {
return aors;
}
public void setAors(String aors) {
this.aors = aors;
}
public String getAuth() {
return auth;
}
public void setAuth(String auth) {
this.auth = auth;
}
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
public String getDisallow() {
return disallow;
}
public void setDisallow(String disallow) {
this.disallow = disallow;
}
public String getAllow() {
return allow;
}
public void setAllow(String allow) {
this.allow = allow;
}
public String getDirectMedia() {
return directMedia;
}
public void setDirectMedia(String directMedia) {
this.directMedia = directMedia;
}
public String getConnectedLineMethod() {
return connectedLineMethod;
}
public void setConnectedLineMethod(String connectedLineMethod) {
this.connectedLineMethod = connectedLineMethod;
}
public String getCallerid() {
return callerid;
}
public void setCallerid(String callerid) {
this.callerid = callerid;
}
public String getDtmfMode() {
return dtmfMode;
}
public void setDtmfMode(String dtmfMode) {
this.dtmfMode = dtmfMode;
}
public String getMohsuggest() {
return mohsuggest;
}
public void setMohsuggest(String mohsuggest) {
this.mohsuggest = mohsuggest;
}
public String getMailboxes() {
return mailboxes;
}
public void setMailboxes(String mailboxes) {
this.mailboxes = mailboxes;
}
}

View File

@ -0,0 +1,40 @@
package com.example.cezenPBX.service;
import com.example.cezenPBX.DAO.CezenPbxOpsDAO;
import com.example.cezenPBX.entity.PsEndPoints;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class BasicPbxService implements BasicPbxServiceInterface {
@Autowired
private CezenPbxOpsDAO cezenPbxOpsDAO;
// the service method will create an instance of PsEndPoints entity for persistence
@Override
public boolean createANewEndpointService(String id, String transport, String aors, String auth,
String context, String disallow, String allow, String directMedia,
String connectedLineMethod, String callerid, String dtmfMode,
String mohsuggest, String mailboxes) {
// create the persistence object
PsEndPoints psEndPoints = new PsEndPoints(
id,
transport,
aors,
auth,
context,
disallow,
allow,
directMedia,
connectedLineMethod,
callerid,
dtmfMode,
mohsuggest,
mailboxes
);
return cezenPbxOpsDAO.addNewEndPoint(psEndPoints);
}
}

View File

@ -0,0 +1,9 @@
package com.example.cezenPBX.service;
public interface BasicPbxServiceInterface {
public boolean createANewEndpointService(String id, String transport, String aors, String auth,
String context, String disallow, String allow, String directMedia,
String connectedLineMethod, String callerid, String dtmfMode,
String mohsuggest, String mailboxes);
}