Skip to content

Commit

Permalink
Merge pull request #17 from No-Country-simulation/ale-back
Browse files Browse the repository at this point in the history
buscador desde la API de deezer
  • Loading branch information
alelex10 authored Nov 27, 2024
2 parents 685a02f + c41eee9 commit 6cea4cf
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 0 deletions.
Binary file added Back-End/app/downloaded_song.mp3
Binary file not shown.
26 changes: 26 additions & 0 deletions Back-End/app/src/main/java/com/web/app/client/DeezerClient.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<SearchDeezerResponse> findTracksByAlbumId(
@RequestParam(required = false) String artist,
@RequestParam(required = false) String track,
@RequestParam(required = false) String album) {
return searchService.searchDeezaer(artist,track,album);
}
}
Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.web.app.dto.search;

import java.util.ArrayList;

public record SearchDeezerResponse(
ArrayList<DataResponseBySearch> data,
int total,
String next
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SearchDeezerResponse> searchDeezaer(String artist, String track, String album) {
SearchDeezerResponse response=deezerClient.searchDeezerAPI(artist, track, album);
return ExtendedBaseResponse.of(BaseResponse.ok("Busqueda por Deezer Exitoso"), response);
}
}

0 comments on commit 6cea4cf

Please sign in to comment.