-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
아이템 수정 & 데이로그 수정 & 아이템 oridinal 수정 재업로드 (#710)
* refactor: 아이템, 데이로그 수정 쿼리 개선 * refactor: 아이템 수정 로직 변경
- Loading branch information
Showing
15 changed files
with
343 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/hanglog/image/domain/repository/CustomImageRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package hanglog.image.domain.repository; | ||
|
||
import hanglog.image.domain.Image; | ||
import java.util.List; | ||
|
||
public interface CustomImageRepository { | ||
|
||
void saveAll(final List<Image> images); | ||
|
||
void deleteAll(final List<Image> images); | ||
} |
58 changes: 58 additions & 0 deletions
58
backend/src/main/java/hanglog/image/infrastructure/CustomImageRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package hanglog.image.infrastructure; | ||
|
||
import hanglog.image.domain.Image; | ||
import hanglog.image.domain.repository.CustomImageRepository; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
import org.springframework.jdbc.core.namedparam.SqlParameterSource; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class CustomImageRepositoryImpl implements CustomImageRepository { | ||
|
||
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate; | ||
|
||
@Override | ||
public void saveAll(final List<Image> images) { | ||
final String sql = """ | ||
INSERT INTO image (created_at, modified_at, item_id, name, status) | ||
VALUES (:createdAt, :modifiedAt, :itemId, :name, :status) | ||
"""; | ||
namedParameterJdbcTemplate.batchUpdate(sql, getImageToSqlParameterSources(images)); | ||
} | ||
|
||
@Override | ||
public void deleteAll(final List<Image> images) { | ||
final String sql = """ | ||
DELETE FROM image WHERE id IN (:imageIds) | ||
"""; | ||
namedParameterJdbcTemplate.update(sql, getDeletedImageIdsSqlParameterSources(images)); | ||
} | ||
|
||
private SqlParameterSource getDeletedImageIdsSqlParameterSources(final List<Image> images) { | ||
final List<Long> imageIds = images.stream() | ||
.map(Image::getId) | ||
.toList(); | ||
return new MapSqlParameterSource("imageIds", imageIds); | ||
} | ||
|
||
private MapSqlParameterSource[] getImageToSqlParameterSources(final List<Image> images) { | ||
return images.stream() | ||
.map(this::getImageToSqlParameterSource) | ||
.toArray(MapSqlParameterSource[]::new); | ||
} | ||
|
||
private MapSqlParameterSource getImageToSqlParameterSource(final Image image) { | ||
final LocalDateTime now = LocalDateTime.now(); | ||
return new MapSqlParameterSource() | ||
.addValue("createdAt", now) | ||
.addValue("modifiedAt", now) | ||
.addValue("itemId", image.getItem().getId()) | ||
.addValue("name", image.getName()) | ||
.addValue("status", image.getStatus().name()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.