Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
practise30 committed Aug 21, 2024
1 parent ed4c7f0 commit 2a0b3a3
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ env:

on:
push:
branches: [ "dev" ]
branches: [ "fix/uploading-image-test" ]


jobs:
Expand Down
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 src/main/java/nbdream/bulletin/dto/request/BulletinTestDto.java
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ public interface BulletinRepository extends JpaRepository<Bulletin, Long> {

@Query("SELECT b FROM Bulletin b WHERE b.author.id = :authorId")
List<Bulletin> findByAuthorId(@Param("authorId") Long authorId);

@Query("INSERT INTO Bulletin(content) VALUES('TEST')")
String saveContent(String content);
}
28 changes: 28 additions & 0 deletions src/main/java/nbdream/bulletin/service/TestBulletinService.java
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));

}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ResponseEntity<ApiResponse> handleBadRequest(final Exception e) {
@ExceptionHandler({UnauthorizedException.class, JwtException.class})
public ResponseEntity<ApiResponse> handleUnauthorized(final Exception e) {
log.debug("UnauthorizedException : {}", e.getMessage());
log.debug("Exception Stack Trace : \n{}", e.getStackTrace());
//log.debug("Exception Stack Trace : \n{}", e.getStackTrace());
return ResponseEntity.status(UNAUTHORIZED).body(ApiResponse.of(UNAUTHORIZED, e.getMessage()));
}

Expand Down
51 changes: 51 additions & 0 deletions src/main/java/nbdream/image/service/TestImageService.java
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();
}
}

}
74 changes: 37 additions & 37 deletions src/test/java/nbdream/GpsTransferTest.java
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))
// );
// }
//}
4 changes: 1 addition & 3 deletions src/test/java/nbdream/NbdreamApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
@SpringBootTest
class NbdreamApplicationTests {

@Test
void contextLoads() {
}


}

0 comments on commit 2a0b3a3

Please sign in to comment.