Skip to content

Commit

Permalink
refactor: port 인터페이스 분리
Browse files Browse the repository at this point in the history
포트 인터페이스가 의존성을 넓게 갖지 않도록 역할에 따라 인터페이스를 분리한다
  • Loading branch information
sa46lll committed Dec 24, 2023
1 parent ec8965b commit 683cd05
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.flow.sa46lll.fileshield.port.out;

import com.flow.sa46lll.fileshield.domain.BlockedExtension;
import java.util.List;

public interface ReadExtensionPersistencePort {

List<BlockedExtension> findAll();
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.flow.sa46lll.fileshield.port.out;

import com.flow.sa46lll.fileshield.domain.BlockedExtension;
import java.util.List;

public interface ExtensionPersistencePort {

List<BlockedExtension> findAll();
public interface WriteExtensionPersistencePort {

Long blockCustomExtension(final BlockedExtension blockedExtension);

void updateExtensionBlockStatus(final BlockedExtension blockedExtension);

void deleteCustomExtensionById(final Long extensionId);

boolean existsByExtension(String extension);
boolean existsByExtension(final String extension);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.flow.sa46lll.fileshield.port.in.BlockCustomExtensionUseCase;
import com.flow.sa46lll.fileshield.port.in.UpdateFixedExtensionUsecase;
import com.flow.sa46lll.fileshield.port.in.UnblockCustomExtensionUseCase;
import com.flow.sa46lll.fileshield.port.out.ExtensionPersistencePort;
import com.flow.sa46lll.fileshield.port.out.WriteExtensionPersistencePort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -18,30 +18,30 @@
public class ExtensionCommandService implements BlockCustomExtensionUseCase,
UnblockCustomExtensionUseCase, UpdateFixedExtensionUsecase {

private final ExtensionPersistencePort extensionPersistencePort;
private final WriteExtensionPersistencePort writeExtensionPersistencePort;

public ExtensionCommandService(final ExtensionPersistencePort extensionPersistencePort) {
this.extensionPersistencePort = extensionPersistencePort;
public ExtensionCommandService(final WriteExtensionPersistencePort writeExtensionPersistencePort) {
this.writeExtensionPersistencePort = writeExtensionPersistencePort;
}

@Override
public BlockCustomExtensionResponse blockCustom(final BlockCustomExtensionCommand blockCustomExtensionCommand) {
validateExtensionDuplication(blockCustomExtensionCommand.extension());

BlockedExtension blockedExtension = blockCustomExtensionCommand.toDomain();
Long savedId = extensionPersistencePort.blockCustomExtension(blockedExtension);
Long savedId = writeExtensionPersistencePort.blockCustomExtension(blockedExtension);
return BlockCustomExtensionResponseMapper.toResponse(savedId);
}

private void validateExtensionDuplication(String extension) {
if (extensionPersistencePort.existsByExtension(extension)) {
if (writeExtensionPersistencePort.existsByExtension(extension)) {
throw new ExtensionDuplicationException("이미 존재하는 확장자입니다.");
}
}

@Override
public void unblockCustom(final Long extensionId) {
extensionPersistencePort.deleteCustomExtensionById(extensionId);
writeExtensionPersistencePort.deleteCustomExtensionById(extensionId);
}

@Override
Expand All @@ -59,6 +59,6 @@ public void unblockFixed(final Long extensionId) {
}

private void updateExtensionBlockStatus(final BlockedExtension blockedExtension) {
extensionPersistencePort.updateExtensionBlockStatus(blockedExtension);
writeExtensionPersistencePort.updateExtensionBlockStatus(blockedExtension);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.flow.sa46lll.fileshield.dto.GetExtensionResponse;
import com.flow.sa46lll.fileshield.dto.GetExtensionsResponse;
import com.flow.sa46lll.fileshield.port.in.GetExtensionQuery;
import com.flow.sa46lll.fileshield.port.out.ExtensionPersistencePort;
import com.flow.sa46lll.fileshield.port.out.ReadExtensionPersistencePort;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -13,15 +13,15 @@
@Transactional(readOnly = true)
public class ExtensionQueryService implements GetExtensionQuery {

private final ExtensionPersistencePort extensionPersistencePort;
private final ReadExtensionPersistencePort readExtensionPersistencePort;

public ExtensionQueryService(final ExtensionPersistencePort extensionPersistencePort) {
this.extensionPersistencePort = extensionPersistencePort;
public ExtensionQueryService(final ReadExtensionPersistencePort readExtensionPersistencePort) {
this.readExtensionPersistencePort = readExtensionPersistencePort;
}

@Override
public GetExtensionsResponse findAll() {
List<BlockedExtension> extensions = extensionPersistencePort.findAll();
List<BlockedExtension> extensions = readExtensionPersistencePort.findAll();
List<GetExtensionResponse> fixedExtensions = extensions.stream()
.filter(BlockedExtension::isFixed)
.map(GetExtensionResponse::of)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.flow.sa46lll.fileshield.adapter;

import com.flow.sa46lll.fileshield.domain.BlockedExtension;
import com.flow.sa46lll.fileshield.mapper.BlockedExtensionMapper;
import com.flow.sa46lll.fileshield.port.out.ReadExtensionPersistencePort;
import com.flow.sa46lll.fileshield.repository.BlockedExtensionRepository;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class ReadExtensionPersistenceAdapter implements ReadExtensionPersistencePort {

private final BlockedExtensionRepository blockedExtensionRepository;

public ReadExtensionPersistenceAdapter(BlockedExtensionRepository blockedExtensionRepository) {
this.blockedExtensionRepository = blockedExtensionRepository;
}

@Override
public List<BlockedExtension> findAll() {
return blockedExtensionRepository.findAll().stream()
.map(BlockedExtensionMapper::toDomain)
.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,23 @@

import com.flow.sa46lll.fileshield.domain.BlockedExtension;
import com.flow.sa46lll.fileshield.mapper.BlockedExtensionMapper;
import com.flow.sa46lll.fileshield.port.out.ExtensionPersistencePort;
import com.flow.sa46lll.fileshield.port.out.WriteExtensionPersistencePort;
import com.flow.sa46lll.fileshield.entity.BlockedExtensionEntity;
import com.flow.sa46lll.fileshield.entity.ExtensionTypeEntity;
import com.flow.sa46lll.fileshield.repository.BlockedExtensionRepository;
import java.util.List;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@Transactional
public class ExtensionPersistenceAdapter implements ExtensionPersistencePort {
public class WriteExtensionPersistenceAdapter implements WriteExtensionPersistencePort {

private final BlockedExtensionRepository blockedExtensionRepository;

public ExtensionPersistenceAdapter(final BlockedExtensionRepository blockedExtensionRepository) {
public WriteExtensionPersistenceAdapter(final BlockedExtensionRepository blockedExtensionRepository) {
this.blockedExtensionRepository = blockedExtensionRepository;
}

@Override
public List<BlockedExtension> findAll() {
return blockedExtensionRepository.findAll().stream()
.map(BlockedExtensionMapper::toDomain)
.toList();
}

@Override
public Long blockCustomExtension(BlockedExtension blockedExtension) {
return blockedExtensionRepository
Expand Down

0 comments on commit 683cd05

Please sign in to comment.