Skip to content

Commit

Permalink
Merge branch 'develop' into test/DDING-000
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/test/java/ddingdong/ddingdongBE/domain/club/service/FacadeCentralClubServiceImplTest.java
  • Loading branch information
5uhwann committed Nov 30, 2024
2 parents 776a908 + 6497982 commit 4a2893c
Show file tree
Hide file tree
Showing 21 changed files with 305 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dev-server-integrator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: chmod +x gradlew

- name: CI Test
run: ./gradlew clean test
run: ./gradlew clean test --no-build-cache

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
Expand Down
6 changes: 5 additions & 1 deletion compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ services:
- mysql
ports:
- "8080:8080"

mysql:
image: mysql:8.0.33
image: mysql:8.0.40
environment:
MYSQL_DATABASE: ddingdong
MYSQL_ROOT_PASSWORD: ${DEV_DB_PASSWORD}
TZ: Asia/Seoul
ports:
- "3306:3306"
volumes:
- mysql-volume:/var/lib/mysql

volumes:
mysql-volume:
external: true
1 change: 1 addition & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
org.gradle.annotation.processing=true
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static LocalDateTime parseToLocalDateTime(String dateString) {

public static LocalDateTime processDate(String dateString, LocalDateTime currentDate) {
if (dateString == null) {
return currentDate;
return null;
}

if (dateString.isBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public interface DocumentRepository extends JpaRepository<Document, Long> {
value = """
SELECT *
FROM document AS d
WHERE deleted_at IS NULL
ORDER BY d.id DESC
LIMIT :limit
OFFSET :offsetValue
OFFSET :offset
""",
nativeQuery = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "file_meta_data",indexes = {@Index(columnList = "domainType,entityId,fileStatus")})
@SQLDelete(sql = "update file_meta_data set deleted_at = CURRENT_TIMESTAMP where id=?")
@SQLRestriction("deleted_at IS NULL")
@SQLRestriction("file_status != 'DELETED'")
public class FileMetaData extends BaseEntity {

@Id
Expand All @@ -47,9 +44,6 @@ public class FileMetaData extends BaseEntity {
@Enumerated(EnumType.STRING)
private FileCategory fileCategory;

@Column(name = "deleted_at", columnDefinition = "TIMESTAMP")
private LocalDateTime deletedAt;

@Builder
private FileMetaData(UUID id, String fileKey, String fileName, DomainType domainType, Long entityId,
FileStatus fileStatus,
Expand Down Expand Up @@ -81,4 +75,11 @@ public void updateCoupledEntityInfo(DomainType domainType, Long entityId) {
this.entityId = entityId;
}

public boolean isCoupled() {
return this.fileStatus == FileStatus.COUPLED;
}

public boolean isPending() {
return this.fileStatus == FileStatus.PENDING;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,49 @@

public interface FileMetaDataRepository extends JpaRepository<FileMetaData, UUID> {

@Query("select fmd from FileMetaData fmd where fmd.domainType = :domainType and fmd.entityId = :entityId and fmd.fileStatus = :fileStatus")
@Query("""
select fmd from FileMetaData fmd
where fmd.domainType = :domainType
and fmd.entityId = :entityId
and fmd.fileStatus = :fileStatus
and fmd.fileStatus != 'DELETED'
""")
List<FileMetaData> findAllByDomainTypeAndEntityIdWithFileStatus(
@Param("domainType") DomainType domainType,
@Param("entityId") Long entityId,
@Param("fileStatus") FileStatus fileStatus
@Param("domainType") DomainType domainType,
@Param("entityId") Long entityId,
@Param("fileStatus") FileStatus fileStatus
);

List<FileMetaData> findAllByDomainTypeAndEntityId(DomainType domainType, Long entityId);
@Query(value = """
select * from file_meta_data
where domain_type = :#{#domainType.name()}
and entity_id = :entityId
and file_status != 'DELETED'
""", nativeQuery = true)
List<FileMetaData> findAllByDomainTypeAndEntityId(
@Param("domainType") DomainType domainType,
@Param("entityId") Long entityId
);

@Query(value = """
select *
from file_meta_data
where id in (:ids)
and file_status != 'DELETED'
""", nativeQuery = true)
List<FileMetaData> findByIdIn(@Param("ids") List<UUID> ids);

List<FileMetaData> findByIdIn(List<UUID> ids);
@Query("""
select fmd from FileMetaData fmd
where fmd.domainType = :domainType
and fmd.entityId = :entityId
and fmd.fileStatus = :fileStatus
and fmd.fileStatus != 'DELETED'
order by fmd.id asc
""")
List<FileMetaData> findAllByDomainTypeAndEntityIdWithFileStatusOrderedAsc(
@Param("domainType") DomainType domainType,
@Param("entityId") Long entityId,
@Param("fileStatus") FileStatus fileStatus
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public interface FileMetaDataService {

List<FileMetaData> getCoupledAllByDomainTypeAndEntityId(DomainType domainType, Long entityId);

List<FileMetaData> getCoupledAllByDomainTypeAndEntityIdOrderedAsc(DomainType domainType,
Long entityId);

void updateStatusToCoupled(List<String> ids, DomainType domainType, Long entityId);

void updateStatusToCoupled(String id, DomainType domainType, Long entityId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,30 @@ public List<FileMetaData> getCoupledAllByDomainTypeAndEntityId(DomainType domain
return fileMetaDataRepository.findAllByDomainTypeAndEntityIdWithFileStatus(domainType, entityId, COUPLED);
}

@Override
public List<FileMetaData> getCoupledAllByDomainTypeAndEntityIdOrderedAsc(DomainType domainType,
Long entityId) {
return fileMetaDataRepository.findAllByDomainTypeAndEntityIdWithFileStatusOrderedAsc(
domainType, entityId, COUPLED);
}

@Transactional
@Override
public void updateStatusToCoupled(List<String> ids, DomainType domainType, Long entityId) {
if (ids.isEmpty()) {
if (ids == null || ids.isEmpty()) {
return;
}
List<UUID> fileMetaDataId = toUUIDs(ids);
List<FileMetaData> fileMetaDatas = fileMetaDataRepository.findByIdIn(fileMetaDataId);
List<UUID> fileMetaDataIds = toUUIDs(ids);
List<FileMetaData> fileMetaDatas = fileMetaDataRepository.findByIdIn(fileMetaDataIds);
if (ids.size() != fileMetaDatas.size()) {
throw new ResourceNotFound("해당 FileMetaData(id: " + fileMetaDataId + ")를 찾을 수 없습니다.");
throw new ResourceNotFound("해당 FileMetaData(id: " + fileMetaDataIds + ")를 찾을 수 없습니다.");
}
fileMetaDatas.forEach(fileMetaData -> {
fileMetaData.updateCoupledEntityInfo(domainType, entityId);
fileMetaData.updateStatus(COUPLED);
});
fileMetaDatas.stream()
.filter(FileMetaData::isPending)
.forEach(fileMetaData -> {
fileMetaData.updateCoupledEntityInfo(domainType, entityId);
fileMetaData.updateStatus(COUPLED);
});
}

@Transactional
Expand All @@ -60,48 +69,74 @@ public void updateStatusToCoupled(String id, DomainType domainType, Long entityI
return;
}
UUID fileMetaDataId = UUID.fromString(id);
FileMetaData fileMetaData = fileMetaDataRepository.findById(fileMetaDataId).orElse(null);
if (fileMetaData == null) {
throw new ResourceNotFound("해당 FileMetaData(id: " + fileMetaDataId + ")를 찾을 수 없습니다.");
}
FileMetaData fileMetaData = findById(fileMetaDataId);
fileMetaData.updateCoupledEntityInfo(domainType, entityId);
fileMetaData.updateStatus(COUPLED);
}

@Transactional
@Override
public void update(String id, DomainType domainType, Long entityId) {
updateStatusToDelete(domainType, entityId);
if (id == null) {
if (isCoupled(id)) {
return;
}
updateStatusToDelete(domainType, entityId);
updateStatusToCoupled(id, domainType, entityId);
}

@Transactional
@Override
public void update(List<String> ids, DomainType domainType, Long entityId) {
updateStatusToDelete(domainType, entityId);
if (ids == null || ids.isEmpty()) {
updateStatusToDelete(domainType, entityId);
return;
}
updateStatusToCoupled(ids, domainType, entityId);
deleteOldIds(ids, domainType, entityId); //ids에 포함된 id를 가진 fileMetaData외에 전부 제거
List<String> newIds = getNewIds(ids); //기존 id가 아닌 새로운 id 반환
updateStatusToCoupled(newIds, domainType, entityId);
}

@Transactional
@Override
public void updateStatusToDelete(DomainType domainType, Long entityId) {
List<FileMetaData> fileMetaDatas = getCoupledAllByDomainTypeAndEntityId(domainType, entityId);
List<FileMetaData> fileMetaDatas = fileMetaDataRepository.findAllByDomainTypeAndEntityId(domainType, entityId);
fileMetaDatas.forEach(fileMetaData -> {
fileMetaData.updateStatus(DELETED);
entityManager.flush();
fileMetaDataRepository.delete(fileMetaData);
});
}

private List<String> getNewIds(List<String> ids) {
List<FileMetaData> fileMetaDatas = fileMetaDataRepository.findByIdIn(toUUIDs(ids));
return fileMetaDatas.stream()
.filter(FileMetaData::isPending)
.map(fileMetaData -> String.valueOf(fileMetaData.getId()))
.toList();
}

private boolean isCoupled(String id) {
if (id == null) {
return false;
}
FileMetaData fileMetaData = findById(UUID.fromString(id));
return fileMetaData.isCoupled();
}

private void deleteOldIds(List<String> ids, DomainType domainType, Long entityId) {
List<FileMetaData> fileMetaDatas = fileMetaDataRepository.findAllByDomainTypeAndEntityId(domainType, entityId);
List<FileMetaData> deleteTarget = fileMetaDatas.stream()
.filter(fileMetaData -> !ids.contains(String.valueOf(fileMetaData.getId())))
.toList();
deleteTarget.forEach(target -> target.updateStatus(DELETED));
}

private FileMetaData findById(UUID id) {
return fileMetaDataRepository.findById(id)
.orElseThrow(() -> new ResourceNotFound("해당 FileMetaData(id: " + id + ")를 찾을 수 없습니다."));
}

private List<UUID> toUUIDs(List<String> ids) {
return ids.stream()
.map(UUID::fromString)
.toList();
.map(UUID::fromString)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ public record CreateNoticeRequest(
String content,

@Schema(description = "공지사항 이미지 식별자 목록", example = "[\"0192c828-ffce-7ee8-94a8-d9d4c8cdec00\", \"0192c828-ffce-7ee8-94a8-d9d4c8cdec00\"]")
List<String> images,
List<String> imageIds,

@Schema(description = "공지사항 파일 식별자 목록", example = "[\"0192c828-ffce-7ee8-94a8-d9d4c8cdec00\", \"0192c828-ffce-7ee8-94a8-d9d4c8cdec00\"]")
List<String> files
List<String> fileIds
) {

public CreateNoticeCommand toCommand(User user) {
return CreateNoticeCommand.builder()
.user(user)
.title(title)
.content(content)
.images(images)
.files(files)
.imageIds(imageIds)
.fileIds(fileIds)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ public record UpdateNoticeRequest(
String content,

@Schema(description = "공지사항 이미지 식별자 목록", example = "[\"0192c828-ffce-7ee8-94a8-d9d4c8cdec00\", \"0192c828-ffce-7ee8-94a8-d9d4c8cdec00\"]")
List<String> images,
List<String> imageIds,

@Schema(description = "공지사항 파일 식별자 목록", example = "[\"0192c828-ffce-7ee8-94a8-d9d4c8cdec00\", \"0192c828-ffce-7ee8-94a8-d9d4c8cdec00\"]")
List<String> files
List<String> fileIds
) {

public UpdateNoticeCommand toCommand(Long noticeId) {
return UpdateNoticeCommand.builder()
.noticeId(noticeId)
.title(title)
.content(content)
.images(images)
.files(files)
.imageIds(imageIds)
.fileIds(fileIds)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface NoticeRepository extends JpaRepository<Notice, Long> {
value = """
SELECT *
FROM notice AS n
WHERE deleted_at IS NULL
ORDER BY n.id DESC
LIMIT :limit
OFFSET :offsetValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public void create(CreateNoticeCommand command) {
Notice notice = command.toEntity();
Long createdNoticeId = noticeService.save(notice);

fileMetaDataService.updateStatusToCoupled(command.images(), DomainType.NOTICE_IMAGE,
fileMetaDataService.updateStatusToCoupled(command.imageIds(), DomainType.NOTICE_IMAGE,
createdNoticeId);
fileMetaDataService.updateStatusToCoupled(command.files(), DomainType.NOTICE_FILE,
fileMetaDataService.updateStatusToCoupled(command.fileIds(), DomainType.NOTICE_FILE,
createdNoticeId);
}

Expand All @@ -33,9 +33,9 @@ public void update(UpdateNoticeCommand command) {
Notice notice = noticeService.getById(command.noticeId());
notice.update(command.toEntity());

fileMetaDataService.update(command.images(), DomainType.NOTICE_IMAGE,
fileMetaDataService.update(command.imageIds(), DomainType.NOTICE_IMAGE,
command.noticeId());
fileMetaDataService.update(command.files(), DomainType.NOTICE_FILE,
fileMetaDataService.update(command.fileIds(), DomainType.NOTICE_FILE,
command.noticeId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public NoticeQuery getNotice(Long noticeId) {
Notice notice = noticeService.getById(noticeId);

List<UploadedFileUrlQuery> imageUrlQueries = fileMetaDataService
.getCoupledAllByDomainTypeAndEntityId(DomainType.NOTICE_IMAGE, noticeId)
.getCoupledAllByDomainTypeAndEntityIdOrderedAsc(DomainType.NOTICE_IMAGE, noticeId)
.stream()
.map(fileMetaData -> s3FileService.getUploadedFileUrl(fileMetaData.getFileKey()))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public record CreateNoticeCommand(
User user,
String title,
String content,
List<String> images,
List<String> files
List<String> imageIds,
List<String> fileIds
) {

public Notice toEntity() {
Expand Down
Loading

0 comments on commit 4a2893c

Please sign in to comment.