Skip to content

Commit

Permalink
add anime release schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
Fauzanmhr committed Aug 23, 2024
1 parent 6820f77 commit d1526c2
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ web_modules/
.env.test.local
.env.production.local
.env.local
.env

# parcel-bundler cache (https://parceljs.org/)
.cache
Expand Down
6 changes: 6 additions & 0 deletions controllers/scheduleController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { fetchSchedule } from '../services/scheduleService.js';

export const getSchedule = async (req, res) => {
const schedule = await fetchSchedule();
res.render('schedule', { schedule });
};
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import animeRoutes from './routes/animeRoutes.js';
import genreRoutes from './routes/genreRoutes.js';
import episodeRoutes from './routes/episodeRoutes.js';
import shortlinkRoutes from './routes/shortlinkRoutes.js';
import scheduleRoutes from './routes/scheduleRoutes.js';
import {fetchAllAnimeData} from './services/animeService.js';

const __filename = fileURLToPath(import.meta.url);
Expand Down Expand Up @@ -43,6 +44,7 @@ app.use('/', animeRoutes);
app.use('/', genreRoutes);
app.use('/', episodeRoutes);
app.use('/', shortlinkRoutes);
app.use('/', scheduleRoutes);

// Start the server
app.listen(port, () => {
Expand Down
8 changes: 8 additions & 0 deletions routes/scheduleRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import express from 'express';
import { getSchedule } from '../controllers/scheduleController.js';

const router = express.Router();

router.get('/schedule', getSchedule);

export default router;
11 changes: 11 additions & 0 deletions services/scheduleService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ky from 'ky';

export const fetchSchedule = async () => {
try {
const response = await ky.get(`${process.env.API_URL}/otakudesu/jadwal`).json();
return response.data;
} catch (error) {
console.error('Error fetching schedule data:', error);
return [];
}
};
5 changes: 4 additions & 1 deletion views/partials/navbar.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
<a class="nav-link" href="/all-anime">All Anime</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/Genres">Genres</a>
<a class="nav-link" href="/genres">Genres</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/schedule">Schedule</a>
</li>
</ul>
</div>
Expand Down
22 changes: 22 additions & 0 deletions views/schedule.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%- include('partials/header', { title: 'Anime Schedule - ZANNIME' }) %>
<div class="container">
<h1 class="mt-4">Anime Release Schedule</h1>
<% schedule.forEach(day => { %>
<div class="day-schedule card mt-3">
<div class="card-body">
<h2 class="card-title"><%= day.hari %></h2>
<p class="card-text">
<% day.anime.forEach((anime, index) => { %>
<a href="/anime/<%= anime.slug %>" class="badge bg-dark me-1 text-decoration-none"><%= anime.judul %></a><% if (index < day.anime.length - 1) { %>, <% } %>
<% }) %>
</p>
</div>
</div>
<% }) %>
</div>
<br>
<%- include('partials/footer') %>
<!-- Bootstrap JS -->
<script src="/js/bootstrap.bundle.min.js"></script>
</body>
</html>

0 comments on commit d1526c2

Please sign in to comment.