Skip to content

Commit

Permalink
Merge pull request #99 from franfreezy/main
Browse files Browse the repository at this point in the history
fix frontend fetches
  • Loading branch information
franfreezy authored Dec 4, 2024
2 parents cd68cfc + cc8cde9 commit c763a6a
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 21 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/azure-static-web-apps-lively-mud-042177e03.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

name: Azure Static Web Apps CI/CD

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
types: [opened, synchronize, reopened]
branches:
- main

Expand All @@ -25,25 +24,25 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install Dependencies
run: |
cd frontend
npm install
- name: Build Application
run: |
cd frontend
npm run build
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_LIVELY_MUD_042177E03 }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: "upload"
app_location: "./frontend"
output_location: 'dist'

output_location: 'dist'

close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
Expand Down
4 changes: 2 additions & 2 deletions AgritechSat/AgritechSat/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
DEBUG = os.environ.get('DEBUG')
ALLOWED_HOSTS = ['*']
CSRF_TRUSTED_ORIGINS = [
'https://agroxsat.onrender.com/'
'https://lively-mud-042177e03.4.azurestaticapps.net/'
]
INSTALLED_APPS = [
'django.contrib.admin',
Expand Down Expand Up @@ -131,7 +131,7 @@
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOWED_ORIGINS = [
'https://agroxsatsite.onrender.com',
'https://lively-mud-042177e03.4.azurestaticapps.net/',
'http://localhost:5173',

]
Expand Down
24 changes: 23 additions & 1 deletion AgritechSat/BackendApi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ def post(self, request, *args, **kwargs):
if None in [soil_moisture, temperature, humidity, smoke_level, soil_ph]:
return Response({"error": "Missing required fields"}, status=status.HTTP_400_BAD_REQUEST)


payload = Payload.objects.create(
soil_moisture=soil_moisture,
temperature=temperature,
Expand All @@ -322,6 +321,29 @@ def post(self, request, *args, **kwargs):
except Exception as e:
return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

def get(self, request, *args, **kwargs):
try:

payloads = Payload.objects.all()

payload_data = [
{
"payload_id": payload.id,
"soil_moisture": payload.soil_moisture,
"temperature": payload.temperature,
"humidity": payload.humidity,
"smoke_level": payload.smoke_level,
"soil_ph": payload.soil_ph,
"created_at": payload.created_at.isoformat() if hasattr(payload, 'created_at') else None,
}
for payload in payloads
]

return Response(payload_data, status=status.HTTP_200_OK)

except Exception as e:
return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

def parse_request_data(self, request):
if isinstance(request.data, dict) and '_content' not in request.data:
return request.data
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/@Dashboard/components/googlemaps.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const MapboxComponent = () => {
useEffect(() => {
const fetchCoordinates = async () => {
try {
const response = await axios.get("https://agroxsat.onrender.com/backendapi/");
const response = await axios.get("https://agrixcubesat.azurewebsites.net/backendapi/");
const { latitude, longitude } = response.data;
setCoordinates({ latitude, longitude });
} catch (error) {
Expand All @@ -27,7 +27,7 @@ const MapboxComponent = () => {

const fetchAllCoordinates = async () => {
try {
const response = await axios.get("https://agroxsat.onrender.com/backendapi/satLocation/");
const response = await axios.get("https://agrixcubesat.azurewebsites.net/backendapi/satLocation/");
const { coordinates } = response.data;
setAllCoordinates(coordinates); // Set all coordinates
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/@Dashboard/pages/commands/console.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const Commands = () => {

// API call to send command
try {
const response = await fetch("https://agroxsat.onrender.com/backendapi/command/", {
const response = await fetch("https://agrixcubesat.azurewebsites.net/backendapi/command/", {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const BatteryGauge = () => {
const fetchBatteryLevel = async () => {
try {
const response = await fetch(
"https://agroxsat.onrender.com/backendapi/telemetry/"
"https://agrixcubesat.azurewebsites.net/backendapi/telemetry/"
);
if (!response.ok) {
throw new Error("Failed to fetch data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CurrentGauge = () => {
const fetchCurrentValue = async () => {
try {
const response = await fetch(
"https://agroxsat.onrender.com/backendapi/telemetry/"
"https://agrixcubesat.azurewebsites.net/backendapi/telemetry/"
);
if (!response.ok) {
throw new Error("Failed to fetch data");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const EPSTemperatureGauge = () => {

const fetchTemperature = async () => {
try {
const response = await fetch("https://agroxsat.onrender.com/backendapi/telemetry/");
const response = await fetch("https://agrixcubesat.azurewebsites.net/backendapi/telemetry/");
if (!response.ok) {
throw new Error("Failed to fetch EPS temperature data");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const IMUDisplay = () => {

const fetchIMUData = async () => {
try {
const response = await fetch("https://agroxsat.onrender.com/backendapi/telemetry/");
const response = await fetch("https://agrixcubesat.azurewebsites.net/backendapi/telemetry/");
if (!response.ok) {
throw new Error("Failed to fetch IMU data");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const PressureGauge = () => {

const fetchPressure = async () => {
try {
const response = await fetch("https://agroxsat.onrender.com/backendapi/telemetry/");
const response = await fetch("https://agrixcubesat.azurewebsites.net/backendapi/telemetry/");
if (!response.ok) {
throw new Error("Failed to fetch pressure data");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Temperature = () => {

const fetchTemperature = async () => {
try {
const response = await fetch("https://agroxsat.onrender.com/backendapi/telemetry/");
const response = await fetch("https://agrixcubesat.azurewebsites.net/backendapi/telemetry/");
if (!response.ok) {
throw new Error("Failed to fetch temperature data");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const VoltageGauge = () => {
const fetchVoltageLevel = async () => {
try {
const response = await fetch(
"https://agroxsat.onrender.com/backendapi/telemetry/"
"https://agrixcubesat.azurewebsites.net/backendapi/telemetry/"
);
if (!response.ok) {
throw new Error("Failed to fetch data");
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/@auth/login/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Login = () => {
try {
console.log("Sending Request");
const response = await fetch(
"https://agroxsat.onrender.com/backend/login/",
"https://agrixcubesat.azurewebsites.net/backend/login/",
{
method: "POST",
headers: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/@auth/register/register.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Register() {

try {
const response = await fetch(
"https://agroxsat.onrender.com/backend/register/",
"https://agrixcubesat.azurewebsites.net/backend/register/",
{
method: "POST",
headers: {
Expand Down

0 comments on commit c763a6a

Please sign in to comment.