Update API parameters

This commit is contained in:
Vishnu Mohandas 2020-08-01 02:56:53 +05:30
parent 54daebf096
commit e1cf0706f3
7 changed files with 25 additions and 15 deletions

View file

@ -7,6 +7,7 @@ class Configuration {
static const _endpointKey = "endpoint_7";
static const _tokenKey = "token";
static const _usernameKey = "username";
static const _userIDKey = "user_id";
static const _passwordKey = "password";
SharedPreferences _preferences;
@ -46,6 +47,14 @@ class Configuration {
await _preferences.setString(_usernameKey, username);
}
int getUserID() {
return _preferences.getInt(_userIDKey);
}
void setUserID(int userID) async {
await _preferences.setInt(_userIDKey, userID);
}
String getPassword() {
return _preferences.getString(_passwordKey);
}

View file

@ -14,7 +14,7 @@ class FoldersDB {
static final columnId = 'id';
static final columnName = 'name';
static final columnOwner = 'owner';
static final columnOwnerID = 'owner_id';
static final columnDeviceFolder = 'device_folder';
static final columnSharedWith = 'shared_with';
static final columnUpdationTime = 'updation_time';
@ -41,11 +41,11 @@ class FoldersDB {
CREATE TABLE $table (
$columnId INTEGER PRIMARY KEY NOT NULL,
$columnName TEXT NOT NULL,
$columnOwner TEXT NOT NULL,
$columnOwnerID INTEGER NOT NULL,
$columnDeviceFolder TEXT NOT NULL,
$columnSharedWith TEXT NOT NULL,
$columnUpdationTime INTEGER NOT NULL,
UNIQUE($columnOwner, $columnDeviceFolder)
UNIQUE($columnOwnerID, $columnDeviceFolder)
)
''');
}
@ -86,7 +86,7 @@ class FoldersDB {
final row = new Map<String, dynamic>();
row[columnId] = folder.id;
row[columnName] = folder.name;
row[columnOwner] = folder.owner;
row[columnOwnerID] = folder.ownerID;
row[columnDeviceFolder] = folder.deviceFolder;
row[columnSharedWith] = jsonEncode(folder.sharedWith.toList());
row[columnUpdationTime] = folder.updationTime;
@ -97,7 +97,7 @@ class FoldersDB {
return Folder(
row[columnId],
row[columnName],
row[columnOwner],
row[columnOwnerID],
row[columnDeviceFolder],
(jsonDecode(row[columnSharedWith]) as List<dynamic>)
.cast<String>()

View file

@ -45,7 +45,7 @@ class FolderSharingService {
}
}
for (final folder in folders) {
if (folder.owner != Configuration.instance.getUsername()) {
if (folder.ownerID != Configuration.instance.getUserID()) {
await syncDiff(folder);
await FoldersDB.instance.putFolder(folder);
}
@ -136,7 +136,7 @@ class FolderSharingService {
return Folder(
null,
Configuration.instance.getUsername() + "s " + deviceFolder,
Configuration.instance.getUsername(),
Configuration.instance.getUserID(),
deviceFolder,
Set<String>(),
null,

View file

@ -24,7 +24,7 @@ class File {
File();
File.fromJson(Map<String, dynamic> json) {
uploadedFileId = json["fileID"];
uploadedFileId = json["id"];
localId = json["deviceFileID"];
deviceFolder = json["deviceFolder"];
title = json["title"];

View file

@ -5,7 +5,7 @@ import 'package:photos/models/file.dart';
class Folder {
final int id;
final String name;
final String owner;
final int ownerID;
final String deviceFolder;
final Set<String> sharedWith;
final int updationTime;
@ -14,7 +14,7 @@ class Folder {
Folder(
this.id,
this.name,
this.owner,
this.ownerID,
this.deviceFolder,
this.sharedWith,
this.updationTime,
@ -25,8 +25,8 @@ class Folder {
return Folder(
map['id'],
map['owner'] + "'s " + map['deviceFolder'],
map['owner'],
map['name'],
map['ownerID'],
map['deviceFolder'],
Set<String>.from(map['sharedWith']),
map['updationTime'],
@ -35,14 +35,14 @@ class Folder {
@override
String toString() {
return 'Folder(id: $id, name: $name, owner: $owner, deviceFolder: $deviceFolder, sharedWith: $sharedWith, updationTime: $updationTime)';
return 'Folder(id: $id, name: $name, ownerID: $ownerID, deviceFolder: $deviceFolder, sharedWith: $sharedWith, updationTime: $updationTime)';
}
Map<String, dynamic> toMap() {
return {
'id': id,
'name': name,
'owner': owner,
'ownerID': ownerID,
'deviceFolder': deviceFolder,
'sharedWith': sharedWith.toList(),
'updationTime': updationTime,

View file

@ -78,7 +78,7 @@ class _RemoteFolderGalleryWidgetState extends State<RemoteFolderGalleryWidget> {
final folders = await FoldersDB.instance.getFolders();
final filteredFolders = List<Folder>();
for (final folder in folders) {
if (folder.owner == Configuration.instance.getUsername()) {
if (folder.ownerID == Configuration.instance.getUserID()) {
continue;
}
try {

View file

@ -24,6 +24,7 @@ class UserAuthenticator {
if (response.statusCode == 200 && response.data != null) {
Configuration.instance.setUsername(username);
Configuration.instance.setPassword(password);
Configuration.instance.setUserID(response.data["id"]);
Configuration.instance.setToken(response.data["token"]);
Bus.instance.fire(UserAuthenticatedEvent());
return true;