Skip to content

Instantly share code, notes, and snippets.

@itsgokhanyilmaz
itsgokhanyilmaz / MockBlobStorageService.java
Last active August 31, 2020 18:01
MockBlobStorageService
@Service
@ConditionalOnProperty(value = "mock.azure.blobstorage.service.enabled", havingValue = "true")
public class MockBlobStorageService implements BlobStorageService{
@Override
public URI uploadPicture(MultipartFile multipartFile) {
return URI.create("https://mahallemstorage.blob.core.windows.net/testmahallem/mordor_ale.png");
}
}
mock:
azure.blobstorage.service.enabled: true
@RequiredArgsConstructor
@Repository
public class UserRepositoryImpl implements UserRepository {
@NotNull
private final MongoTemplate mongoTemplate;
@Override
public void uploadProfilePicture(String url, ObjectId id) {
UpdateResult updateResult = mongoTemplate.updateFirst(Query.query(Criteria.where("_id").is(id)),
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
private final BlobStorageService blobStorageService;
@NotNull
final MongoTemplate mongoTemplate;
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {
private final UserService userService;
@PostMapping("upload-profile-picture")
public ResponseEntity<MainResponse<UserResponse>> writeBlobFile(@RequestParam(value = "image", required = false) MultipartFile file, HttpServletRequest httpServletRequest) throws IOException {
String userId = JwtUtil.getObjectIdFromRequest(httpServletRequest);
@itsgokhanyilmaz
itsgokhanyilmaz / BlobStorageServiceImpl.java
Created August 29, 2020 14:37
BlobStorageServiceImpl
@Service
@RequiredArgsConstructor
@ConditionalOnProperty(value = "mock.azure.blobstorage.service.enabled", havingValue = "false", matchIfMissing = true)
public class BlobStorageServiceImpl implements BlobStorageService {
private final Logger LOGGER = LoggerFactory.getLogger(BlobStorageServiceImpl.class);
private final CloudBlobContainer cloudBlobContainer;
@Override
public URI uploadPicture(MultipartFile multipartFile) {
public interface BlobStorageService {
public URI uploadPicture(MultipartFile multipartFile);
}
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-storage</artifactId>
<version>8.4.0</version>
</dependency>
spring:
azure:
blob:
store:
connectionString: ${azure_blob_store_connection_string}
containerName: ${azure_blob_store_connection_name}