-
Notifications
You must be signed in to change notification settings - Fork 1
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
12 changed files
with
279 additions
and
49 deletions.
There are no files selected for viewing
68 changes: 34 additions & 34 deletions
68
perfume-api/src/main/java/io/perfume/api/common/config/RedisConfiguration.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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
package io.perfume.api.common.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; | ||
|
||
@Configuration | ||
@EnableRedisRepositories | ||
@RequiredArgsConstructor | ||
public class RedisConfiguration { | ||
|
||
@Value("${spring.redis.host}") | ||
private String host; | ||
|
||
@Value("${spring.redis.port}") | ||
private int port; | ||
|
||
@Value("${spring.redis.password}") | ||
private String password; | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); | ||
redisStandaloneConfiguration.setHostName(host); | ||
redisStandaloneConfiguration.setPort(port); | ||
redisStandaloneConfiguration.setPassword(password); | ||
return new LettuceConnectionFactory(redisStandaloneConfiguration); | ||
} | ||
} | ||
//package io.perfume.api.common.config; | ||
// | ||
//import lombok.RequiredArgsConstructor; | ||
//import org.springframework.beans.factory.annotation.Value; | ||
//import org.springframework.context.annotation.Bean; | ||
//import org.springframework.context.annotation.Configuration; | ||
//import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
//import org.springframework.data.redis.connection.RedisStandaloneConfiguration; | ||
//import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
//import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; | ||
// | ||
//@Configuration | ||
//@EnableRedisRepositories | ||
//@RequiredArgsConstructor | ||
//public class RedisConfiguration { | ||
// | ||
// @Value("${spring.redis.host}") | ||
// private String host; | ||
// | ||
// @Value("${spring.redis.port}") | ||
// private int port; | ||
// | ||
// @Value("${spring.redis.password}") | ||
// private String password; | ||
// | ||
// @Bean | ||
// public RedisConnectionFactory redisConnectionFactory() { | ||
// RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); | ||
// redisStandaloneConfiguration.setHostName(host); | ||
// redisStandaloneConfiguration.setPort(port); | ||
// redisStandaloneConfiguration.setPassword(password); | ||
// return new LettuceConnectionFactory(redisStandaloneConfiguration); | ||
// } | ||
//} |
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
13 changes: 13 additions & 0 deletions
13
.../main/java/io/perfume/api/notification/adapter/port/in/dto/GetNotificationRequestDto.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 io.perfume.api.notification.adapter.port.in.dto; | ||
|
||
import io.perfume.api.notification.application.port.in.dto.GetNotificationCommand; | ||
|
||
public record GetNotificationRequestDto(Integer pageSize, String before, String after) { | ||
public GetNotificationCommand toCommand() { | ||
return new GetNotificationCommand(getSizeOrDefault(), before, after); | ||
} | ||
|
||
private int getSizeOrDefault() { | ||
return pageSize == null ? 10 : pageSize; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...main/java/io/perfume/api/notification/adapter/port/in/dto/GetNotificationResponseDto.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,14 @@ | ||
package io.perfume.api.notification.adapter.port.in.dto; | ||
|
||
import io.perfume.api.notification.application.port.in.dto.GetNotificationResult; | ||
|
||
public record GetNotificationResponseDto(Long id, String content, String notificationType) { | ||
|
||
public static GetNotificationResponseDto from(GetNotificationResult getNotificationResult) { | ||
return new GetNotificationResponseDto( | ||
getNotificationResult.id(), | ||
getNotificationResult.content(), | ||
getNotificationResult.notificationType() | ||
); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
...src/main/java/io/perfume/api/notification/application/port/in/GetNotificationUseCase.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,10 @@ | ||
package io.perfume.api.notification.application.port.in; | ||
|
||
import dto.repository.CursorPagination; | ||
import io.perfume.api.notification.application.port.in.dto.GetNotificationCommand; | ||
import io.perfume.api.notification.application.port.in.dto.GetNotificationResult; | ||
|
||
public interface GetNotificationUseCase { | ||
|
||
CursorPagination<GetNotificationResult> getNotifications(long userId, GetNotificationCommand command); | ||
} |
23 changes: 23 additions & 0 deletions
23
...main/java/io/perfume/api/notification/application/port/in/dto/GetNotificationCommand.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,23 @@ | ||
package io.perfume.api.notification.application.port.in.dto; | ||
|
||
import dto.repository.CursorDirection; | ||
|
||
public record GetNotificationCommand(int pageSize, String before, String after) { | ||
public String getCursor() { | ||
if (before != null) return before; | ||
return after; | ||
} | ||
|
||
public boolean hasNext() { | ||
return after != null; | ||
} | ||
|
||
public boolean hasPrevious() { | ||
return before != null; | ||
} | ||
|
||
public CursorDirection getDirection() { | ||
if (before != null) return CursorDirection.PREVIOUS; | ||
return CursorDirection.NEXT; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
.../main/java/io/perfume/api/notification/application/port/in/dto/GetNotificationResult.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,4 @@ | ||
package io.perfume.api.notification.application.port.in.dto; | ||
|
||
public record GetNotificationResult(Long id, String content, String notificationType) { | ||
} |
6 changes: 6 additions & 0 deletions
6
...rfume/api/notification/application/port/out/notification/NotificationQueryRepository.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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package io.perfume.api.notification.application.port.out.notification; | ||
|
||
import dto.repository.CursorPageable; | ||
import dto.repository.CursorPagination; | ||
import io.perfume.api.notification.application.port.in.dto.NotificationResult; | ||
import io.perfume.api.notification.domain.Notification; | ||
|
||
import java.util.Optional; | ||
|
||
public interface NotificationQueryRepository { | ||
|
||
Optional<Notification> findById(Long id); | ||
|
||
CursorPagination<Notification> findByreceiveUserId(CursorPageable pageable, long userId); | ||
} |
37 changes: 37 additions & 0 deletions
37
...src/main/java/io/perfume/api/notification/application/service/GetNotificationService.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,37 @@ | ||
package io.perfume.api.notification.application.service; | ||
|
||
import dto.repository.CursorPageable; | ||
import dto.repository.CursorPagination; | ||
import io.perfume.api.notification.application.port.in.GetNotificationUseCase; | ||
import io.perfume.api.notification.application.port.in.dto.GetNotificationCommand; | ||
import io.perfume.api.notification.application.port.in.dto.GetNotificationResult; | ||
import io.perfume.api.notification.application.port.out.notification.NotificationQueryRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class GetNotificationService implements GetNotificationUseCase { | ||
|
||
private final NotificationQueryRepository notificationQueryRepository; | ||
|
||
public GetNotificationService(NotificationQueryRepository notificationQueryRepository) { | ||
this.notificationQueryRepository = notificationQueryRepository; | ||
} | ||
|
||
@Override | ||
public CursorPagination<GetNotificationResult> getNotifications(long userId, GetNotificationCommand command) { | ||
var pageable = | ||
new CursorPageable(command.pageSize(), command.getDirection(), command.getCursor()); | ||
var notifications = notificationQueryRepository.findByreceiveUserId(pageable, userId); | ||
var result = | ||
notifications.getItems().stream() | ||
.map( | ||
item -> | ||
new GetNotificationResult( | ||
item.getId(), | ||
item.getContent(), | ||
item.getNotificationType().getType())) | ||
.toList(); | ||
|
||
return CursorPagination.of(result, notifications); | ||
} | ||
} |
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
Oops, something went wrong.