Files
Backend-Api/plan-addApkTypeToAndroidApkVersion.prompt.md

7.6 KiB

Plan: Add ApkType to AndroidApkVersion for WebView and FaceDetection separation

Overview

The user wants to integrate the ApkType enum (WebView/FaceDetection) into the AndroidApkVersion entity to distinguish between the two different APK types. Currently, all APKs are treated as WebView. The system needs to be updated to support both types with separate handling.

Steps

1. Update AndroidApkVersion.cs domain entity

File: Company.Domain\AndroidApkVersionAgg\AndroidApkVersion.cs

  • Add ApkType property to the class
  • Update constructor to accept ApkType parameter
  • Modify Title property generation to include APK type information
  • Update the constructor logic to handle both WebView and FaceDetection types

2. Update AndroidApkVersionMapping.cs EF configuration

File: CompanyManagment.EFCore\Mapping\AndroidApkVersionMapping.cs

  • Add mapping configuration for ApkType property
  • Use enum-to-string conversion (similar to existing IsActive mapping)
  • Set appropriate column max length for the enum value

3. Create database migration

Files: Generated migration files in CompanyManagment.EFCore\Migrations\

  • Generate new migration to add ApkType column to AndroidApkVersions table
  • Set default value to ApkType.WebView for existing records
  • Apply migration to update database schema

4. Update IAndroidApkVersionRepository.cs interface

File: Company.Domain\AndroidApkVersionAgg\IAndroidApkVersionRepository.cs

  • Modify GetActives() to accept ApkType parameter for filtering
  • Modify GetLatestActiveVersionPath() to accept ApkType parameter
  • Add methods to handle type-specific queries

5. Update AndroidApkVersionRepository.cs implementation

File: CompanyManagment.EFCore\Repository\AndroidApkVersionRepository.cs

  • Implement type-based filtering in GetActives() method
  • Implement type-based filtering in GetLatestActiveVersionPath() method
  • Add appropriate WHERE clauses to filter by ApkType

6. Update IAndroidApkVersionApplication.cs interface

File: CompanyManagment.App.Contracts\AndroidApkVersion\IAndroidApkVersionApplication.cs

  • Add ApkType parameter to CreateAndActive() method
  • Add ApkType parameter to CreateAndDeActive() method
  • Add ApkType parameter to GetLatestActiveVersionPath() method
  • Add ApkType parameter to HasAndroidApkToDownload() method

7. Update AndroidApkVersionApplication.cs implementation

File: CompanyManagment.Application\AndroidApkVersionApplication.cs

  • Update CreateAndActive() method:

    • Accept ApkType parameter
    • Change storage path from hardcoded "GozreshgirWebView" to dynamic based on type
    • Use "GozreshgirWebView" for ApkType.WebView
    • Use "GozreshgirFaceDetection" for ApkType.FaceDetection
    • Pass ApkType to repository methods when getting/deactivating existing APKs
    • Pass ApkType to entity constructor
  • Update CreateAndDeActive() method:

    • Accept ApkType parameter
    • Update storage path logic similar to CreateAndActive()
    • Pass ApkType to entity constructor
  • Update GetLatestActiveVersionPath() method:

    • Accept ApkType parameter
    • Pass type to repository method
  • Update HasAndroidApkToDownload() method:

    • Accept ApkType parameter
    • Filter by type when checking for active APKs

8. Update AndroidApk.cs controller

File: ServiceHost\Pages\Apk\AndroidApk.cs

  • Modify the download endpoint to accept ApkType parameter
  • Options:
    • Add query string parameter: /Apk/Android?type=WebView or /Apk/Android?type=FaceDetection
    • Create separate routes: /Apk/Android/WebView and /Apk/Android/FaceDetection
  • Pass the type parameter to GetLatestActiveVersionPath() method
  • Maintain backward compatibility by defaulting to ApkType.WebView if no type specified

9. Update admin UI Index.cshtml.cs

File: ServiceHost\Areas\AdminNew\Pages\Company\AndroidApk\Index.cshtml.cs

  • Add property to store selected ApkType
  • Add [BindProperty] for ApkType selection
  • Modify OnPostUpload() to pass selected ApkType to application method
  • Create corresponding UI changes in Index.cshtml (if exists) to allow type selection

10. Update client-facing pages

Files:

  • ServiceHost\Pages\login\Index.cshtml.cs

  • ServiceHost\Areas\Client\Pages\Index.cshtml.cs

  • Update calls to HasAndroidApkToDownload() to specify which APK type to check

  • Consider showing different download buttons/links for WebView vs FaceDetection apps

  • Update download links to include APK type parameter

Migration Strategy

Handling Existing Data

  • All existing AndroidApkVersion records should be marked as ApkType.WebView by default
  • Use migration to set default value
  • No manual data update required if migration includes default value

Database Schema Change

ALTER TABLE AndroidApkVersions 
ADD ApkType NVARCHAR(20) NOT NULL DEFAULT 'WebView';

UI Design Considerations

Admin Upload Page

Recommended approach: Single form with radio buttons or dropdown

  • Add radio buttons or dropdown to select APK type before upload
  • Labels: "WebView Application" and "Face Detection Application"
  • Group uploads by type in the list/table view
  • Show type column in the APK list

Client Download Pages

Recommended approach: Separate download buttons

  • Show "Download Gozareshgir WebView" button (existing functionality)
  • Show "Download Gozareshgir FaceDetection" button (new functionality)
  • Only show buttons if corresponding APK type is available
  • Use different icons or colors to distinguish between types

Download URL Structure

Recommended approach: Single endpoint with query parameter

  • Current: /Apk/Android (defaults to WebView for backward compatibility)
  • New WebView: /Apk/Android?type=WebView
  • New FaceDetection: /Apk/Android?type=FaceDetection

Alternative approach: Separate endpoints

  • /Apk/Android/WebView
  • /Apk/Android/FaceDetection

Testing Checklist

  1. Upload WebView APK successfully
  2. Upload FaceDetection APK successfully
  3. Both types can coexist in database
  4. Activating WebView APK doesn't affect FaceDetection APK
  5. Activating FaceDetection APK doesn't affect WebView APK
  6. Download correct APK based on type parameter
  7. Admin UI shows type information correctly
  8. Client pages show correct download availability
  9. Backward compatibility maintained (existing links still work)
  10. Migration applies successfully to existing database

File Summary

Files to modify:

  1. Company.Domain\AndroidApkVersionAgg\AndroidApkVersion.cs
  2. CompanyManagment.EFCore\Mapping\AndroidApkVersionMapping.cs
  3. Company.Domain\AndroidApkVersionAgg\IAndroidApkVersionRepository.cs
  4. CompanyManagment.EFCore\Repository\AndroidApkVersionRepository.cs
  5. CompanyManagment.App.Contracts\AndroidApkVersion\IAndroidApkVersionApplication.cs
  6. CompanyManagment.Application\AndroidApkVersionApplication.cs
  7. ServiceHost\Pages\Apk\AndroidApk.cs
  8. ServiceHost\Areas\AdminNew\Pages\Company\AndroidApk\Index.cshtml.cs
  9. ServiceHost\Pages\login\Index.cshtml.cs
  10. ServiceHost\Areas\Client\Pages\Index.cshtml.cs

Files to create:

  1. New migration file (auto-generated)
  2. Possibly ServiceHost\Areas\AdminNew\Pages\Company\AndroidApk\Index.cshtml (if doesn't exist)

Notes

  • The ApkType enum is already defined in AndroidApkVersion.cs
  • Storage folders will be separate: Storage/Apk/Android/GozreshgirWebView and Storage/Apk/Android/GozreshgirFaceDetection
  • Each APK type maintains its own active/inactive state independently
  • Consider adding validation to ensure APK file matches selected type (optional enhancement)