-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
130 additions
and
17 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
8 changes: 8 additions & 0 deletions
8
...java/site/timecapsulearchive/core/domain/group/repository/GroupInviteQueryRepository.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,8 @@ | ||
package site.timecapsulearchive.core.domain.group.repository; | ||
|
||
import java.util.List; | ||
|
||
public interface GroupInviteQueryRepository { | ||
|
||
void bulkSave(final Long groupOwnerId, final List<Long> groupMemberIds); | ||
} |
48 changes: 48 additions & 0 deletions
48
.../site/timecapsulearchive/core/domain/group/repository/GroupInviteQueryRepositoryImpl.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,48 @@ | ||
package site.timecapsulearchive.core.domain.group.repository; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
import java.sql.Timestamp; | ||
import java.sql.Types; | ||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.jdbc.core.BatchPreparedStatementSetter; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class GroupInviteQueryRepositoryImpl implements GroupInviteQueryRepository { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
@Override | ||
public void bulkSave(Long groupOwnerId, List<Long> groupMemberIds) { | ||
jdbcTemplate.batchUpdate( | ||
""" | ||
INSERT INTO group_invite ( | ||
group_invite_id, group_owner_id, group_member_id, created_at, updated_at | ||
) values (?, ?, ?, ?, ?) | ||
""", | ||
new BatchPreparedStatementSetter() { | ||
|
||
@Override | ||
public void setValues(final PreparedStatement ps, final int i) throws SQLException { | ||
final Long groupMember = groupMemberIds.get(i); | ||
ps.setNull(1, Types.BIGINT); | ||
ps.setLong(2, groupOwnerId); | ||
ps.setLong(3, groupMember); | ||
ps.setTimestamp(4, Timestamp.valueOf(ZonedDateTime.now().toLocalDateTime())); | ||
ps.setTimestamp(5, Timestamp.valueOf(ZonedDateTime.now().toLocalDateTime())); | ||
} | ||
|
||
@Override | ||
public int getBatchSize() { | ||
return groupMemberIds.size(); | ||
} | ||
} | ||
); | ||
} | ||
|
||
} |
6 changes: 4 additions & 2 deletions
6
...main/java/site/timecapsulearchive/core/domain/group/repository/GroupInviteRepository.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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package site.timecapsulearchive.core.domain.group.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.repository.Repository; | ||
import site.timecapsulearchive.core.domain.group.entity.GroupInvite; | ||
|
||
public interface GroupInviteRepository extends JpaRepository<GroupInvite, Long> { | ||
public interface GroupInviteRepository extends Repository<GroupInvite, Long>, | ||
GroupInviteQueryRepository { | ||
|
||
void save(GroupInvite groupInvite); | ||
} | ||
|
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
20 changes: 20 additions & 0 deletions
20
backend/core/src/main/resources/db/migration/V25__group_invite_update.sql
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,20 @@ | ||
alter table group_invite | ||
drop foreign key fk_group_invite_member_id; | ||
|
||
alter table group_invite | ||
drop column member_id; | ||
|
||
|
||
ALTER TABLE group_invite | ||
ADD COLUMN group_owner_id BIGINT; | ||
ALTER TABLE group_invite | ||
ADD COLUMN group_member_id BIGINT; | ||
|
||
ALTER TABLE group_invite | ||
ADD CONSTRAINT fk_group_invite_group_owner_id FOREIGN KEY (group_owner_id) REFERENCES member (member_id); | ||
|
||
ALTER TABLE group_invite | ||
ADD CONSTRAINT fk_group_invite_group_member_id FOREIGN KEY (group_member_id) REFERENCES member (member_id); | ||
|
||
ALTER TABLE group_invite | ||
ADD CONSTRAINT unique_owner_member_pair UNIQUE (group_owner_id, group_member_id); |