diff --git a/Back-End/app/downloaded_song.mp3 b/Back-End/app/downloaded_song.mp3 new file mode 100644 index 0000000..392bf9f Binary files /dev/null and b/Back-End/app/downloaded_song.mp3 differ diff --git a/Back-End/app/src/main/java/com/web/app/client/DeezerClient.java b/Back-End/app/src/main/java/com/web/app/client/DeezerClient.java new file mode 100644 index 0000000..4b576bf --- /dev/null +++ b/Back-End/app/src/main/java/com/web/app/client/DeezerClient.java @@ -0,0 +1,26 @@ +package com.web.app.client; + +import com.web.app.dto.search.SearchDeezerResponse; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class DeezerClient { + + private final String url = "https://api.deezer.com/"; + + public SearchDeezerResponse searchDeezerAPI(String artist, String track, String album) { + RestTemplate template = new RestTemplate(); + return template.getForObject(url + "search?q=" +// con comillas o que las agreguen al hacer la peticion +// creo que al hacer las peticiones son un buen indicador de + + "artist:" + artist + + " track:" + track + + " album:" + album + +// + "artist:" + "\"" + artist + "\"" +// + " track:" + "\"" + track + "\"" +// + " album:" + "\"" + album + "\"" + , SearchDeezerResponse.class); + } +} diff --git a/Back-End/app/src/main/java/com/web/app/controllers/SearchController.java b/Back-End/app/src/main/java/com/web/app/controllers/SearchController.java new file mode 100644 index 0000000..c118253 --- /dev/null +++ b/Back-End/app/src/main/java/com/web/app/controllers/SearchController.java @@ -0,0 +1,41 @@ +package com.web.app.controllers; + +import com.web.app.dto.ExtendedBaseResponse; +import com.web.app.dto.search.SearchDeezerResponse; +import com.web.app.service.impl.SearchServiceImpl; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "Buscador", description = "Buscar canciones, album, artist tanto desde la API de Deezar como la nuestra") +@RestController +@RequestMapping("/search") +@RequiredArgsConstructor +public class SearchController { + public final SearchServiceImpl searchService; + // Implementación de los métodos para buscar canciones, albums y artistas + @Operation(summary = "Buscador", + description = "Al Buscar canciones, album, artist, hacerlo entre comillas" + ) + @ApiResponses( value = { + @ApiResponse( + responseCode = "200", + description = "Busqueda por API Deezer Exitoso.", + content = { + @Content(mediaType = "application/json", + schema = @Schema(implementation = ExtendedBaseResponse.class)) + }) + }) + @GetMapping + public ExtendedBaseResponse findTracksByAlbumId( + @RequestParam(required = false) String artist, + @RequestParam(required = false) String track, + @RequestParam(required = false) String album) { + return searchService.searchDeezaer(artist,track,album); + } +} diff --git a/Back-End/app/src/main/java/com/web/app/dto/search/AlbumResponseBySearch.java b/Back-End/app/src/main/java/com/web/app/dto/search/AlbumResponseBySearch.java new file mode 100644 index 0000000..646ef4a --- /dev/null +++ b/Back-End/app/src/main/java/com/web/app/dto/search/AlbumResponseBySearch.java @@ -0,0 +1,15 @@ +package com.web.app.dto.search; + +public record AlbumResponseBySearch( + long id, + String title, + String cover, + String cover_small, + String cover_medium, + String cover_big, + String cover_xl, + String md5_image, + String tracklist +// String type +) { +} diff --git a/Back-End/app/src/main/java/com/web/app/dto/search/ArtistResponseBySearch.java b/Back-End/app/src/main/java/com/web/app/dto/search/ArtistResponseBySearch.java new file mode 100644 index 0000000..177cc15 --- /dev/null +++ b/Back-End/app/src/main/java/com/web/app/dto/search/ArtistResponseBySearch.java @@ -0,0 +1,15 @@ +package com.web.app.dto.search; + +public record ArtistResponseBySearch( + String id, + String name, +// String link, + String picture, + String picture_small, + String picture_medium, + String picture_big, + String picture_xl, + String tracklist +// String type +) { +} diff --git a/Back-End/app/src/main/java/com/web/app/dto/search/DataResponseBySearch.java b/Back-End/app/src/main/java/com/web/app/dto/search/DataResponseBySearch.java new file mode 100644 index 0000000..d097c3e --- /dev/null +++ b/Back-End/app/src/main/java/com/web/app/dto/search/DataResponseBySearch.java @@ -0,0 +1,22 @@ +package com.web.app.dto.search; + +import lombok.AllArgsConstructor; + +public record DataResponseBySearch( + long id, +// boolean readable, + String title, + String title_short, +// String title_version, +// String link, + int duration, +// int rank, +// boolean explicit_lyrics, +// int explicit_content_lyrics, +// int explicit_content_cover, + String preview, + String md5_image, + ArtistResponseBySearch artist, + AlbumResponseBySearch album +) { +} diff --git a/Back-End/app/src/main/java/com/web/app/dto/search/SearchDeezerResponse.java b/Back-End/app/src/main/java/com/web/app/dto/search/SearchDeezerResponse.java new file mode 100644 index 0000000..6c3c213 --- /dev/null +++ b/Back-End/app/src/main/java/com/web/app/dto/search/SearchDeezerResponse.java @@ -0,0 +1,10 @@ +package com.web.app.dto.search; + +import java.util.ArrayList; + +public record SearchDeezerResponse( + ArrayList data, + int total, + String next +) { +} diff --git a/Back-End/app/src/main/java/com/web/app/security/SecurityConfiguration.java b/Back-End/app/src/main/java/com/web/app/security/SecurityConfiguration.java index df2cf9b..ac41a6a 100644 --- a/Back-End/app/src/main/java/com/web/app/security/SecurityConfiguration.java +++ b/Back-End/app/src/main/java/com/web/app/security/SecurityConfiguration.java @@ -27,6 +27,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .authorizeHttpRequests( auth -> auth .requestMatchers("/auth/**") .permitAll() + .requestMatchers("/search/**") + .permitAll() .requestMatchers("/api-docs/**", "api-docs.yaml") .permitAll() .requestMatchers("/swagger-ui-custom.html", "/swagger-ui/**", "/swagger-ui/") diff --git a/Back-End/app/src/main/java/com/web/app/service/impl/SearchServiceImpl.java b/Back-End/app/src/main/java/com/web/app/service/impl/SearchServiceImpl.java new file mode 100644 index 0000000..8179f3c --- /dev/null +++ b/Back-End/app/src/main/java/com/web/app/service/impl/SearchServiceImpl.java @@ -0,0 +1,18 @@ +package com.web.app.service.impl; + +import com.web.app.client.DeezerClient; +import com.web.app.dto.BaseResponse; +import com.web.app.dto.ExtendedBaseResponse; +import com.web.app.dto.search.SearchDeezerResponse; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +@AllArgsConstructor +@Service +public class SearchServiceImpl { + public final DeezerClient deezerClient; + public ExtendedBaseResponse searchDeezaer(String artist, String track, String album) { + SearchDeezerResponse response=deezerClient.searchDeezerAPI(artist, track, album); + return ExtendedBaseResponse.of(BaseResponse.ok("Busqueda por Deezer Exitoso"), response); + } +}