-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#5): integrate frontend and backend for driver registration, add…
… backend fixes, and enable Docker hot-reload
- Loading branch information
1 parent
cdc5a84
commit a58e1a7
Showing
18 changed files
with
156 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
/node_modules | ||
node_modules | ||
dist | ||
.git |
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 |
---|---|---|
|
@@ -11,4 +11,4 @@ COPY . . | |
|
||
EXPOSE 3000 | ||
|
||
CMD yarn install && yarn build && node dist/start.js | ||
CMD yarn install && yarn dev |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
import Koa from 'koa'; | ||
import bodyParser from 'koa-bodyparser'; | ||
import sequelize from './config/database'; | ||
import driverRoutes from './routes/driver-routes'; | ||
import driverRoutes from './routes'; | ||
|
||
const app = new Koa(); | ||
|
||
sequelize.sync().then(() => console.log("Connected to PostgreSQL")); | ||
// sequelize.sync().then(() => console.log("Connected to PostgreSQL")); | ||
|
||
app.use(bodyParser()); | ||
|
||
// Temporary test route | ||
app.use(async (ctx, next) => { | ||
if (ctx.path === '/') { | ||
ctx.body = 'Server is up!'; | ||
} else { | ||
console.log('Request received:', ctx.method, ctx.path); | ||
await next(); | ||
} | ||
}); | ||
|
||
app.use(driverRoutes.routes()).use(driverRoutes.allowedMethods()); | ||
|
||
export default app; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import Router from "@koa/router"; | ||
import { registerDriver } from "../controllers/driver-controller"; | ||
import Router from '@koa/router'; | ||
import { registerDriver } from '../controllers/driver-controller'; | ||
|
||
const router = new Router(); | ||
router.post("/drivers/register", registerDriver); | ||
|
||
router.post('/register', registerDriver); | ||
|
||
export default router; |
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,8 @@ | ||
import Router from '@koa/router'; | ||
import driverRoutes from './driver-routes'; | ||
|
||
const router = new Router(); | ||
|
||
router.use('/drivers', driverRoutes.routes(), driverRoutes.allowedMethods()); | ||
|
||
export default router; |
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 |
---|---|---|
@@ -1,4 +1,14 @@ | ||
import app from './app'; | ||
|
||
const PORT = process.env.PORT || 3000; | ||
// Temporary test route | ||
app.use(async (ctx, next) => { | ||
if (ctx.path === '/') { | ||
ctx.body = 'Server is up!'; | ||
} else { | ||
console.log('Request received:', ctx.method, ctx.path); | ||
await next(); | ||
} | ||
}); | ||
|
||
app.listen(PORT, () => console.log(`Server running on http://localhost:${PORT}`)); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
EXPO_PUBLIC_MORRO_API_BASE_URL=http://192.168.68.106:3000 |
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,53 @@ | ||
import { ApiResponse, DriverData } from './models'; | ||
|
||
const API_BASE_URL = process.env.EXPO_PUBLIC_MORRO_API_BASE_URL; | ||
|
||
export const registerDriver = async (driverData: DriverData): Promise<ApiResponse> => { | ||
try { | ||
console.log('TEST', API_BASE_URL) | ||
const response = await fetch(`${API_BASE_URL}/drivers/register`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(driverData), | ||
}); | ||
console.log('TEST2', await response.text()) | ||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
throw new Error(errorData.error || 'Registration failed'); | ||
} | ||
|
||
return response.json(); | ||
} catch (error) { | ||
if (error instanceof TypeError && error.message === 'Network request failed') { | ||
console.log(error) | ||
throw new Error('Network error: Please check your internet connection and try again.'); | ||
} | ||
throw error; | ||
} | ||
}; | ||
|
||
export const loginDriver = async (driverData: DriverData): Promise<ApiResponse> => { | ||
try { | ||
const response = await fetch(`${API_BASE_URL}/drivers/login`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(driverData), | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
throw new Error(errorData.error || 'Login failed'); | ||
} | ||
|
||
return response.json(); | ||
} catch (error) { | ||
if (error instanceof TypeError && error.message === 'Network request failed') { | ||
throw new Error('Network error: Please check your internet connection and try again.'); | ||
} | ||
throw error; | ||
} | ||
}; |
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,9 @@ | ||
export interface DriverData { | ||
email: string; | ||
password: string; | ||
} | ||
|
||
export interface ApiResponse { | ||
message: string; | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useMutation, UseMutationResult } from "@tanstack/react-query"; | ||
import { registerDriver } from "../../api/index"; | ||
import { ApiResponse, DriverData } from "../../api/models"; | ||
|
||
export const useRegisterDriver = (): UseMutationResult< | ||
ApiResponse, | ||
Error, | ||
DriverData | ||
> => { | ||
return useMutation<ApiResponse, Error, DriverData>({ | ||
mutationFn: registerDriver, | ||
}); | ||
}; |
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