Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.callv2.drive.domain.member.QuotaUnit;

public record CreateRequestQuotaInput(String memberId, Long ammount, QuotaUnit unit) {
public record CreateRequestQuotaInput(String memberId, Long amount, QuotaUnit unit) {

public static CreateRequestQuotaInput of(String memberId, Long amount, QuotaUnit unit) {
return new CreateRequestQuotaInput(memberId, amount, unit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void execute(final CreateRequestQuotaInput input) {
.orElseThrow(() -> NotFoundException.with(Member.class, input.memberId()));

final Notification notification = Notification.create();
notification.validate(() -> member.requestQuota(Quota.of(input.ammount(), input.unit())));
notification.validate(() -> member.requestQuota(Quota.of(input.amount(), input.unit())));

if (notification.hasError())
throw ValidationException.with("Request Quota Error", notification);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.callv2.drive.application.member.quota.retrieve.summary;

import com.callv2.drive.domain.file.FileGateway;
import com.callv2.drive.domain.member.MemberGateway;

public class DefaultGetQuotasSummaryUseCase extends GetQuotasSummaryUseCase {

private final MemberGateway memberGateway;
private final FileGateway fileGateway;

public DefaultGetQuotasSummaryUseCase(
final MemberGateway memberGateway,
final FileGateway fileGateway) {
this.memberGateway = memberGateway;
this.fileGateway = fileGateway;
}

@Override
public GetQuotasSummaryOutput execute() {

final Long totalMembers = this.memberGateway.count();
final Long totalAllocatedQuota = this.memberGateway.sumAllQuota();
final Long totalUsedStorage = this.fileGateway.sumAllContentSize();

return new GetQuotasSummaryOutput(
totalMembers,
totalAllocatedQuota,
totalUsedStorage,
totalAllocatedQuota - totalUsedStorage);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.callv2.drive.application.member.quota.retrieve.summary;

public record GetQuotasSummaryOutput(
Long membersCount,
Long totalAllocatedQuota,
Long totalUsedQuota,
Long totalAvailableQuota) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.callv2.drive.application.member.quota.retrieve.summary;

import com.callv2.drive.application.NullaryUseCase;

public abstract class GetQuotasSummaryUseCase extends NullaryUseCase<GetQuotasSummaryOutput> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public interface FileGateway {

void deleteById(FileID id);

Long sumAllContentSize();

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public interface MemberGateway {

Member create(Member member);

Long count();

Page<Member> findAll(SearchQuery searchQuery);

Optional<Member> findById(MemberID id);
Expand All @@ -19,4 +21,6 @@ public interface MemberGateway {

Boolean existsById(MemberID id);

Long sumAllQuota();

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
@RequestMapping("members")
public interface MemberAPI {

@Operation(summary = "Request drive quota", description = "This method request a drive ammount quota", security = @SecurityRequirement(name = "bearerAuth"))
@Operation(summary = "Request drive quota", description = "This method request a drive amount quota", security = @SecurityRequirement(name = "bearerAuth"))
@ApiResponse(responseCode = "204", description = "Requested successfuly")
@ApiResponse(responseCode = "404", description = "Member not found", content = @Content(schema = @Schema(implementation = Void.class)))
@PostMapping("quotas/requests/{amount}")
ResponseEntity<Void> requestQuota(
@PathVariable(value = "amount", required = true) long amount,
@RequestParam(value = "unit", defaultValue = "GIGABYTE") QuotaUnit unit);

@Operation(summary = "Retrieve actual drive quota", description = "This method retrieve a drive ammount quota", security = @SecurityRequirement(name = "bearerAuth"))
@Operation(summary = "Retrieve actual drive quota", description = "This method retrieve a drive amount quota", security = @SecurityRequirement(name = "bearerAuth"))
@ApiResponse(responseCode = "200", description = "Retrieve successfuly")
@ApiResponse(responseCode = "404", description = "Member not found", content = @Content(schema = @Schema(implementation = Void.class)))
@GetMapping("quotas")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.callv2.drive.infrastructure.member.model.MemberQuotaListResponse;
import com.callv2.drive.infrastructure.member.model.MemberQuotaResponse;
import com.callv2.drive.infrastructure.member.model.QuotaRequestListResponse;
import com.callv2.drive.infrastructure.member.model.QuotaSummaryResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -28,13 +29,13 @@
@RequestMapping("admin/members")
public interface MemberAdminAPI {

@Operation(summary = "Request drive quota", description = "This method request a drive ammount quota", security = @SecurityRequirement(name = "bearerAuth"))
@Operation(summary = "Request drive quota", description = "This method request a drive amount quota", security = @SecurityRequirement(name = "bearerAuth"))
@ApiResponse(responseCode = "200", description = "Retrieve successfuly")
@ApiResponse(responseCode = "404", description = "Member not found", content = @Content(schema = @Schema(implementation = Void.class)))
@GetMapping("{id}/quotas")
ResponseEntity<MemberQuotaResponse> getQuota(@PathVariable(value = "id", required = true) String id);

@Operation(summary = "Approve drive quota request", description = "This method approve a drive ammount quota request", security = @SecurityRequirement(name = "bearerAuth"))
@Operation(summary = "Approve drive quota request", description = "This method approve a drive amount quota request", security = @SecurityRequirement(name = "bearerAuth"))
@ApiResponse(responseCode = "204", description = "Approved successfuly")
@ApiResponse(responseCode = "404", description = "Member not found", content = @Content(schema = @Schema(implementation = Void.class)))
@PatchMapping("{id}/quotas/requests")
Expand Down Expand Up @@ -66,4 +67,10 @@ ResponseEntity<Page<MemberQuotaListResponse>> listQuotas(
@RequestParam(name = "filterOperator", required = false, defaultValue = "AND") Filter.Operator filterOperator,
@RequestParam(name = "filters", required = false) List<String> filters);

@Operation(summary = "Get quota summary", description = "Returns an aggregated summary of quotas, including total allocated quota, used quota, available quota, and total members.", security = @SecurityRequirement(name = "bearerAuth"))
@ApiResponse(responseCode = "200", description = "Quota summary retrieved successfully", content = @Content(schema = @Schema(implementation = QuotaSummaryResponse.class)))
@ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content(schema = @Schema(implementation = ApiError.class)))
@GetMapping("quotas/summary")
ResponseEntity<QuotaSummaryResponse> quotaSummary();

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.callv2.drive.application.member.quota.retrieve.get.GetQuotaInput;
import com.callv2.drive.application.member.quota.retrieve.get.GetQuotaUseCase;
import com.callv2.drive.application.member.quota.retrieve.list.ListQuotasUseCase;
import com.callv2.drive.application.member.quota.retrieve.summary.GetQuotasSummaryUseCase;
import com.callv2.drive.domain.pagination.Filter;
import com.callv2.drive.domain.pagination.Filter.Operator;
import com.callv2.drive.domain.pagination.Page;
Expand All @@ -22,6 +23,7 @@
import com.callv2.drive.infrastructure.member.model.MemberQuotaListResponse;
import com.callv2.drive.infrastructure.member.model.MemberQuotaResponse;
import com.callv2.drive.infrastructure.member.model.QuotaRequestListResponse;
import com.callv2.drive.infrastructure.member.model.QuotaSummaryResponse;
import com.callv2.drive.infrastructure.member.presenter.MemberPresenter;

@Controller
Expand All @@ -31,16 +33,19 @@ public class MemberAdminController implements MemberAdminAPI {
private final ListRequestQuotaUseCase listRequestQuotaUseCase;
private final GetQuotaUseCase getQuotaUseCase;
private final ListQuotasUseCase listQuotasUseCase;
private final GetQuotasSummaryUseCase getQuotasSummaryUseCase;

public MemberAdminController(
final ApproveRequestQuotaUseCase approveRequestQuotaUseCase,
final ListRequestQuotaUseCase listRequestQuotaUseCase,
final GetQuotaUseCase getQuotaUseCase,
final ListQuotasUseCase listQuotasUseCase) {
final ListQuotasUseCase listQuotasUseCase,
final GetQuotasSummaryUseCase getQuotasSummaryUseCase) {
this.approveRequestQuotaUseCase = approveRequestQuotaUseCase;
this.listRequestQuotaUseCase = listRequestQuotaUseCase;
this.getQuotaUseCase = getQuotaUseCase;
this.listQuotasUseCase = listQuotasUseCase;
this.getQuotasSummaryUseCase = getQuotasSummaryUseCase;
}

@Override
Expand Down Expand Up @@ -94,4 +99,9 @@ public ResponseEntity<Page<MemberQuotaListResponse>> listQuotas(

}

@Override
public ResponseEntity<QuotaSummaryResponse> quotaSummary() {
return ResponseEntity.ok(MemberPresenter.present(getQuotasSummaryUseCase.execute()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.callv2.drive.application.member.quota.retrieve.get.GetQuotaUseCase;
import com.callv2.drive.application.member.quota.retrieve.list.DefaultListQuotasUseCase;
import com.callv2.drive.application.member.quota.retrieve.list.ListQuotasUseCase;
import com.callv2.drive.application.member.quota.retrieve.summary.DefaultGetQuotasSummaryUseCase;
import com.callv2.drive.application.member.quota.retrieve.summary.GetQuotasSummaryUseCase;
import com.callv2.drive.application.member.synchronize.DefaultSynchronizeMemberUseCase;
import com.callv2.drive.application.member.synchronize.SynchronizeMemberUseCase;
import com.callv2.drive.domain.file.FileGateway;
Expand Down Expand Up @@ -59,4 +61,9 @@ ListQuotasUseCase listQuotasUseCase() {
return new DefaultListQuotasUseCase(memberGateway);
}

@Bean
GetQuotasSummaryUseCase getQuotasSummaryUseCase() {
return new DefaultGetQuotasSummaryUseCase(memberGateway, fileGateway);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ public void deleteById(final FileID id) {
this.fileRepository.deleteById(id.getValue());
}

@Override
public Long sumAllContentSize() {
return this.fileRepository.sumAllContentSize();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface FileJpaRepository extends JpaRepository<FileJpaEntity, UUID> {

Expand All @@ -16,4 +17,7 @@ public interface FileJpaRepository extends JpaRepository<FileJpaEntity, UUID> {

List<FileJpaEntity> findByOwnerId(String ownerId);

@Query("select coalesce(sum(f.contentSize), 0) from File f")
Long sumAllContentSize();

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public Member create(final Member member) {
return this.memberJpaRepository.save(MemberJpaEntity.fromDomain(member)).toDomain();
}

@Override
public Long count() {
return memberJpaRepository.count();
}

@Override
public Page<Member> findAll(SearchQuery searchQuery) {

Expand Down Expand Up @@ -83,9 +88,9 @@ public Member update(final Member member) {
memberJpa.getId(),
memberJpa.getUsername(),
memberJpa.getNickname(),
memberJpa.getQuotaAmmount(),
memberJpa.getQuotaAmount(),
memberJpa.getQuotaUnit(),
memberJpa.getQuotaRequestAmmount(),
memberJpa.getQuotaRequestAmount(),
memberJpa.getQuotaRequestUnit(),
memberJpa.getQuotaRequestedAt(),
memberJpa.getCreatedAt(),
Expand Down Expand Up @@ -118,4 +123,9 @@ public Boolean existsById(MemberID id) {
return this.memberJpaRepository.existsById(id.getValue());
}

@Override
public Long sumAllQuota() {
return this.memberJpaRepository.sumAllQuota();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.callv2.drive.infrastructure.member.model;

public record QuotaSummaryResponse(
Long membersCount,
Long totalAllocatedQuota,
Long totalUsedQuota,
Long totalAvailableQuota) {

}
Loading