-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/org/sopt/confeti/api/artist/controller/ArtistController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.sopt.confeti.api.artist.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.confeti.api.artist.dto.response.SearchArtistResponse; | ||
import org.sopt.confeti.api.artist.facade.ArtistFacade; | ||
import org.sopt.confeti.api.artist.facade.dto.response.SearchArtistDTO; | ||
import org.sopt.confeti.api.user.facade.UserInfoFacade; | ||
import org.sopt.confeti.global.common.BaseResponse; | ||
import org.sopt.confeti.global.message.SuccessMessage; | ||
import org.sopt.confeti.global.util.ApiResponseUtil; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/artists") | ||
public class ArtistController { | ||
|
||
private final ArtistFacade artistFacade; | ||
|
||
@GetMapping | ||
public ResponseEntity<BaseResponse<?>> search( | ||
@RequestHeader(name = "Authorization", required = false) Long userId, | ||
@RequestParam(name = "search") String keyword | ||
) { | ||
SearchArtistDTO artist = artistFacade.searchByKeyword(userId, keyword); | ||
return ApiResponseUtil.success(SuccessMessage.SUCCESS, SearchArtistResponse.from(artist)); | ||
} | ||
} |
Empty file.
13 changes: 13 additions & 0 deletions
13
src/main/java/org/sopt/confeti/api/artist/dto/response/SearchArtistResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.sopt.confeti.api.artist.dto.response; | ||
|
||
import org.sopt.confeti.api.artist.facade.dto.response.SearchArtistDTO; | ||
|
||
public record SearchArtistResponse( | ||
SearchArtistSingleResponse artist | ||
) { | ||
public static SearchArtistResponse from(final SearchArtistDTO searchArtistDTO) { | ||
return new SearchArtistResponse( | ||
SearchArtistSingleResponse.from(searchArtistDTO) | ||
); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/sopt/confeti/api/artist/dto/response/SearchArtistSingleResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.sopt.confeti.api.artist.dto.response; | ||
|
||
import java.time.LocalDate; | ||
import org.sopt.confeti.api.artist.facade.dto.response.SearchArtistDTO; | ||
|
||
public record SearchArtistSingleResponse( | ||
String artistId, | ||
String name, | ||
String profileUrl, | ||
LocalDate latestReleaseAt, | ||
boolean isFavorite, | ||
boolean isMultipleArtists | ||
) { | ||
public static SearchArtistSingleResponse from(final SearchArtistDTO searchArtistDTO) { | ||
return new SearchArtistSingleResponse( | ||
searchArtistDTO.artistId(), | ||
searchArtistDTO.name(), | ||
searchArtistDTO.profileUrl(), | ||
searchArtistDTO.latestReleaseAt(), | ||
searchArtistDTO.isFavorite(), | ||
searchArtistDTO.isMultipleArtists() | ||
); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/sopt/confeti/api/artist/facade/ArtistFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.sopt.confeti.api.artist.facade; | ||
|
||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.confeti.annotation.Facade; | ||
import org.sopt.confeti.api.artist.facade.dto.response.SearchArtistDTO; | ||
import org.sopt.confeti.domain.artistfavorite.application.ArtistFavoriteService; | ||
import org.sopt.confeti.global.util.artistsearcher.ConfetiArtist; | ||
import org.sopt.confeti.global.util.artistsearcher.SpotifyAPIHandler; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Facade | ||
@RequiredArgsConstructor | ||
public class ArtistFacade { | ||
|
||
private final ArtistFavoriteService artistFavoriteService; | ||
private final SpotifyAPIHandler spotifyAPIHandler; | ||
|
||
@Transactional(readOnly = true) | ||
public SearchArtistDTO searchByKeyword(final Long userId, final String keyword) { | ||
Optional<ConfetiArtist> confetiArtist = spotifyAPIHandler.findArtistsByKeyword(keyword); | ||
|
||
boolean isFavorite = false; | ||
|
||
if (confetiArtist.isPresent() && userId != null) { | ||
isFavorite = artistFavoriteService.isFavorite(userId, confetiArtist.get().getArtistId()); | ||
} | ||
|
||
return SearchArtistDTO.from( | ||
confetiArtist.orElse(ConfetiArtist.empty()), | ||
isFavorite | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/org/sopt/confeti/api/artist/facade/dto/response/SearchArtistDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.sopt.confeti.api.artist.facade.dto.response; | ||
|
||
import java.time.LocalDate; | ||
import org.sopt.confeti.global.util.artistsearcher.ConfetiArtist; | ||
|
||
public record SearchArtistDTO( | ||
String artistId, | ||
String name, | ||
String profileUrl, | ||
LocalDate latestReleaseAt, | ||
boolean isFavorite, | ||
boolean isMultipleArtists | ||
) { | ||
private static final boolean fixedIsMultipleArtists = false; | ||
|
||
public static SearchArtistDTO from(final ConfetiArtist confetiArtist, final boolean isFavorite) { | ||
return new SearchArtistDTO( | ||
confetiArtist.getArtistId(), | ||
confetiArtist.getName(), | ||
confetiArtist.getProfileUrl(), | ||
confetiArtist.getLatestReleaseAt(), | ||
isFavorite, | ||
fixedIsMultipleArtists | ||
); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters