This file contains hidden or 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
| mvn spring-boot:run -Dspring-boot.run.profiles=<active-profile> |
This file contains hidden or 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
| @Service | |
| public class StorageService { | |
| private final Logger log = LoggerFactory.getLogger(StorageService.class); | |
| private final StorageStrategy storageStrategy; | |
| public StorageService(StorageFactory storageFactory) { | |
| this.storageStrategy = storageFactory.createStrategy(); | |
| } | |
| public FileDTO uploadFile(MultipartFile file) throws Exception { |
This file contains hidden or 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
| @Service | |
| public class AwsStorageStrategy implements StorageStrategy { | |
| private final Logger log = LoggerFactory.getLogger(AwsStorageStrategy.class); | |
| private final Environment environment; | |
| private AmazonS3 s3client; | |
| @Value("${cloud.aws.endpointurl}") | |
| private String endpointUrl; | |
| @Value("${cloud.aws.region.static}") |
This file contains hidden or 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
| @Service | |
| public class FileStorageStrategy implements StorageStrategy { | |
| private final Logger log = LoggerFactory.getLogger(FileStorageStrategy.class); | |
| private final Path fileStorageLocation; | |
| @Autowired | |
| public FileStorageStrategy(FileStorageProperties fileStorageProperties) throws IOException { | |
| this.fileStorageLocation = Paths.get(fileStorageProperties.getUploadDir()) | |
| .toAbsolutePath().normalize(); | |
| Files.createDirectories(fileStorageLocation); |
This file contains hidden or 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
| public interface StorageStrategy { | |
| String[] uploadFile(MultipartFile multipartFile) throws Exception; | |
| } |
This file contains hidden or 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
| @Service | |
| public class StorageFactory { | |
| private final Logger log = LoggerFactory.getLogger(StorageFactory.class); | |
| private final Environment environment; | |
| private final AwsStorageStrategy awsStorageStrategy; | |
| private final FileStorageStrategy fileStorageStrategy; | |
| public StorageFactory(Environment environment, AwsStorageStrategy awsStorageStrategy, FileStorageStrategy fileStorageStrategy) { | |
| this.environment = environment; |
This file contains hidden or 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
| @Service | |
| public class GmailStrategy implements MailStrategy { | |
| private final Logger log = LoggerFactory.getLogger(GmailStrategy.class); | |
| private static final String USER = "user"; | |
| private static final String BASE_URL = "baseUrl"; | |
| private final JavaMailSender javaMailSender; | |
| private final MessageSource messageSource; | |
| private final SpringTemplateEngine templateEngine; | |
| private final Environment environment; |
This file contains hidden or 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
| @Service | |
| public class SendGridMailStrategy implements MailStrategy { | |
| private final Logger log = LoggerFactory.getLogger(SendGridMailStrategy.class); | |
| private final SpringTemplateEngine templateEngine; | |
| private final Environment environment; | |
| private static final String USER = "user"; | |
| private static final String BASE_URL = "baseUrl"; | |
| public SendGridMailStrategy(SpringTemplateEngine templateEngine, Environment environment) { | |
| this.templateEngine = templateEngine; |
This file contains hidden or 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
| public interface MailStrategy { | |
| @Async | |
| void sendActivationEmail(User user); | |
| } |
This file contains hidden or 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
| @Service | |
| public class MailFactory { | |
| private final Logger log = LoggerFactory.getLogger(MailFactory.class); | |
| private final Environment environment; | |
| private final GmailStrategy gmailStrategy; | |
| private final SendGridMailStrategy sendGridMailStrategy; | |
| public MailFactory(Environment environment, GmailStrategy gmailStrategy, SendGridMailStrategy sendGridMailStrategy) { | |
| this.environment = environment; | |
| this.gmailStrategy = gmailStrategy; |