Skip to content

Commit

Permalink
Merge pull request #86 from BbeumbungE/hotfix/BACK-87
Browse files Browse the repository at this point in the history
fix: 랭킹 없을 경우 예외처리 추가 [BACK-87]
  • Loading branch information
Fishphobiagg authored Oct 4, 2023
2 parents cfac958 + 9611dbf commit a959970
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public class VisionDetectingService {
public Score calculateCanvasScore(Long canvasId) {
Canvas canvas = canvasFindDao.findById(canvasId);
Map<String, Float> detectResult = visionService.detectLabels(canvas.getCanvas());
log.info(detectResult.size() + "개");
if (detectResult.size() == 0 || detectResult.containsKey("Error")) {return Score.LOW;}
log.info(detectResult + "점");
Float detectionScore = detectResult.get(canvas.getSubject().getPix2Pix().getVisionName());

return Score.determineScore(detectionScore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public void cachingRankToRedis(RankingCachingDto rankingCachingDto){

public String getTopPostThisWeek(Long subjectId){
RankingCachingDto rankingCachingDto = redisTemplate.opsForList().index(generateRedisKey(subjectId), -1);
if (rankingCachingDto == null){
return null;
}
if (rankingCachingDto.getRankerList().isEmpty()){
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public class GoogleVisionApiTests {
void 라벨_추출_테스트(){

// given
String imageUrl = "https://aicanvas-mw.s3.ap-northeast-2.amazonaws.com/subject/car.png";
String imageUrl = "https://aicanvas-mw.s3.ap-northeast-2.amazonaws.com/profile/36/canvas/handbag/1696378614753525592.JPG";

// when
Map<String, Float> results = googleVisionApiService.detectLabels(imageUrl);

// then
assertFalse(results.isEmpty());
assertTrue(results.containsKey("car"));
assertTrue(results.containsKey("bag"));
assertTrue(results.keySet().stream().allMatch(key -> key.equals(key.toLowerCase())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.siliconvalley.domain.canvas.domain.Canvas;
import com.siliconvalley.domain.google.service.GoogleVisionApiService;
import com.siliconvalley.domain.google.service.VisionDetectingService;
import com.siliconvalley.domain.item.subject.domain.Subject;
import com.siliconvalley.domain.pix2pix.domain.Pix2Pix;
import com.siliconvalley.domain.stage.domain.Score;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -12,6 +14,8 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Map;

Expand All @@ -28,10 +32,11 @@ public class VisionDetectingServiceTests {
private VisionDetectingService visionDetectingService;

@Mock
private CanvasFindDao canvasFindDao;
private GoogleVisionApiService visionService;

@Mock
private GoogleVisionApiService visionService;
private CanvasFindDao canvasFindDao;


@Test
@DisplayName(value = "다른 물체만 감지되었을 때 그림의 점수를 LOW(1)로 반환")
Expand Down Expand Up @@ -124,5 +129,4 @@ public class VisionDetectingServiceTests {
// Then
assertEquals(Score.LOW, result);
}

}

0 comments on commit a959970

Please sign in to comment.