adding admin tools

This commit is contained in:
2026-02-06 13:20:21 +00:00
parent f546e8ae23
commit dbdab24e17
4 changed files with 34 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ package handlers
import ( import (
"context" "context"
"net/http" "net/http"
"time"
"adam-french.co.uk/backend/services" "adam-french.co.uk/backend/services"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -54,6 +55,10 @@ func (store *Store) ListeningTo(ctx *gin.Context) {
func (store *Store) RecentlyPlayed(ctx *gin.Context) { func (store *Store) RecentlyPlayed(ctx *gin.Context) {
opts := spotify.RecentlyPlayedOptions{Limit: 3} opts := spotify.RecentlyPlayedOptions{Limit: 3}
if store.RecentSongsFresh() {
ctx.JSON(200, *store.RecentSongs)
}
played, err := store.SpotifyClient.PlayerRecentlyPlayedOpt(ctx, &opts) played, err := store.SpotifyClient.PlayerRecentlyPlayedOpt(ctx, &opts)
if err != nil { if err != nil {
ctx.JSON(500, gin.H{"error": err.Error()}) ctx.JSON(500, gin.H{"error": err.Error()})
@@ -62,3 +67,15 @@ func (store *Store) RecentlyPlayed(ctx *gin.Context) {
ctx.JSON(200, played) ctx.JSON(200, played)
} }
func (s *Store) RecentSongsFresh() bool {
if s.RecentSongs == nil {
return false
}
if len(*s.RecentSongs) == 0 {
return false
}
return time.Since(s.RecentSongsFetchedAt) < time.Minute
}

View File

@@ -1,6 +1,8 @@
package handlers package handlers
import ( import (
"time"
"adam-french.co.uk/backend/services" "adam-french.co.uk/backend/services"
"github.com/zmb3/spotify/v2" "github.com/zmb3/spotify/v2"
spotifyauth "github.com/zmb3/spotify/v2/auth" spotifyauth "github.com/zmb3/spotify/v2/auth"
@@ -13,4 +15,7 @@ type Store struct {
SpotifyClient *spotify.Client SpotifyClient *spotify.Client
Auth *services.Auth Auth *services.Auth
Notes *services.Notes Notes *services.Notes
RecentSongs *[]spotify.RecentlyPlayedItem
RecentSongsFetchedAt time.Time
} }

View File

@@ -1,10 +1,8 @@
<script setup> <script setup>
import Button from "@/components/input/Button.vue"; import Button from "@/components/input/Button.vue";
import { ref, onMounted, computed } from "vue"; import { ref } from "vue";
import axios from "axios"; import axios from "axios";
import { useAuthStore } from "@/stores/auth";
const auth = useAuthStore();
const title = ref(""); const title = ref("");
const content = ref(""); const content = ref("");
@@ -24,7 +22,7 @@ async function post() {
</script> </script>
<template> <template>
<div class="flex flex-col" v-if="auth.loggedIn"> <div class="flex flex-col">
<h1>Create Post</h1> <h1>Create Post</h1>
<input type="text" v-model="title" placeholder="Title" /> <input type="text" v-model="title" placeholder="Title" />
<textarea <textarea

View File

@@ -1,7 +1,14 @@
<script setup> <script setup>
import { ref } from "vue";
import { useAuthStore } from "@/stores/auth";
import Login from "@/components/admin/Login.vue"; import Login from "@/components/admin/Login.vue";
import CreateUser from "@/components/admin/CreateUser.vue"; import CreateUser from "@/components/admin/CreateUser.vue";
import CreatePost from "@/components/admin/CreatePost.vue"; import CreatePost from "@/components/admin/CreatePost.vue";
import CreateFavorite from "@/components/admin/CreateFavorite.vue";
import CreateActivity from "@/components/admin/CreateActivity.vue";
const auth = useAuthStore();
</script> </script>
<template> <template>
@@ -11,7 +18,9 @@ import CreatePost from "@/components/admin/CreatePost.vue";
<!-- <!--
<CreateUser class="bdr-2 bg-bg_primary" /> <CreateUser class="bdr-2 bg-bg_primary" />
--> -->
<CreatePost class="bdr-2 bg-bg_primary" /> <CreatePost class="bdr-2 bg-bg_primary" v-if="auth.loggedIn" />
<CreateFavorite class="bdr-2 bg-bg_primary" v-if="auth.loggedIn" />
<CreateActivity class="bdr-2 bg-bg_primary" v-if="auth.loggedIn" />
</div> </div>
</main> </main>
</template> </template>