Skip to content

Commit

Permalink
Fix : Code Smells 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
haeyonghahn committed Mar 5, 2024
1 parent 3296a87 commit 0ff9a1f
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public S3ServiceStore(S3Client s3Client) {

public String putFile(String key, File file) {
s3Client.putObject(
(req) -> {
req -> {
req.bucket(bucket);
req.key(key);
},
Expand All @@ -39,15 +39,15 @@ public File getFile(String key) {
File file = new File(key);
ResponseInputStream<GetObjectResponse> s3Object =
s3Client.getObject(
(req) -> {
req -> {
req.bucket(bucket);
req.key(key);
});

try {
FileUtils.writeByteArrayToFile(file, s3Object.readAllBytes());
} catch (Exception e) {
throw new RuntimeException(e);
throw new IllegalArgumentException(e);
}
return file;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ private KakaoMember getKakaoMember(String kakaoOauthToken) {

if (responseEntity.getStatusCode() == HttpStatus.OK) {
return new KakaoMember(
responseEntity.getBody().getId(),
responseEntity.getBody().getKakaoAccount().getEmail(),
responseEntity.getBody().getProperties());
Objects.requireNonNull(responseEntity.getBody()).getId(),
Objects.requireNonNull(responseEntity.getBody()).getKakaoAccount().getEmail(),
Objects.requireNonNull(responseEntity.getBody()).getProperties());
} else {
throw new ConnectionException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void create(RecordRequest recordRequest) throws IOException {
.placeLongitude(recordRequest.getPlaceLongitude())
.build();
Recorder recorder = recorderService.createRecorder(recordRequest.getRecorderMemberId());
Record record =
Record gilog =
Record.builder()
.number(recordNo)
.coordinate(coordinate)
Expand All @@ -62,16 +62,16 @@ public void create(RecordRequest recordRequest) throws IOException {
.recordDate(recordRequest.getRecordDate())
.images(images)
.build();
recordRepository.save(record);
recordRepository.save(gilog);
}

@Transactional
public void delete(String recordNo) {
Record record =
Record gilog =
recordRepository.findById(RecordNo.of(recordNo)).orElseThrow(NoRecordException::new);
for (Image image : record.getImages()) {
for (Image image : gilog.getImages()) {
fileService.deleteFile(image.getId().getId());
}
recordRepository.delete(record);
recordRepository.delete(gilog);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.dnd.gooding.record.command.domain;

import java.security.SecureRandom;
import java.util.Date;
import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom;
import org.springframework.data.repository.Repository;

public interface RecordRepository extends Repository<Record, RecordNo> {

Optional<Record> findById(RecordNo recordNo);

void save(Record record);
void save(Record gilog);

void delete(Record record);
void delete(Record gilog);

default RecordNo nextRecordNo() {
int randomNo = ThreadLocalRandom.current().nextInt(900000) + 100000;
int randomNo = new SecureRandom().nextInt(900000) + 100000;
String number = String.format("%tY%<tm%<td%<tH-%d", new Date(), randomNo);
return new RecordNo(number);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public List<RecordData> getRecord(MemberId recorderMemberId) {
List<ImageData> images = imageDataDao.findByRecordNumberIn(toRecordIds(records));
Map<String, List<ImageData>> imageMap =
images.stream().collect(Collectors.groupingBy(ImageData::getRecordNumber));
records.forEach(record -> record.setImages(imageMap.get(record.getRecordNumber())));
records.forEach(x -> x.setImages(imageMap.get(x.getRecordNumber())));
return records;
}

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/dnd/gooding/record/query/dao/ImageDataDao.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.dnd.gooding.record.query.dao;

import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
Expand All @@ -12,11 +11,11 @@ public interface ImageDataDao extends Repository<ImageData, Long> {

@Query(
"""
select new com.dnd.gooding.record.query.dto.ImageData(
i.id, i.path, i.uploadTime, i.recordNumber
)
from ImageData i
where i.recordNumber in (:recordIds)
select new com.dnd.gooding.record.query.dto.ImageData(
i.id, i.path, i.uploadTime, i.recordNumber
)
from ImageData i
where i.recordNumber in (:recordIds)
"""
)
List<ImageData> findByRecordNumberIn(List<String> recordIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class RecordController {

private final RecordService recordService;

private RecordController(RecordService recordService) {
public RecordController(RecordService recordService) {
this.recordService = recordService;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.dnd.gooding.token.command.model;

import java.util.Collection;
import java.util.Objects;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

public class JwtAuthenticationToken extends AbstractAuthenticationToken {

private Object principal;
private transient Object principal;
private String credentials;

public JwtAuthenticationToken(
Expand Down Expand Up @@ -52,4 +53,19 @@ public void eraseCredentials() {
super.eraseCredentials();
credentials = null;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
JwtAuthenticationToken that = (JwtAuthenticationToken) o;
return Objects.equals(principal, that.principal)
&& Objects.equals(credentials, that.credentials);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), principal, credentials);
}
}
11 changes: 7 additions & 4 deletions src/main/java/com/dnd/gooding/util/FileCreateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

public class FileCreateUtil {

private static final String OS_NAME = "os.name";
private static final String USER_HOME = "user.home";

private FileCreateUtil() {}

public static File convert(MultipartFile multipartFile) throws IOException {
Expand Down Expand Up @@ -38,7 +41,7 @@ private static String getOsPath(String appHome) {
}

private static String getUserHomeDir() {
return System.getProperty("user.home");
return System.getProperty(USER_HOME);
}

private static String getSystemDriver() {
Expand All @@ -51,14 +54,14 @@ private static String getSystemDriver() {
}

private static boolean isWindow() {
return (System.getProperty("os.name").toLowerCase().contains("win"));
return (System.getProperty(OS_NAME).toLowerCase().contains("win"));
}

private static boolean isMacOS() {
return (System.getProperty("os.name").toLowerCase().contains("mac"));
return (System.getProperty(OS_NAME).toLowerCase().contains("mac"));
}

private static boolean isLinux() {
return (System.getProperty("os.name").toLowerCase().contains("linux"));
return (System.getProperty(OS_NAME).toLowerCase().contains("linux"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class S3ServiceStoreTest extends IntegrationTest {

@DisplayName("S3 서비스에 파일을 넣고 가져온다.")
@Test
public void s3PutAndGetTest() throws Exception {
void s3PutAndGetTest() throws Exception {
// given
String key = "sampleObject.txt";
File sampleFile = new ClassPathResource("static/sample.txt").getFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.mockito.Mockito;

@DisplayName("기록 조회 유닛 테스트")
public class RecordQueryServiceTest {
class RecordQueryServiceTest {

private RecordDataDao recordDataDao;
private ImageDataDao imageDataDao;
Expand Down

0 comments on commit 0ff9a1f

Please sign in to comment.