5.9 KiB
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
- Add
IsForceboolean field to theAndroidApkVersionentity - Allow administrators to specify force update status when uploading APK
- Store force update status in database
- Return force update status via API endpoint
- Separate handling for WebView and FaceDetection APK types
Implementation Steps
1. Domain Layer Updates
- ✅ Add
IsForceproperty toAndroidApkVersionentity - ✅ Update constructor to accept
isForceparameter with default value offalse - ✅ File:
Company.Domain/AndroidApkVersionAgg/AndroidApkVersion.cs
2. Database Mapping
- ✅ Add
IsForceproperty mapping inAndroidApkVersionMapping - ✅ File:
CompanyManagment.EFCore/Mapping/AndroidApkVersionMapping.cs
3. Application Layer Updates
- ✅ Update
IAndroidApkVersionApplicationinterface:- Add
isForceparameter toCreateAndActivemethod - Add
isForceparameter toCreateAndDeActivemethod - Remove
isForceUpdateparameter fromGetLatestActiveInfomethod
- Add
- ✅ File:
CompanyManagment.App.Contracts/AndroidApkVersion/IAndroidApkVersionApplication.cs
4. Application Implementation
- ✅ Update
AndroidApkVersionApplication:- Pass
isForcetoAndroidApkVersionconstructor inCreateAndActive - Pass
isForcetoAndroidApkVersionconstructor inCreateAndDeActive - Update
GetLatestActiveInfoto returnIsForcefrom database entity instead of parameter
- Pass
- ✅ File:
CompanyManagment.Application/AndroidApkVersionApplication.cs
5. API Controller Updates
- ✅ Update
AndroidApkController:- Remove
forceparameter fromCheckUpdateendpoint - API now returns
IsForcefrom database
- Remove
- ✅ File:
ServiceHost/Areas/Admin/Controllers/AndroidApkController.cs
6. Admin UI Updates
- ✅ Add
IsForceproperty toIndexModel - ✅ Add checkbox for force update in upload form
- ✅ Pass
IsForcevalue toCreateAndActivemethod - ✅ Files:
ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.csServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml
7. Database Migration (To Be Done)
- ⚠️ REQUIRED: Create and run migration to add
IsForcecolumn toAndroidApkVersionstable - Command:
Add-Migration AddIsForceToAndroidApkVersion - Then:
Update-Database
API Endpoints
Check for Updates
GET /api/android-apk/check-update?type={ApkType}¤tVersionCode={int}
Parameters:
type: Enum value -WebVieworFaceDetectioncurrentVersionCode: 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:
-
WebView: Original web-view based application
- Stored in:
Storage/Apk/Android/GozreshgirWebView/ - Title format:
Gozareshgir-WebView-{version}-{date}
- Stored in:
-
FaceDetection: New face detection application
- Stored in:
Storage/Apk/Android/GozreshgirFaceDetection/ - Title format:
Gozareshgir-FaceDetection-{version}-{date}
- Stored in:
Each APK type maintains its own:
- Version history
- Active version
- Force update settings
- Download endpoint
Usage Examples
Admin Upload with Force Update
- Navigate to admin APK upload page
- Select APK file
- Choose APK type (WebView or FaceDetection)
- Check "آپدیت اجباری (Force Update)" if update should be mandatory
- Click Upload
Client Check for Update (WebView)
GET /api/android-apk/check-update?type=WebView¤tVersionCode=100
Client Check for Update (FaceDetection)
GET /api/android-apk/check-update?type=FaceDetection¤tVersionCode=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
isForceUpdatevalue for WebView - Verify API returns correct
isForceUpdatevalue for FaceDetection - Verify only one active version exists per APK type
- Test migration creates
IsForcecolumn correctly - Verify existing records default to
falseforIsForce
Notes
- Default value for
IsForceisfalse(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
Company.Domain/AndroidApkVersionAgg/AndroidApkVersion.csCompanyManagment.EFCore/Mapping/AndroidApkVersionMapping.csCompanyManagment.App.Contracts/AndroidApkVersion/IAndroidApkVersionApplication.csCompanyManagment.Application/AndroidApkVersionApplication.csServiceHost/Areas/Admin/Controllers/AndroidApkController.csServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.csServiceHost/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.