Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 아티스트 구독 및 생성 구현 수정 #178

Merged
merged 16 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.example.error;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.ErrorHandler;

@Component
@Slf4j
public class RedisSubErrorHandler implements ErrorHandler {

@Override
public void handleError(Throwable t) {
log.error("Redis Sub error occurred - message : {}, cause : {} ", t.getMessage(), t.getCause());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

public final class ValidatorUser {

public static UUID getUserId(AuthenticatedInfo user) {
if (user == null) {
public static UUID getUserId(AuthenticatedInfo info) {
if (info == null) {
return null;
}

return user.userId();
return info.userId();
}

}
4 changes: 4 additions & 0 deletions app/api/show-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ dependencies {
implementation project(":app:domain:user-domain")
implementation project(':app:api:common-api')

//redis sub
implementation 'org.springframework.data:spring-data-redis'
implementation 'io.lettuce:lettuce-core:6.3.0.RELEASE'

//testFixtures
testImplementation(testFixtures(project(":app:domain:show-domain")))
testImplementation(testFixtures(project(":app:domain:user-domain")))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
package com.example.artist.controller;

import com.example.artist.controller.dto.request.ArtistCreateApiForm;
import com.example.artist.controller.dto.request.ArtistUpdateApiForm;
import com.example.artist.controller.dto.response.ArtistDetailApiFormResponse;
import com.example.artist.service.ArtistAdminService;
import com.example.artist.service.dto.response.ArtistDetailServiceResponse;
import com.example.genre.controller.dto.response.GenreNameApiResponse;
import com.example.genre.service.GenreAdminService;
import jakarta.validation.Valid;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
Expand All @@ -26,22 +15,7 @@
public class ArtistAdminController {

private final ArtistAdminService artistAdminService;
private final GenreAdminService genreAdminService;

@GetMapping
public String createArtist(Model model) {
List<GenreNameApiResponse> genres = genreAdminService.findAllGenres().stream()
.map(GenreNameApiResponse::new)
.toList();
model.addAttribute("genres", genres);
return "artist_create_form";
}

@PostMapping
public String createArtist(@Valid ArtistCreateApiForm artistCreateApiForm) {
artistAdminService.save(artistCreateApiForm.toArtistCreateServiceRequest());
return "redirect:/admin/artists/list";
}

@GetMapping("/list")
public String findAllArtist(Model model) {
Expand All @@ -53,36 +27,4 @@ public String findAllArtist(Model model) {
model.addAttribute("artists", artistDetailApiFormResponses);
return "artist_list_form";
}

@GetMapping("/{id}")
public String findArtist(@PathVariable("id") UUID id, Model model) {
List<GenreNameApiResponse> genres = genreAdminService.findAllGenres().stream()
.map(GenreNameApiResponse::new)
.toList();
model.addAttribute("genres", genres);

ArtistDetailServiceResponse artistDetailServiceResponse = artistAdminService.findArtistById(
id);
ArtistDetailApiFormResponse artistDetailApiFormResponse = new ArtistDetailApiFormResponse(
artistDetailServiceResponse);
model.addAttribute("artist", artistDetailApiFormResponse);

return "artist_form";
}

@PutMapping("/{id}")
public String updateArtist(
@PathVariable("id") UUID id,
@Valid ArtistUpdateApiForm artistUpdateApiForm
) {
artistAdminService.updateArtist(id, artistUpdateApiForm.toArtistUpdateServiceRequest());
return "redirect:/admin/artists/list";
}

@DeleteMapping("/{id}")
public String deleteGenre(@PathVariable("id") UUID id) {
artistAdminService.deleteArtist(id);
return "redirect:/admin/artists/list";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import com.example.artist.controller.dto.param.ArtistSearchPaginationApiParam;
import com.example.artist.controller.dto.param.ArtistSubscriptionPaginationApiParam;
import com.example.artist.controller.dto.param.ArtistUnsubscriptionPaginationApiParam;
import com.example.artist.controller.dto.request.ArtistFilterTotalCountApiRequest;
import com.example.artist.controller.dto.request.ArtistSearchPaginationApiRequest;
import com.example.artist.controller.dto.request.ArtistSubscriptionApiRequest;
import com.example.artist.controller.dto.request.ArtistSubscriptionPaginationApiRequest;
import com.example.artist.controller.dto.request.ArtistUnsubscriptionApiRequest;
import com.example.artist.controller.dto.request.ArtistUnsubscriptionPaginationApiRequest;
import com.example.artist.controller.dto.response.ArtistFilterTotalCountApiResponse;
import com.example.artist.controller.dto.response.ArtistSubscriptionApiResponse;
import com.example.artist.controller.dto.response.ArtistUnsubscriptionApiResponse;
import com.example.artist.controller.dto.response.NumberOfSubscribedArtistApiResponse;
Expand Down Expand Up @@ -47,8 +45,9 @@ public ResponseEntity<PaginationApiResponse<ArtistUnsubscriptionPaginationApiPar
@AuthenticationPrincipal AuthenticatedInfo info,
@Valid @ParameterObject ArtistUnsubscriptionPaginationApiRequest request
) {
UUID userId = ValidatorUser.getUserId(info);
var response = artistService.findArtistUnsubscriptions(
request.toServiceRequest(info.userId())
request.toServiceRequest(userId)
);
var data = response.data().stream()
.map(ArtistUnsubscriptionPaginationApiParam::from)
Expand Down Expand Up @@ -151,19 +150,4 @@ public ResponseEntity<PaginationApiResponse<ArtistSearchPaginationApiParam>> sea
.build()
);
}

@GetMapping("/filter-total-count")
@Operation(summary = "필터링한 데이터의 총 개수 가져오기")
public ResponseEntity<ArtistFilterTotalCountApiResponse> filterTotalCount(
@AuthenticationPrincipal AuthenticatedInfo info,
@Valid @RequestBody ArtistFilterTotalCountApiRequest request
) {
var response = artistService.filterArtistTotalCount(
request.toServiceRequest(info.userId())
);

return ResponseEntity.ok(
ArtistFilterTotalCountApiResponse.from(response.totalCount())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ public record ArtistSubscriptionPaginationApiParam(
UUID id,
@Schema(description = "아티스트 이미지 URL")
String imageURL,
@Schema(description = "아티스트 한글 이름")
String koreanName,
@Schema(description = "아티스트 영문 이름")
String englishName
@Schema(description = "아티스트 이름")
String name
) {

public static ArtistSubscriptionPaginationApiParam from(ArtistSubscriptionPaginationServiceParam param) {
return new ArtistSubscriptionPaginationApiParam(
param.artistId(),
param.artistImageUrl(),
param.artistKoreanName(),
param.artistEnglishName()
param.id(),
param.image(),
param.name()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ public record ArtistUnsubscriptionPaginationApiParam(
UUID id,
@Schema(description = "아티스트 이미지 URL")
String imageURL,
@Schema(description = "아티스트 한글 이름")
String koreanName,
@Schema(description = "아티스트 영문 이름")
String englishName
@Schema(description = "아티스트 이름")
String name
) {

public static ArtistUnsubscriptionPaginationApiParam from(
ArtistUnsubscriptionPaginationServiceParam param
) {
return new ArtistUnsubscriptionPaginationApiParam(
param.artistId(),
param.artistImageUrl(),
param.artistKoreanName(),
param.artistEnglishName()
param.id(),
param.image(),
param.name()
);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import java.util.UUID;

public record ArtistSubscriptionApiRequest(
@Schema(description = "아티스트 ID 목록")
@NotEmpty(message = "아티스트 ID는 최소 하나 이상 입력해야합니다.")
List<UUID> artistIds
@Schema(description = "spotify 아티스트 ID 목록")
@NotEmpty(message = "spotify 아티스트 ID는 최소 하나 이상 입력해야합니다.")
List<String> spotifyArtistIds
) {

public ArtistSubscriptionServiceRequest toServiceRequest(UUID userId) {
return new ArtistSubscriptionServiceRequest(artistIds, userId);
return new ArtistSubscriptionServiceRequest(spotifyArtistIds, userId);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.artist.controller.dto.request;

import com.example.artist.service.dto.request.ArtistSubscriptionPaginationServiceRequest;
import com.example.artist.vo.ArtistSortApiType;
import com.example.vo.SubscriptionStatusApiType;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -11,12 +10,6 @@
@Schema
public record ArtistSubscriptionPaginationApiRequest(

@Parameter(
description = "정렬 기준, default: ENGLISH_NAME_ASC",
schema = @Schema(implementation = ArtistSortApiType.class)
)
ArtistSortApiType sort,

@Parameter(description = "이전 페이지네이션 마지막 데이터의 cursorId / 최초 조회라면 null")
UUID cursorId,

Expand All @@ -26,11 +19,9 @@ public record ArtistSubscriptionPaginationApiRequest(
) {

public ArtistSubscriptionPaginationApiRequest(
ArtistSortApiType sort,
UUID cursorId,
Integer size
) {
this.sort = sort == null ? ArtistSortApiType.ENGLISH_NAME_ASC : sort;
this.cursorId = cursorId;
this.size = size == null ? 30 : size;
}
Expand All @@ -39,7 +30,6 @@ public ArtistSubscriptionPaginationServiceRequest toServiceRequest(UUID userId)
return ArtistSubscriptionPaginationServiceRequest.builder()
.subscriptionStatusApiType(SubscriptionStatusApiType.SUBSCRIBED)
.size(size)
.sortStandard(sort)
.cursor(cursorId)
.userId(userId)
.build();
Expand Down
Loading
Loading