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

5.9 KiB

Plan: Add IsForce Field to Android APK Version Management

Overview

Add support for force update functionality to the Android APK version management system. This allows administrators to specify whether an APK update is mandatory (force update) or optional when uploading new versions. The system now supports two separate APK types: WebView and FaceDetection.

Context

  • The system manages Android APK versions for two different application types
  • Previously, all updates were treated as optional
  • Need to add ability to mark certain updates as mandatory
  • Force update flag should be stored in database and returned via API

Requirements

  1. Add IsForce boolean field to the AndroidApkVersion entity
  2. Allow administrators to specify force update status when uploading APK
  3. Store force update status in database
  4. Return force update status via API endpoint
  5. Separate handling for WebView and FaceDetection APK types

Implementation Steps

1. Domain Layer Updates

  • Add IsForce property to AndroidApkVersion entity
  • Update constructor to accept isForce parameter with default value of false
  • File: Company.Domain/AndroidApkVersionAgg/AndroidApkVersion.cs

2. Database Mapping

  • Add IsForce property mapping in AndroidApkVersionMapping
  • File: CompanyManagment.EFCore/Mapping/AndroidApkVersionMapping.cs

3. Application Layer Updates

  • Update IAndroidApkVersionApplication interface:
    • Add isForce parameter to CreateAndActive method
    • Add isForce parameter to CreateAndDeActive method
    • Remove isForceUpdate parameter from GetLatestActiveInfo method
  • File: CompanyManagment.App.Contracts/AndroidApkVersion/IAndroidApkVersionApplication.cs

4. Application Implementation

  • Update AndroidApkVersionApplication:
    • Pass isForce to AndroidApkVersion constructor in CreateAndActive
    • Pass isForce to AndroidApkVersion constructor in CreateAndDeActive
    • Update GetLatestActiveInfo to return IsForce from database entity instead of parameter
  • File: CompanyManagment.Application/AndroidApkVersionApplication.cs

5. API Controller Updates

  • Update AndroidApkController:
    • Remove force parameter from CheckUpdate endpoint
    • API now returns IsForce from database
  • File: ServiceHost/Areas/Admin/Controllers/AndroidApkController.cs

6. Admin UI Updates

  • Add IsForce property to IndexModel
  • Add checkbox for force update in upload form
  • Pass IsForce value to CreateAndActive method
  • Files:
    • ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs
    • ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml

7. Database Migration (To Be Done)

  • ⚠️ REQUIRED: Create and run migration to add IsForce column to AndroidApkVersions table
  • Command: Add-Migration AddIsForceToAndroidApkVersion
  • Then: Update-Database

API Endpoints

Check for Updates

GET /api/android-apk/check-update?type={ApkType}&currentVersionCode={int}

Parameters:

  • type: Enum value - WebView or FaceDetection
  • currentVersionCode: Current version code of installed app (integer)

Response:

{
  "latestVersionCode": 120,
  "latestVersionName": "1.2.0",
  "shouldUpdate": true,
  "isForceUpdate": false,
  "downloadUrl": "/Apk/Android?type=WebView",
  "releaseNotes": "Bug fixes and improvements"
}

APK Type Separation

The system now fully supports two separate APK types:

  1. WebView: Original web-view based application

    • Stored in: Storage/Apk/Android/GozreshgirWebView/
    • Title format: Gozareshgir-WebView-{version}-{date}
  2. FaceDetection: New face detection application

    • Stored in: Storage/Apk/Android/GozreshgirFaceDetection/
    • Title format: Gozareshgir-FaceDetection-{version}-{date}

Each APK type maintains its own:

  • Version history
  • Active version
  • Force update settings
  • Download endpoint

Usage Examples

Admin Upload with Force Update

  1. Navigate to admin APK upload page
  2. Select APK file
  3. Choose APK type (WebView or FaceDetection)
  4. Check "آپدیت اجباری (Force Update)" if update should be mandatory
  5. Click Upload

Client Check for Update (WebView)

GET /api/android-apk/check-update?type=WebView&currentVersionCode=100

Client Check for Update (FaceDetection)

GET /api/android-apk/check-update?type=FaceDetection&currentVersionCode=50

Testing Checklist

  • Test uploading APK with force update enabled for WebView
  • Test uploading APK with force update disabled for WebView
  • Test uploading APK with force update enabled for FaceDetection
  • Test uploading APK with force update disabled for FaceDetection
  • Verify API returns correct isForceUpdate value for WebView
  • Verify API returns correct isForceUpdate value for FaceDetection
  • Verify only one active version exists per APK type
  • Test migration creates IsForce column correctly
  • Verify existing records default to false for IsForce

Notes

  • Default value for IsForce is false (optional update)
  • When uploading new active APK, all previous active versions of same type are deactivated
  • Each APK type is managed independently
  • Force update flag is stored per version, not globally
  • API returns force update status from the latest active version in database

Files Modified

  1. Company.Domain/AndroidApkVersionAgg/AndroidApkVersion.cs
  2. CompanyManagment.EFCore/Mapping/AndroidApkVersionMapping.cs
  3. CompanyManagment.App.Contracts/AndroidApkVersion/IAndroidApkVersionApplication.cs
  4. CompanyManagment.Application/AndroidApkVersionApplication.cs
  5. ServiceHost/Areas/Admin/Controllers/AndroidApkController.cs
  6. ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs
  7. ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml

Migration Required

⚠️ Important: Don't forget to create and run the database migration to add the IsForce column.