Refactor data handlers + misc fixes
This refactors the data handlers into a more standard/understood model-like architecture, to prepare for a new, more robust config system. It also fixes a problem with creating new Notes and uploading new Photos via the web interface (related to #58). Finally, it speeds up docker builds by sending in less files, which aren't necessary or will be built anyway. This is all in preparation to allow building #13 more robustly.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Handlers, PageProps } from 'fresh/server.ts';
|
||||
|
||||
import { Dashboard, FreshContextState } from '/lib/types.ts';
|
||||
import { createDashboard, getDashboardByUserId } from '/lib/data/dashboard.ts';
|
||||
import { DashboardModel } from '/lib/models/dashboard.ts';
|
||||
import Notes from '/islands/dashboard/Notes.tsx';
|
||||
import Links from '/islands/dashboard/Links.tsx';
|
||||
|
||||
@@ -15,10 +15,10 @@ export const handler: Handlers<Data, FreshContextState> = {
|
||||
return new Response('Redirect', { status: 303, headers: { 'Location': `/login` } });
|
||||
}
|
||||
|
||||
let userDashboard = await getDashboardByUserId(context.state.user.id);
|
||||
let userDashboard = await DashboardModel.getByUserId(context.state.user.id);
|
||||
|
||||
if (!userDashboard) {
|
||||
userDashboard = await createDashboard(context.state.user.id);
|
||||
userDashboard = await DashboardModel.create(context.state.user.id);
|
||||
}
|
||||
|
||||
return await context.render({ userDashboard });
|
||||
|
||||
Reference in New Issue
Block a user