Skip to content

Commit

Permalink
archive status lookup return string instead of enum to int
Browse files Browse the repository at this point in the history
  • Loading branch information
shukriadams committed Oct 18, 2024
1 parent 4f59dc9 commit 075c5d2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/Tetrifact.Core/ArchiveProgressInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;

using Newtonsoft.Json.Converters;
using System;
using System.Text.Json.Serialization;

namespace Tetrifact.Core
{
/// <summary>
Expand All @@ -25,6 +27,7 @@ public class ArchiveProgressInfo
/// <summary>
///
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public PackageArchiveCreationStates State { get;set;}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Tetrifact.Core/ArchiveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public ArchiveProgressInfo GetPackageArchiveStatus(string packageId)
if (!_fileSystem.File.Exists(archiveQueuePath))
return new ArchiveProgressInfo
{
State = PackageArchiveCreationStates.Processed_ArchiveNotAvailableNotGenerated
State = PackageArchiveCreationStates.Processed_ArchiveNotGenerated
};

string progressCacheKey = this.GetArchiveProgressKey(packageId);
Expand Down
17 changes: 11 additions & 6 deletions src/Tetrifact.Core/IArchiveService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Tetrifact.Core
public interface IArchiveService
{
/// <summary>
/// Generates an archive for the given package id, sychronously. Returns when archive is generated. This method is exposed for testing purposes only, and must not tamper with archive queue.
/// Generates an archive for the given package id, synchronously. Returns when archive is generated. This method is exposed for testing purposes only, and must not tamper with archive queue.
/// Normally it will be called from CreateNextQueuedArchive().
/// </summary>
/// <param name="packageId"></param>
Expand Down Expand Up @@ -40,11 +40,6 @@ public interface IArchiveService
/// <summary>
/// Returns a status code the given archive. Requesting status for a given archive will also start
/// generating that archive.
/// 0 : Archive creation was started.
/// 1 : Archive is already started, is still in progress.
/// 2 : Archive is available for download.
///
/// throw a PackageNotFoundException if the package does not exist or is marked for delete
/// </summary>
/// <returns></returns>
ArchiveProgressInfo GetPackageArchiveStatus(string packageId);
Expand All @@ -65,8 +60,18 @@ public interface IArchiveService
/// <returns></returns>
string GetPackageArchivePath(string packageId);

/// <summary>
/// Returns a memcache key at which archive progress object is stored at.
/// </summary>
/// <param name="packageId"></param>
/// <returns></returns>
string GetArchiveProgressKey(string packageId);

/// <summary>
/// Returns the absolute path an archive queue file is stored at.
/// </summary>
/// <param name="packageId"></param>
/// <returns></returns>
string GetPackageArchiveQueuePath(string packageId);
}
}
4 changes: 2 additions & 2 deletions src/Tetrifact.Core/PackageArchiveCreationStates.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace Tetrifact.Core
{
public enum PackageArchiveCreationStates
public enum PackageArchiveCreationStates
{
Queued,
ArchiveGenerating,
Processed_PackageNotFound,
Processed_ArchiveAvailable,
Processed_ArchiveNotAvailableNotGenerated,
Processed_ArchiveNotGenerated,
Processed_CleanupRequired
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void GetArchiveStarted()
.Returns(false);

IArchiveService archiveService = MoqHelper.CreateInstanceWithDependencies<Core.ArchiveService>(new object[] { indexReader, filesystem });
Assert.Equal(PackageArchiveCreationStates.Processed_ArchiveNotAvailableNotGenerated, archiveService.GetPackageArchiveStatus("any-package-id").State);
Assert.Equal(PackageArchiveCreationStates.Processed_ArchiveNotGenerated, archiveService.GetPackageArchiveStatus("any-package-id").State);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Tetrifact.Web/Views/Shared/ArchiveProgress.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@{
// TODO :simply this if statement
}
@if (Model == null || Model.State == PackageArchiveCreationStates.Processed_ArchiveNotAvailableNotGenerated || Model.State == PackageArchiveCreationStates.Processed_ArchiveAvailable || Model.State == PackageArchiveCreationStates.Processed_CleanupRequired)
@if (Model == null || Model.State == PackageArchiveCreationStates.Processed_ArchiveNotGenerated || Model.State == PackageArchiveCreationStates.Processed_ArchiveAvailable || Model.State == PackageArchiveCreationStates.Processed_CleanupRequired)
{
<a class="button button-header" href="/v1/archives/@packageId">&#10515; Download</a>
}
Expand Down

0 comments on commit 075c5d2

Please sign in to comment.