Skip to content

Commit

Permalink
feat : 알림 서버 API 연동 (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Nov 11, 2024
1 parent 91e52d4 commit dc5d9aa
Show file tree
Hide file tree
Showing 24 changed files with 316 additions and 103 deletions.
1 change: 1 addition & 0 deletions .github/workflows/showpot-dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
spring.datasource.password: ${{ secrets.APPLICATION_DATASOURCE_PASSWORD }}
spotify.client-id: ${{ secrets.SPOTIFY_CLIENT_ID }}
spotify.client-secret: ${{ secrets.SPOTIFY_CLIENT_SECRET }}
alarm.api-url: ${{ secrets.ALARM_SERVER_API_URL }}

- name: Build with Gradle Wrapper
run: ./gradlew clean build -Dspring.profiles.active=dev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private RequestMatcher getMatcherForUserAndAdmin() {
antMatcher(HttpMethod.POST, "/api/v1/artists/unsubscribe"),
antMatcher(HttpMethod.GET, "/api/v1/artists/subscriptions"),
antMatcher(HttpMethod.GET, "/api/v1/users/notifications"),
antMatcher(HttpMethod.GET, "/api/v1/users/notifications/unread")
antMatcher(HttpMethod.GET, "/api/v1/users/notifications/exist")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@

@Builder
public record ShowRelationArtistAndGenreServiceMessage(
UUID showId,
List<UUID> artistIds,
List<UUID> genreIds
) {

public static ShowRelationArtistAndGenreServiceMessage of(List<UUID> artistIds, List<UUID> genreIds) {
public static ShowRelationArtistAndGenreServiceMessage of(
UUID showId,
List<UUID> artistIds,
List<UUID> genreIds
) {
return ShowRelationArtistAndGenreServiceMessage.builder()
.showId(showId)
.artistIds(artistIds)
.genreIds(genreIds)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.example.dto.show.response.ShowInfoDomainResponse;
import org.example.entity.show.Show;
import org.example.usecase.ArtistUseCase;
import org.example.usecase.GenreUseCase;
import org.example.usecase.ShowAdminUseCase;
Expand All @@ -29,13 +30,14 @@ public class ShowAdminService {
public void save(ShowCreateServiceRequest showCreateServiceRequest) {
String imageURL = fileUploadComponent.uploadFile("show", showCreateServiceRequest.post());

showAdminUseCase.save(
Show show = showAdminUseCase.save(
showCreateServiceRequest.toDomainRequest(imageURL)
);

messagePublisher.publishShow(
"registerShow",
ShowRelationArtistAndGenreServiceMessage.of(
show.getId(),
showCreateServiceRequest.artistIds(),
showCreateServiceRequest.genreIds()
)
Expand Down Expand Up @@ -83,6 +85,7 @@ public void updateShow(UUID id, ShowUpdateServiceRequest showUpdateServiceReques
messagePublisher.publishShow(
"updateShow",
ShowRelationArtistAndGenreServiceMessage.of(
id,
artistIdsToPublish,
genreIdsToPublish
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willDoNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -19,6 +18,7 @@
import java.util.UUID;
import org.example.dto.show.request.ShowUpdateDomainRequest;
import org.example.fixture.domain.ShowArtistFixture;
import org.example.fixture.domain.ShowFixture;
import org.example.fixture.domain.ShowGenreFixture;
import org.example.usecase.ArtistUseCase;
import org.example.usecase.GenreUseCase;
Expand Down Expand Up @@ -48,12 +48,16 @@ class ShowAdminServiceTest {
void showCreateWithUploadedImageUrl() {
//given
ShowCreateServiceRequest showCreateServiceRequest = ShowRequestDtoFixture.showCreateServiceRequest();
String url = "test_imageUrl";
given(
fileUploadComponent.uploadFile(
"artist",
"show",
showCreateServiceRequest.post()
)
).willReturn("test_imageUrl");
given(
showAdminUseCase.save(any())
).willReturn(ShowFixture.deafultShow());

//when
showAdminService.save(showCreateServiceRequest);
Expand All @@ -67,10 +71,9 @@ void showCreateWithUploadedImageUrl() {
void showCreateWithPublishRelationArtistIdsAndGenreIds() {
//given
var showCreateServiceRequest = ShowRequestDtoFixture.showCreateServiceRequest();
var showCreationDomainRequest = showCreateServiceRequest.toDomainRequest(
"test_imageUrl"
);
willDoNothing().given(showAdminUseCase).save(showCreationDomainRequest);
given(
showAdminUseCase.save(any())
).willReturn(ShowFixture.deafultShow());

//when
showAdminService.save(showCreateServiceRequest);
Expand All @@ -90,7 +93,7 @@ void showUpdateWithUploadedImageUrl() {
UUID showId = UUID.randomUUID();
given(
fileUploadComponent.uploadFile(
"artist",
"show",
showUpdateServiceRequest.post()
)
).willReturn("test_imageUrl");
Expand All @@ -99,7 +102,8 @@ void showUpdateWithUploadedImageUrl() {
showAdminService.updateShow(showId, showUpdateServiceRequest);

//then
verify(showAdminUseCase, times(1)).updateShow(eq(showId), any(ShowUpdateDomainRequest.class));
verify(showAdminUseCase, times(1)).updateShow(eq(showId),
any(ShowUpdateDomainRequest.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.example.config;

import org.example.property.AlarmServerProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@Import(UserDomainConfig.class)
@EnableConfigurationProperties(AlarmServerProperty.class)
@ComponentScan(basePackages = "org.example")
public class UserApiConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.time.LocalDateTime;
import java.util.List;
import jakarta.validation.constraints.Max;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.example.controller.dto.param.SimpleNotificationApiParam;
import org.example.controller.dto.response.HasUnreadNotificationApiResponse;
import org.example.controller.dto.response.NotificationsApiResponse;
import org.example.controller.dto.response.NotificationExistApiResponse;
import org.example.dto.response.PaginationApiResponse;
import org.example.security.dto.AuthenticatedInfo;
import org.example.util.DateTimeUtil;
import org.example.service.UserAlarmService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "유저 알림")
Expand All @@ -22,50 +23,39 @@
@RequiredArgsConstructor
public class UserAlarmController {

@GetMapping("/notifications/unread")
@Operation(summary = "안 읽은 알림 존재 여부")
public ResponseEntity<HasUnreadNotificationApiResponse> hasUnreadNotifications(
private final UserAlarmService userAlarmService;

@GetMapping("/notifications/exist")
@Operation(summary = "알림 미열람 존재 여부")
public ResponseEntity<NotificationExistApiResponse> hasUnreadNotifications(
@AuthenticationPrincipal AuthenticatedInfo info
) {
var response = userAlarmService.getNotificationExist(info.userId());

return ResponseEntity.ok(
HasUnreadNotificationApiResponse.builder()
.hasUnreadNotification(true)
.build()
NotificationExistApiResponse.from(response)
);
}

@GetMapping("/notifications")
@Operation(summary = "알림 목록")
public ResponseEntity<NotificationsApiResponse> getNotifications(
public ResponseEntity<PaginationApiResponse<SimpleNotificationApiParam>> getNotifications(
@RequestParam(value = "cursorId", required = false) UUID cursorId,
@RequestParam(value = "size") @Max(value = 30, message = "조회하는 데이터의 최대 개수는 30입니다.")
Integer size,
@AuthenticationPrincipal AuthenticatedInfo info

) {
var response = userAlarmService.findNotifications(info.userId(), cursorId, size);
var data = response.data().stream()
.map(SimpleNotificationApiParam::from)
.toList();

return ResponseEntity.ok(
NotificationsApiResponse.builder()
.notifications(
List.of(
SimpleNotificationApiParam.builder()
.title("오하요 고자이마스")
.message("본문 데스")
.notifiedAt(DateTimeUtil.formatDateTime(LocalDateTime.of(2021, 9, 27, 0, 0, 0)))
.showId(java.util.UUID.randomUUID())
.showImageURL("https://example.com/show.jpg")
.build(),
SimpleNotificationApiParam.builder()
.title("알림알림제목제목알림알림제목제목")
.message("알림본문본문알림본문본문알림본문본문")
.notifiedAt(DateTimeUtil.formatDateTime(LocalDateTime.of(2021, 9, 27, 12, 0, 0)))
.showId(java.util.UUID.randomUUID())
.showImageURL("https://example.com/show.jpg")
.build(),
SimpleNotificationApiParam.builder()
.title("알림 제목")
.message("알림 본문")
.notifiedAt(DateTimeUtil.formatDateTime(LocalDateTime.of(2021, 9, 27, 23, 0, 0)))
.showId(java.util.UUID.randomUUID())
.showImageURL("https://example.com/show.jpg")
.build()
)
)
PaginationApiResponse.<SimpleNotificationApiParam>builder()
.hasNext(response.hasNext())
.data(data)
.cursor(response.cursor())
.build()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,35 @@
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.UUID;
import lombok.Builder;
import org.example.service.dto.response.NotificationServiceResponse.NotificationInfoWithImageResponse;
import org.example.util.DateTimeUtil;

@Builder
public record SimpleNotificationApiParam(
@Schema(description = "알림 제목")
String title,

@Schema(description = "알림 본문")
String message,
@Schema(description = "알림 시간")

@Schema(description = "알림 생성 시간")
String notifiedAt,

@Schema(description = "공연 ID")
UUID showId,

@Schema(description = "공연 이미지 URL")
String showImageURL
) {

public static SimpleNotificationApiParam from(NotificationInfoWithImageResponse response) {
return SimpleNotificationApiParam.builder()
.title(response.title())
.message(response.content())
.notifiedAt(DateTimeUtil.formatDateTime(response.createAt()))
.showId(response.showId())
.showImageURL(response.imageURL())
.build();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.example.controller.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import org.example.service.dto.response.NotificationExistServiceResponse;

@Builder
public record NotificationExistApiResponse(
@Schema(description = "미열람 존재 여부")
boolean isExist
) {

public static NotificationExistApiResponse from(NotificationExistServiceResponse response) {
return new NotificationExistApiResponse(response.isActivate());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.example.property;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "alarm")
public record AlarmServerProperty(
String apiURL
) {
}
Loading

0 comments on commit dc5d9aa

Please sign in to comment.