Skip to content

Commit f24a2da

Browse files
committed
cleaned up main to create new branch
1 parent 762833d commit f24a2da

File tree

2 files changed

+0
-111
lines changed

2 files changed

+0
-111
lines changed

routes/roverRouter.ts

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +0,0 @@
1-
import express from "express";
2-
import axios from "axios";
3-
const roverRouter = express.Router();
4-
5-
import dotenv from "dotenv";
6-
dotenv.config({ path: './.env' });
7-
const apiKey = process.env.NASA_API_KEY;
8-
9-
enum Cameras {
10-
FHAZ = "FHAZ",
11-
RHAZ = "RHAZ",
12-
MAST = "MAST",
13-
CHEMCAM = "CHEMCAM",
14-
MAHLI = "MAHLI = 5",
15-
MARDI = "MARDI",
16-
NAVCAM = "NAVCAM",
17-
PANCAM = "PANCAM",
18-
MINITES = "MINITES"
19-
}
20-
21-
enum Rovers {
22-
CURIOSITY = "Curiosity",
23-
SPIRIT = "Spirit",
24-
OPPORTUNITY = "Opportunity",
25-
PERSEVERANCE = "Perseverance"
26-
}
27-
28-
interface Camera {
29-
id?: number;
30-
name: string;
31-
rover_id?: number;
32-
full_name: string;
33-
}
34-
35-
interface Rover {
36-
id: number;
37-
name: string;
38-
landing_date: string;
39-
launch_date: string;
40-
status: string;
41-
max_sol: number;
42-
max_date: string;
43-
total_photos: number;
44-
cameras: Camera[];
45-
}
46-
47-
interface Photo {
48-
id: number;
49-
sol: number;
50-
camera: Camera;
51-
img_src: string;
52-
earth_date: string;
53-
rover: Rover;
54-
}
55-
56-
roverRouter.get('/', (req: any, res: any) => {
57-
axios.get(`https://api.nasa.gov/mars-photos/api/v1/rovers?api_key=${apiKey}`)
58-
.then(response => {
59-
res.send(response.data);
60-
})
61-
.catch(error => {
62-
console.error(error);
63-
res.render("error");
64-
})
65-
});
66-
67-
roverRouter.get('/:rovername/photos/:camera?', (req: any, res: any) => {
68-
69-
const { rovername, camera } = req.params;
70-
71-
console.log(`rover: ${rovername}, camera: ${camera}`);
72-
73-
const nasaUrl = camera ? `https://api.nasa.gov/mars-photos/api/v1/rovers/${rovername}/photos?sol=1000&camera=${camera}&api_key=${apiKey}`
74-
: `https://api.nasa.gov/mars-photos/api/v1/rovers/${rovername}/photos?sol=1000&api_key=${apiKey}`;
75-
76-
axios.get(nasaUrl)
77-
.then(response => {
78-
const photos: Photo[] = response.data.photos;
79-
const urls: string[] = [];
80-
photos.forEach(photo => {
81-
urls.push(photo.img_src);
82-
});
83-
res.send(urls);
84-
})
85-
.catch(error => {
86-
console.error(error);
87-
res.render("error");
88-
})
89-
});
90-
91-
export default roverRouter;

src/server.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +0,0 @@
1-
import express from "express";
2-
import roverRouter from "../routes/roverRouter";
3-
4-
const app = express();
5-
const port = 3000;
6-
7-
app.get("/", (req: any, res: any) => {
8-
res.send(`Hello space traveller!
9-
What are you exploring today?
10-
A) /rover = all info
11-
B) /rover/photos = photos from that rover`)
12-
});
13-
14-
app.use("/rovers", roverRouter);
15-
16-
app.listen(port, () => {
17-
console.log(`Test backend is running on port ${port}`);
18-
});
19-
20-
export default app;

0 commit comments

Comments
 (0)