Changeset 5938bc9


Ignore:
Timestamp:
02/07/26 14:59:57 (5 months ago)
Author:
Filip Gavrilovski <filipgavrilovski28@…>
Branches:
main
Children:
ebdd3d4
Parents:
591919d
Message:

fix bug that prevented unauthenticated users to see top songs

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • finkwave/src/main/java/com/ukim/finki/develop/finkwave/controller/SongController.java

    r591919d r5938bc9  
    2020@AllArgsConstructor
    2121public class SongController {
    22     private final AuthService authService;
    2322    private final SongService songService;
    2423
    2524    @GetMapping("/top")
    2625    public HttpEntity<List<MusicalEntityDto>> getSongs(){
    27         Long userId = authService.getCurrentUserID();
    28         return ResponseEntity.ok(songService.getTopSongs(userId));
     26        return ResponseEntity.ok(songService.getTopSongs());
    2927    }
    3028
  • finkwave/src/main/java/com/ukim/finki/develop/finkwave/service/SongService.java

    r591919d r5938bc9  
    1515    private final AuthService authService;
    1616
    17     public List<MusicalEntityDto> getTopSongs(Long userId){
     17    public List<MusicalEntityDto> getTopSongs(){
     18        Long userId = null;
     19        try {
     20            userId = authService.getCurrentUserID();
     21        } catch (Exception ignored) {}
    1822        return songRepository.findTopByListens(userId);
    1923    }
  • frontend/src/App.tsx

    r591919d r5938bc9  
    44import "react-toastify/dist/ReactToastify.css";
    55import Sidebar from "./components/Sidebar";
     6import { useAuth } from "./context/authContext";
    67import AllUsers from "./pages/AllUsers";
    78import LandingPage from "./pages/LandingPage";
     
    1213import UserDetail from "./pages/UserDetail";
    1314
    14 const Layout = () => {
    15         const [isSidebarOpen, setIsSidebarOpen] = useState(true);
     15const MainLayout = () => {
     16        const { user } = useAuth();
     17        const [isSidebarOpen, setIsSidebarOpen] = useState(!!user);
    1618
    1719        return (
     
    4345                </div>
    4446        );
     47};
     48
     49const Layout = () => {
     50        const { isAuthLoading } = useAuth();
     51
     52        if (isAuthLoading) {
     53                return (
     54                        <div className="flex h-screen items-center justify-center bg-[#121212]">
     55                                <div className="w-12 h-12 border-4 border-white/10 border-t-[#1db954] rounded-full animate-spin"></div>
     56                        </div>
     57                );
     58        }
     59
     60        return <MainLayout />;
    4561};
    4662
  • frontend/src/components/Sidebar.tsx

    r591919d r5938bc9  
    11import { useEffect, useState } from "react";
    22import axiosInstance from "../api/axiosInstance";
     3import { useAuth } from "../context/authContext";
    34import type { BasicPlaylist, BasicSong, SidebarProps } from "../utils/types";
    45
    56const Sidebar = ({ isOpen, onClose }: SidebarProps) => {
     7        const { user } = useAuth();
    68        const [recentlyListened, setRecentlyListened] = useState<BasicSong[]>([]);
    79        const [playlists, setPlaylists] = useState<BasicPlaylist[]>([]);
     
    2527                        }
    2628                };
    27                 fetchData();
    28         }, []);
     29                if (user) {
     30                        fetchData();
     31                } else {
     32                        setRecentlyListened([]);
     33                        setPlaylists([]);
     34                }
     35        }, [user]);
    2936        return (
    3037                <div
Note: See TracChangeset for help on using the changeset viewer.