Skip to content

Commit

Permalink
#18 [FIX] 템플릿 업데이트 삭제 & 로그 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hysong4u committed Dec 2, 2024
1 parent 99ec42b commit fbab1b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,15 @@ public void saveTemplate(ShareTemplateRequestDto shareTemplateRequestDto, String
Repo repo = repoRepository.findByRepoUrl(shareTemplateRequestDto.repoUrl())
.orElseThrow(() -> new EntityNotFoundException(REPO_NOT_FOUND));

Template existingTemplate = templateRepository.findByRepoAndType(repo, shareTemplateRequestDto.type())
.orElse(null);
if (existingTemplate != null) {
existingTemplate.updateContent(shareTemplateRequestDto.title(), shareTemplateRequestDto.content(), imageUrl);
templateRepository.save(existingTemplate);
} else {
// 새로운 템플릿 생성
Template newTemplate = Template.builder()
.repo(repo)
.title(shareTemplateRequestDto.title())
.content(shareTemplateRequestDto.content())
.type(shareTemplateRequestDto.type())
.imageUrl(imageUrl)
.build();

templateRepository.save(newTemplate);
}
Template newTemplate = Template.builder()
.repo(repo)
.title(shareTemplateRequestDto.title())
.content(shareTemplateRequestDto.content())
.type(shareTemplateRequestDto.type())
.imageUrl(imageUrl)
.build();

templateRepository.save(newTemplate);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public ResponseEntity<String> sendRequest(String url, HttpMethod method, HttpHea
try {
return restTemplate.exchange(url, method, request, String.class);
} catch (HttpClientErrorException e) {
System.out.println("GitHub API request failed: " + e.getMessage());
throw new InternalServerException(GITHUB_API_ERROR);
}
}
Expand All @@ -60,6 +61,7 @@ public String getFileSha(String url, HttpHeaders headers) {
return new org.json.JSONObject(response.getBody()).getString("sha");
}
} catch (Exception e) {
System.out.println("Failed to get SHA from GitHub API: " + e.getMessage());
throw new InternalServerException(UNPROCESSABLE_ENTITY);
}
return null;
Expand Down

0 comments on commit fbab1b2

Please sign in to comment.