Skip to content

Commit

Permalink
Merge pull request #792 from woowacourse-teams/refactor/645-change-de…
Browse files Browse the repository at this point in the history
…lete-method-name

delete 메서드명 명확하게 변경
  • Loading branch information
zangsu authored Oct 17, 2024
2 parents 9078171 + e49502a commit 77a05f4
Show file tree
Hide file tree
Showing 24 changed files with 45 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public interface LikesJpaRepository extends LikesRepository, JpaRepository<Likes

@Modifying(clearAutomatically = true)
@Query("DELETE FROM Likes l WHERE l.template.id in :templateIds")
void deleteByTemplateIds(@Param(value = "templateIds") List<Long> templateIds);
void deleteAllByTemplateIds(@Param(value = "templateIds") List<Long> templateIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public interface LikesRepository {

void deleteByMemberAndTemplate(Member member, Template template);

void deleteByTemplateIds(List<Long> templateIds);
void deleteAllByTemplateIds(List<Long> templateIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public void cancelLike(Member member, long templateId) {

@Transactional
public void deleteAllByTemplateIds(List<Long> templateIds) {
likesRepository.deleteByTemplateIds(templateIds);
likesRepository.deleteAllByTemplateIds(templateIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ public interface TemplateTagJpaRepository extends TemplateTagRepository, JpaRepo
JOIN TemplateTag tt ON t.id = tt.id.tagId
WHERE tt.template = :template
""")
List<Tag> findAllTagsByTemplate(Template template);
List<Tag> findAllTagsByTemplate(@Param("template") Template template);

@Query("""
SELECT tt, t
FROM TemplateTag tt
JOIN FETCH tt.tag t
WHERE tt.id.templateId = :templateId
""")
List<TemplateTag> findAllByTemplateId(Long templateId);
List<TemplateTag> findAllByTemplateId(@Param("templateId") Long templateId);

@Query("""
SELECT tt, t
FROM TemplateTag tt
JOIN FETCH tt.tag t
WHERE tt.id.templateId in :templateIds
""")
List<TemplateTag> findAllByTemplateIdsIn(List<Long> templateIds);
List<TemplateTag> findAllByTemplateIdsIn(@Param("templateIds") List<Long> templateIds);

@Query("""
SELECT DISTINCT t
Expand All @@ -49,9 +49,9 @@ WHERE tt.id.templateId IN (
)
)
""")
List<Tag> findAllTagDistinctByMemberId(Long memberId);
List<Tag> findAllTagDistinctByMemberId(@Param("memberId") Long memberId);

@Modifying(clearAutomatically = true)
@Query("DELETE FROM TemplateTag t WHERE t.template.id in :templateIds")
void deleteByTemplateIds(@Param("templateIds") List<Long> templateIds);
void deleteAllByTemplateIds(@Param("templateIds") List<Long> templateIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ public interface TemplateTagRepository {

void deleteAllByTemplateId(Long templateId);

void deleteByTemplateIds(List<Long> templateIds);
void deleteAllByTemplateIds(List<Long> templateIds);
}
2 changes: 1 addition & 1 deletion backend/src/main/java/codezap/tag/service/TagService.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ public void updateTags(Template template, List<String> tags) {

@Transactional
public void deleteAllByTemplateIds(List<Long> templateIds) {
templateTagRepository.deleteByTemplateIds(templateIds);
templateTagRepository.deleteAllByTemplateIds(templateIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public ResponseEntity<Void> deleteTemplates(
@AuthenticationPrinciple Member member,
@PathVariable List<Long> ids
) {
templateApplicationService.deleteByMemberAndIds(member, ids);
templateApplicationService.deleteAllByMemberAndTemplateIds(member, ids);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import codezap.global.exception.CodeZapException;
import codezap.global.exception.ErrorCode;
Expand Down Expand Up @@ -37,5 +38,5 @@ default SourceCode fetchByTemplateAndOrdinal(Template template, int ordinal) {

@Modifying(clearAutomatically = true)
@Query("DELETE FROM SourceCode s WHERE s.template.id in :templateIds")
void deleteByTemplateIds(List<Long> templateIds);
void deleteAllByTemplateIds(@Param("templateIds") List<Long> templateIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public interface SourceCodeRepository {

void deleteById(Long id);

void deleteByTemplateIds(List<Long> templateIds);
void deleteAllByTemplateIds(List<Long> templateIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import codezap.global.exception.CodeZapException;
import codezap.global.exception.ErrorCode;
Expand All @@ -28,20 +29,20 @@ default Thumbnail fetchByTemplate(Template template) {
join fetch t.sourceCode sc
WHERE t.template = :template
""")
Optional<Thumbnail> findByTemplate(Template template);
Optional<Thumbnail> findByTemplate(@Param("template") Template template);


@Modifying(clearAutomatically = true)
@Query("DELETE FROM Thumbnail t WHERE t.template.id in :templateIds")
void deleteByTemplateIds(List<Long> templateIds);
void deleteAllByTemplateIds(@Param("templateIds") List<Long> templateIds);

@Query("""
SELECT t, sc
FROM Thumbnail t
join fetch t.sourceCode sc
WHERE t.template.id IN :templateIds
""")
List<Thumbnail> findAllByTemplateIn(List<Long> templateIds);
List<Thumbnail> findAllByTemplateIn(@Param("templateIds") List<Long> templateIds);

void deleteByTemplateId(Long id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ public interface ThumbnailRepository {

Thumbnail save(Thumbnail thumbnail);

void deleteByTemplateIds(List<Long> ids);
void deleteAllByTemplateIds(List<Long> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void validateSourceCodesCount(Template template, UpdateTemplateRequest u
}

@Transactional
public void deleteByTemplateIds(List<Long> templateIds) {
sourceCodeRepository.deleteByTemplateIds(templateIds);
public void deleteAllByTemplateIds(List<Long> templateIds) {
sourceCodeRepository.deleteAllByTemplateIds(templateIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ExploreTemplatesResponse findAll() {
}

@Transactional
public void deleteByTemplateIds(List<Long> templateIds) {
thumbnailRepository.deleteByTemplateIds(templateIds);
public void deleteAllByTemplateIds(List<Long> templateIds) {
thumbnailRepository.deleteAllByTemplateIds(templateIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ public void update(Member member, Long templateId, UpdateTemplateRequest updateT
}

@Transactional
public void deleteByMemberAndIds(Member member, List<Long> ids) {
thumbnailService.deleteByTemplateIds(ids);
sourceCodeService.deleteByTemplateIds(ids);
tagService.deleteAllByTemplateIds(ids);
likesService.deleteAllByTemplateIds(ids);
templateService.deleteByMemberAndIds(member, ids);
public void deleteAllByMemberAndTemplateIds(Member member, List<Long> templateIds) {
thumbnailService.deleteAllByTemplateIds(templateIds);
sourceCodeService.deleteAllByTemplateIds(templateIds);
tagService.deleteAllByTemplateIds(templateIds);
likesService.deleteAllByTemplateIds(templateIds);
templateService.deleteByMemberAndIds(member, templateIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public void deleteByMemberAndTemplate(Member member, Template template) {
}

@Override
public void deleteByTemplateIds(List<Long> templateIds) {
public void deleteAllByTemplateIds(List<Long> templateIds) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void testDeleteByTemplateId() {
likesRepository.save(new Likes(template1, member2));
likesRepository.save(new Likes(template2, member1));

likesRepository.deleteByTemplateIds(List.of(template1.getId()));
likesRepository.deleteAllByTemplateIds(List.of(template1.getId()));

assertAll(
() -> assertThat(likesRepository.countByTemplate(template1)).isEqualTo(0),
Expand All @@ -191,7 +191,7 @@ void testDeleteByTemplateIds() {
likesRepository.save(new Likes(template1, member2));
likesRepository.save(new Likes(template2, member1));

likesRepository.deleteByTemplateIds(List.of(template1.getId(), template2.getId()));
likesRepository.deleteAllByTemplateIds(List.of(template1.getId(), template2.getId()));

assertAll(
() -> assertThat(likesRepository.countByTemplate(template1)).isEqualTo(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void deleteById(Long id) {
}

@Override
public void deleteByTemplateIds(List<Long> templateIds) {
public void deleteAllByTemplateIds(List<Long> templateIds) {
templateIds.forEach(id ->
sourceCodes.removeIf(sourceCode -> Objects.equals(sourceCode.getId(), id)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void deleteAllByTemplateId(Long templateId) {
}

@Override
public void deleteByTemplateIds(List<Long> templateIds) {
public void deleteAllByTemplateIds(List<Long> templateIds) {
templateIds.forEach(id ->
templateTags.removeIf(templateTag -> Objects.equals(templateTag.getId(), id)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Thumbnail save(Thumbnail entity) {
}

@Override
public void deleteByTemplateIds(List<Long> templateIds) {
public void deleteAllByTemplateIds(List<Long> templateIds) {
templateIds.forEach(id ->
thumbnails.removeIf(thumbnail -> Objects.equals(thumbnail.getId(), id)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void testDeleteByTemplateId() {
sut.save(new SourceCode(template1, "SourceCode 2", "Content 2", 2));
sut.save(new SourceCode(template2, "SourceCode 3", "Content 3", 1));

sut.deleteByTemplateIds(List.of(1L));
sut.deleteAllByTemplateIds(List.of(1L));
var result = sut.findAllByTemplate(template1);

assertThat(result).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void deleteByTemplateIdSuccess() {
sut.save(new Thumbnail(template, sourceCode));

// when
sut.deleteByTemplateIds(List.of(template.getId()));
sut.deleteAllByTemplateIds(List.of(template.getId()));

// then
assertThatThrownBy(() -> sut.fetchByTemplate(template))
Expand All @@ -136,7 +136,7 @@ void deleteByTemplateIdSuccess() {
@Test
@DisplayName("템플릿 id로 썸네일 삭제 성공: 존재하지 않는 템플릿의 id로 삭제해도 예외로 처리하지 않는다.")
void deleteByNotExistTemplateId() {
assertThatCode(() -> sut.deleteByTemplateIds(List.of(100L)))
assertThatCode(() -> sut.deleteAllByTemplateIds(List.of(100L)))
.doesNotThrowAnyException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ void deleteById() {
sourceCodeRepository.save(SourceCodeFixture.get(template, 2));

// when
sourceCodeService.deleteByTemplateIds(List.of(template.getId()));
sourceCodeService.deleteAllByTemplateIds(List.of(template.getId()));

// then
assertThat(sourceCodeRepository.findAllByTemplate(template)).isEmpty();
Expand All @@ -447,7 +447,7 @@ void deleteByIds() {
sourceCodeRepository.save(SourceCodeFixture.get(template2, 2));

// when
sourceCodeService.deleteByTemplateIds(List.of(template1.getId(), template2.getId()));
sourceCodeService.deleteAllByTemplateIds(List.of(template1.getId(), template2.getId()));

// then
assertAll(
Expand All @@ -461,7 +461,7 @@ void deleteByIds() {
void deleteByIds_WhenIdNotExist() {
Template template = createSavedTemplate();

sourceCodeService.deleteByTemplateIds(List.of(template.getId()));
sourceCodeService.deleteAllByTemplateIds(List.of(template.getId()));

assertThat(sourceCodeRepository.findAllByTemplate(template)).isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ void deleteByTemplateSuccessWithOneThumbnail() {
var sourceCode2 = sourceCodeRepository.save(new SourceCode(template2, "Filename 2", "Content 2", 1));
var savedThumbnail2 = thumbnailRepository.save(new Thumbnail(template2, sourceCode2));

sut.deleteByTemplateIds(List.of(template1.getId()));
sut.deleteAllByTemplateIds(List.of(template1.getId()));
var actual = thumbnailRepository.findAll();

assertThat(actual).hasSize(1)
Expand All @@ -186,7 +186,7 @@ void deleteByTemplateSuccessWithTwoThumbnail() {
var sourceCode2 = sourceCodeRepository.save(new SourceCode(template2, "Filename 2", "Content 2", 1));
var savedThumbnail2 = thumbnailRepository.save(new Thumbnail(template2, sourceCode2));

sut.deleteByTemplateIds(List.of(template1.getId(), template2.getId()));
sut.deleteAllByTemplateIds(List.of(template1.getId(), template2.getId()));
var actual = thumbnailRepository.findAll();

assertThat(actual).doesNotContain(savedThumbnail1, savedThumbnail2);
Expand All @@ -202,7 +202,7 @@ void deleteByTemplateFailWithWrongID() {
var savedThumbnail = thumbnailRepository.save(new Thumbnail(template, sourceCode));
var nonExistentID = 100L;

sut.deleteByTemplateIds(List.of(nonExistentID));
sut.deleteAllByTemplateIds(List.of(nonExistentID));
var actual = thumbnailRepository.findAll();

assertThat(actual).hasSize(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ void deleteByMemberAndIds() {
var deleteIds = List.of(template1.getId(), template2.getId());

// when
sut.deleteByMemberAndIds(member, deleteIds);
sut.deleteAllByMemberAndTemplateIds(member, deleteIds);

// then
Specification<Template> spec = new TemplateSpecification(member.getId(), null, null, null);
Expand Down

0 comments on commit 77a05f4

Please sign in to comment.