-
Notifications
You must be signed in to change notification settings - Fork 0
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
practise30
committed
Aug 21, 2024
1 parent
ed4c7f0
commit 2a0b3a3
Showing
9 changed files
with
155 additions
and
42 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ env: | |
|
||
on: | ||
push: | ||
branches: [ "dev" ] | ||
branches: [ "fix/uploading-image-test" ] | ||
|
||
|
||
jobs: | ||
|
20 changes: 20 additions & 0 deletions
20
src/main/java/nbdream/bulletin/controller/TestBulletinController.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,20 @@ | ||
package nbdream.bulletin.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import nbdream.bulletin.dto.request.BulletinTestDto; | ||
import nbdream.bulletin.service.TestBulletinService; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class TestBulletinController { | ||
|
||
private final TestBulletinService service; | ||
|
||
@PostMapping("/test") | ||
public void test(@RequestPart BulletinTestDto dto) { | ||
service.uploadTestBulletin(dto); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/nbdream/bulletin/dto/request/BulletinTestDto.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 nbdream.bulletin.dto.request; | ||
|
||
import lombok.Data; | ||
import lombok.Getter; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
public class BulletinTestDto { | ||
private String content; | ||
private List<MultipartFile> files; | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/nbdream/bulletin/service/TestBulletinService.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,28 @@ | ||
package nbdream.bulletin.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import nbdream.bulletin.dto.request.BulletinTestDto; | ||
import nbdream.bulletin.repository.BulletinRepository; | ||
import nbdream.image.service.ImageService; | ||
import nbdream.image.service.TestImageService; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class TestBulletinService { | ||
|
||
private final BulletinService service; | ||
private final TestImageService testImageService; | ||
private final BulletinRepository repository; | ||
private final ImageService imageService; | ||
|
||
public void uploadTestBulletin(BulletinTestDto dto) { | ||
repository.saveContent(dto.getContent()); | ||
for (int i = 0; i < dto.getFiles().size(); i++) { | ||
testImageService.uploadTestImage(dto.getFiles().get(i)); | ||
|
||
} | ||
} | ||
|
||
|
||
} |
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
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,51 @@ | ||
package nbdream.image.service; | ||
|
||
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.cloud.storage.BlobInfo; | ||
import com.google.cloud.storage.Storage; | ||
import com.google.cloud.storage.StorageOptions; | ||
import lombok.RequiredArgsConstructor; | ||
import nbdream.image.exception.GcsConnectionException; | ||
import nbdream.image.exception.InvalidDomainException; | ||
import nbdream.image.infrastructure.GcpStorageProperties; | ||
import nbdream.image.repository.ImageRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.util.UUID; | ||
|
||
import static nbdream.image.infrastructure.GcpStorageProperties.BASIC_PATH; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class TestImageService { | ||
|
||
private final GcpStorageProperties gcpStorageProperties; | ||
private final ImageRepository imageRepository; | ||
|
||
|
||
public String uploadTestImage(MultipartFile image) { | ||
try { | ||
|
||
String uuid = UUID.randomUUID().toString(); | ||
String ext = image.getContentType(); | ||
|
||
Storage storage = StorageOptions.newBuilder() | ||
.setCredentials(GoogleCredentials.fromStream(gcpStorageProperties.getCredentialKey())) | ||
.build() | ||
.getService(); | ||
|
||
String blobName = uuid; | ||
BlobInfo blobInfo = BlobInfo.newBuilder(gcpStorageProperties.getBucketName(), blobName) | ||
.setContentType(ext) | ||
.build(); | ||
|
||
storage.create(blobInfo, image.getBytes()); | ||
return BASIC_PATH + blobName; | ||
} catch (IOException e) { | ||
throw new GcsConnectionException(); | ||
} | ||
} | ||
|
||
} |
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,37 +1,37 @@ | ||
package nbdream; | ||
|
||
|
||
import nbdream.common.util.GpsTransfer; | ||
import nbdream.common.util.Grid; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
public class GpsTransferTest { | ||
|
||
@DisplayName("위도 경도 정보를 격자 정보로 변환할 수 있다") | ||
@ParameterizedTest | ||
@MethodSource("gpsAndGrid") | ||
void convertGpsToGrid(double latitude, double longitude, Grid expected) { | ||
// when | ||
Grid actual = GpsTransfer.convertGpsToGrid(latitude, longitude); | ||
|
||
// then | ||
Assertions.assertThat(actual).isEqualTo(expected); | ||
|
||
} | ||
|
||
static Stream<Arguments> gpsAndGrid() { | ||
return Stream.of( | ||
Arguments.arguments(37.579871128849334, 126.98935225645432, new Grid(60, 127)), | ||
Arguments.arguments(35.101148844565955, 129.02478725562108, new Grid(97, 74)), | ||
Arguments.arguments(33.500946412305076, 126.54663058817043, new Grid(53, 38)), | ||
Arguments.arguments(36.531948553218223, 127.01234567891234, new Grid(61, 104)), | ||
Arguments.arguments(39.987654321654987, 128.98765432198765, new Grid(92, 180)) | ||
); | ||
} | ||
} | ||
//package nbdream; | ||
// | ||
// | ||
//import nbdream.common.util.GpsTransfer; | ||
//import nbdream.common.util.Grid; | ||
//import org.assertj.core.api.Assertions; | ||
//import org.junit.jupiter.api.DisplayName; | ||
//import org.junit.jupiter.params.ParameterizedTest; | ||
//import org.junit.jupiter.params.provider.Arguments; | ||
//import org.junit.jupiter.params.provider.MethodSource; | ||
// | ||
//import java.util.stream.Stream; | ||
// | ||
//public class GpsTransferTest { | ||
// | ||
// @DisplayName("위도 경도 정보를 격자 정보로 변환할 수 있다") | ||
// @ParameterizedTest | ||
// @MethodSource("gpsAndGrid") | ||
// void convertGpsToGrid(double latitude, double longitude, Grid expected) { | ||
// // when | ||
// Grid actual = GpsTransfer.convertGpsToGrid(latitude, longitude); | ||
// | ||
// // then | ||
// Assertions.assertThat(actual).isEqualTo(expected); | ||
// | ||
// } | ||
// | ||
// static Stream<Arguments> gpsAndGrid() { | ||
// return Stream.of( | ||
// Arguments.arguments(37.579871128849334, 126.98935225645432, new Grid(60, 127)), | ||
// Arguments.arguments(35.101148844565955, 129.02478725562108, new Grid(97, 74)), | ||
// Arguments.arguments(33.500946412305076, 126.54663058817043, new Grid(53, 38)), | ||
// Arguments.arguments(36.531948553218223, 127.01234567891234, new Grid(61, 104)), | ||
// Arguments.arguments(39.987654321654987, 128.98765432198765, new Grid(92, 180)) | ||
// ); | ||
// } | ||
//} |
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 |
---|---|---|
|
@@ -6,8 +6,6 @@ | |
@SpringBootTest | ||
class NbdreamApplicationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
|
||
} |