Changeset 27660af


Ignore:
Timestamp:
02/09/26 21:35:51 (5 months ago)
Author:
Filip Gavrilovski <filipgavrilovski28@…>
Branches:
main
Children:
890e036
Parents:
8dd3e22
Message:

update form for publishing music - replace mock search with api calls

Files:
2 added
6 edited

Legend:

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

    r8dd3e22 r27660af  
    11package com.ukim.finki.develop.finkwave.controller;
    22
    3 import com.ukim.finki.develop.finkwave.model.MusicalEntity;
    4 import com.ukim.finki.develop.finkwave.model.User;
    5 import com.ukim.finki.develop.finkwave.model.dto.MusicalEntityDto;
    63import com.ukim.finki.develop.finkwave.model.dto.SongDto;
     4import com.ukim.finki.develop.finkwave.model.dto.UserSearchResultDto;
    75import com.ukim.finki.develop.finkwave.repository.SongRepository;
    86import com.ukim.finki.develop.finkwave.repository.UserRepository;
    97import lombok.AllArgsConstructor;
    10 import lombok.Getter;
    118import org.springframework.http.HttpEntity;
    129import org.springframework.http.ResponseEntity;
     
    2825
    2926    @GetMapping("/search/u/{searchTerm}")
    30     public HttpEntity<List<User>> searchUsersTest(@PathVariable String searchTerm){
    31         return ResponseEntity.ok(userRepository.searchListeners(searchTerm));
     27    public HttpEntity<List<UserSearchResultDto>> searchUsersTest(@PathVariable String searchTerm){
     28        return ResponseEntity.ok(userRepository.searchListeners(searchTerm, 10));
    3229    }
    3330    @GetMapping("/search/a/{searchTerm}")
    34     public HttpEntity<List<User>> searchArtistsTest(@PathVariable String searchTerm){
    35         return ResponseEntity.ok(userRepository.searchArtists(searchTerm));
     31    public HttpEntity<List<UserSearchResultDto>> searchArtistsTest(@PathVariable String searchTerm){
     32        return ResponseEntity.ok(userRepository.searchArtists(searchTerm, 10));
    3633    }
    3734}
  • finkwave/src/main/java/com/ukim/finki/develop/finkwave/controller/UserController.java

    r8dd3e22 r27660af  
    22
    33import com.ukim.finki.develop.finkwave.model.User;
     4import com.ukim.finki.develop.finkwave.model.dto.UserSearchResultDto;
    45import com.ukim.finki.develop.finkwave.model.enums.UserType;
    56import com.ukim.finki.develop.finkwave.service.UserService;
     
    2425
    2526    @GetMapping("/search")
    26     public HttpEntity<List<User>> searchArtists(
     27    public HttpEntity<List<UserSearchResultDto>> searchArtists(
    2728            @RequestParam(name = "type") UserType userType,
    28             @RequestParam(name = "q") String searchTerm){
    29         return ResponseEntity.ok(usersService.search(userType, searchTerm));
     29            @RequestParam(name = "q") String searchTerm,
     30            @RequestParam(name = "limit", defaultValue = "10") Integer limit)
     31            {
     32        return ResponseEntity.ok(usersService.search(userType, searchTerm, limit));
    3033    }
    3134}
  • finkwave/src/main/java/com/ukim/finki/develop/finkwave/repository/UserRepository.java

    r8dd3e22 r27660af  
    22
    33import com.ukim.finki.develop.finkwave.model.User;
     4import com.ukim.finki.develop.finkwave.model.dto.UserSearchResultDto;
    45import org.springframework.data.jpa.repository.JpaRepository;
    56import org.springframework.data.jpa.repository.Query;
     7import org.springframework.data.repository.query.Param;
    68import org.springframework.stereotype.Repository;
    79
     
    1416
    1517
    16     @Query("""
    17         SELECT u from User u
    18         WHERE (u.fullName ILIKE '%' || :searchTerm || '%' or u.username ILIKE '%' || :searchTerm || '%')
     18    @Query(value = """
     19        SELECT u.full_name, u.username, u.profile_photo from users u
     20        WHERE (u.full_name ILIKE '%' || :searchTerm || '%' or u.username ILIKE '%' || :searchTerm || '%')
    1921            and u.listener = true and u.artist = false
    20         """)
    21     List<User> searchListeners(String searchTerm);
     22        LIMIT :limit
     23        """, nativeQuery = true)
     24    List<UserSearchResultDto> searchListeners(@Param("searchTerm") String searchTerm, @Param("limit") Integer limit);
    2225
    23     @Query("""
    24         SELECT u from User u
    25         WHERE (u.fullName ILIKE '%' || :searchTerm || '%' or u.username ILIKE '%' || :searchTerm || '%')
    26             and u.artist = true
    27         """)
    28     List<User> searchArtists(String searchTerm);
     26    @Query(value = """
     27        SELECT u.full_name, u.username, u.profile_photo from users u
     28        WHERE (u.full_name ILIKE '%' || :searchTerm || '%' or u.username ILIKE '%' || :searchTerm || '%') and u.artist = true
     29        LIMIT :limit
     30        """, nativeQuery = true)
     31    List<UserSearchResultDto> searchArtists(@Param("searchTerm") String searchTerm, @Param("limit") Integer limit);
     32
     33
    2934}
  • finkwave/src/main/java/com/ukim/finki/develop/finkwave/service/UserService.java

    r8dd3e22 r27660af  
    22
    33import com.ukim.finki.develop.finkwave.model.User;
     4import com.ukim.finki.develop.finkwave.model.dto.UserSearchResultDto;
    45import com.ukim.finki.develop.finkwave.model.enums.UserType;
    56import com.ukim.finki.develop.finkwave.repository.UserRepository;
     
    1819    }
    1920
    20     // todo: add dto-s
    21 
    22     public List<User> search(UserType userType, String searchTerm){
    23 
     21    public List<UserSearchResultDto> search(UserType userType, String searchTerm, int limit){
    2422        return switch (userType) {
    25             case ARTIST -> usersRepository.searchArtists(searchTerm);
    26             case LISTENER -> usersRepository.searchListeners(searchTerm);
     23            case ARTIST -> usersRepository.searchArtists(searchTerm, limit);
     24            case LISTENER -> usersRepository.searchListeners(searchTerm, limit);
    2725            case null -> throw new IllegalArgumentException("Invalid userType");
    2826        };
  • frontend/src/pages/PublishSong.tsx

    r8dd3e22 r27660af  
    22import { Link, useNavigate } from "react-router-dom";
    33import { toast } from "react-toastify";
     4import axiosInstance from "../api/axiosInstance";
    45import { useAuth } from "../context/authContext";
    5 
    6 interface Contributor {
    7         username: string;
    8         fullName: string;
    9         role: string;
    10 }
    11 
    12 interface ArtistSearchResult {
    13         username: string;
    14         fullName: string;
    15         profilePhoto?: string;
    16 }
    17 
    18 interface SongEntry {
    19         title: string;
    20         link: string;
    21         contributors: Contributor[];
    22 }
    23 
    24 const ROLE_OPTIONS = [
    25         { value: "FEATURED", label: "Featured" },
    26         { value: "PRODUCER", label: "Producer" },
    27         { value: "SONGWRITER", label: "Songwriter" },
    28         { value: "COMPOSER", label: "Composer" },
    29         { value: "MIXER", label: "Mixer" },
    30         { value: "ENGINEER", label: "Engineer" },
    31 ];
    32 
    33 const GENRE_OPTIONS = [
    34         "Pop",
    35         "Rock",
    36         "Hip-Hop",
    37         "R&B",
    38         "Electronic",
    39         "Jazz",
    40         "Classical",
    41         "Country",
    42         "Folk",
    43         "Latin",
    44         "Metal",
    45         "Punk",
    46         "Indie",
    47         "Alternative",
    48         "Blues",
    49         "Soul",
    50         "Reggae",
    51         "Funk",
    52         "Disco",
    53         "House",
    54         "Techno",
    55         "Ambient",
    56         "Other",
    57 ];
    58 
    59 // Mock artist search results
    60 const MOCK_ARTISTS: ArtistSearchResult[] = [
    61         { username: "john_doe", fullName: "John Doe" },
    62         { username: "jane_smith", fullName: "Jane Smith" },
    63         { username: "mike_producer", fullName: "Mike the Producer" },
    64         { username: "sarah_vocals", fullName: "Sarah Vocals" },
    65         { username: "alex_beats", fullName: "Alex Beats" },
    66 ];
     6import { GENRE_OPTIONS, ROLE_OPTIONS } from "../utils/consts";
     7import type {
     8        ArtistSearchResult,
     9        Contributor,
     10        SongEntry,
     11} from "../utils/types";
    6712
    6813const MAX_CONTRIBUTORS = 5;
     
    14590                setIsSearching(true);
    14691                try {
    147                         // TODO: replace with api call
    148                         // const response = await axiosInstance.get(`/users/search?type=ARTIST&q=${encodeURIComponent(query)}`);
    149                         // setSearchResults(response.data);
    150 
    151                         // Mock search - filter by name
    152                         await new Promise((resolve) => setTimeout(resolve, 200));
    153                         const filtered = MOCK_ARTISTS.filter(
    154                                 (artist) =>
     92                        const response = await axiosInstance.get(
     93                                `/users/search?type=ARTIST&q=${encodeURIComponent(query)}&limit=5`,
     94                        );
     95
     96                        const filtered = response.data.filter(
     97                                (artist: ArtistSearchResult) =>
    15598                                        artist.fullName.toLowerCase().includes(query.toLowerCase()) ||
    15699                                        artist.username.toLowerCase().includes(query.toLowerCase()),
     
    276219
    277220                        // TODO: replace with api call
    278                         await new Promise((resolve) => setTimeout(resolve, 200));
    279                         const filtered = MOCK_ARTISTS.filter(
    280                                 (artist) =>
     221                        const response = await axiosInstance.get(
     222                                `/users/search?type=ARTIST&q=${encodeURIComponent(query)}&limit=5`,
     223                        );
     224                        const filtered = response.data.filter(
     225                                (artist: ArtistSearchResult) =>
    281226                                        artist.fullName.toLowerCase().includes(query.toLowerCase()) ||
    282227                                        artist.username.toLowerCase().includes(query.toLowerCase()),
  • frontend/src/utils/types.ts

    r8dd3e22 r27660af  
    117117        releaseDate: string;
    118118}
     119
     120export interface Contributor {
     121        username: string;
     122        fullName: string;
     123        role: string;
     124}
     125
     126export interface ArtistSearchResult {
     127        username: string;
     128        fullName: string;
     129        profilePhoto?: string;
     130}
     131
     132export interface SongEntry {
     133        title: string;
     134        link: string;
     135        contributors: Contributor[];
     136}
Note: See TracChangeset for help on using the changeset viewer.