Browse Source

clear code

marinofaggiana 5 years ago
parent
commit
d7541fe501

+ 0 - 1
iOSClient/Library/OCCommunicationLib/OCCommunication.m

@@ -3179,7 +3179,6 @@
 
 - (void)putHCUserProfile:(NSString*)serverPath data:(NSString *)data onCommunication:(OCCommunication *)sharedOCComunication successRequest:(void(^)(NSHTTPURLResponse *response, NSString *redirectedServer))successRequest  failureRequest:(void(^)(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer)) failureRequest {
     
-    data = [data encodeString:NSUTF8StringEncoding];
     serverPath = [serverPath encodeString:NSUTF8StringEncoding];
 
     OCWebDAVClient *request = [[OCWebDAVClient alloc] init];

+ 17 - 8
iOSClient/Networking/NCService.swift

@@ -319,17 +319,26 @@ class NCService: NSObject {
     
     private func requestHC() {
         
-        let professions = CCUtility.getHCBusinessType(appDelegate.activeAccount)
+        let professions = CCUtility.getHCBusinessType("")
         if professions != nil && professions!.count > 0 {
-            
+            OCNetworking.sharedManager()?.putHCUserProfile(withAccount: appDelegate.activeAccount, serverUrl: appDelegate.activeUrl, professions: professions, completion: { (account, message, errorCode) in
+                if errorCode == 0 && account == self.appDelegate.activeAccount {
+                    CCUtility.setHCBusinessType("", professions: nil)
+                    OCNetworking.sharedManager()?.getHCUserProfile(withAccount: self.appDelegate.activeAccount, serverUrl: self.appDelegate.activeUrl, completion: { (account, userProfile, message, errorCode) in
+                        if errorCode == 0 && account == self.appDelegate.activeAccount {
+                            _ = NCManageDatabase.sharedInstance.setAccountUserProfile(userProfile!)
+                        }
+                    })
+                }
+            })
+        } else {
+            OCNetworking.sharedManager()?.getHCUserProfile(withAccount: appDelegate.activeAccount, serverUrl: appDelegate.activeUrl, completion: { (account, userProfile, message, errorCode) in
+                if errorCode == 0 && account == self.appDelegate.activeAccount {
+                    _ = NCManageDatabase.sharedInstance.setAccountUserProfile(userProfile!)
+                }
+            })
         }
         
-        OCNetworking.sharedManager()?.getHCUserProfile(withAccount: appDelegate.activeAccount, serverUrl: appDelegate.activeUrl, completion: { (account, userProfile, message, errorCode) in
-            if errorCode == 0 && account == self.appDelegate.activeAccount {
-                _ = NCManageDatabase.sharedInstance.setAccountUserProfile(userProfile!)
-            }
-        })
-        
         OCNetworking.sharedManager()?.getHCFeatures(withAccount: appDelegate.activeAccount, serverUrl: appDelegate.activeUrl, completion: { (account, features, message, errorCode) in
             if errorCode == 0 && account == self.appDelegate.activeAccount {
             }

+ 1 - 3
iOSClient/Networking/OCNetworking.h

@@ -105,9 +105,7 @@
 #pragma mark ===== Third Parts =====
 
 - (void)getHCUserProfileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl completion:(void (^)(NSString *account, OCUserProfile *userProfile, NSString *message, NSInteger errorCode))completion;
-
-- (void)putHCUserProfileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
-
+- (void)putHCUserProfileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl professions:(NSString *)professions completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion;
 - (void)getHCFeaturesWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl completion:(void (^)(NSString *account, HCFeatures *features, NSString *message, NSInteger errorCode))completion;
 
 @end

+ 6 - 2
iOSClient/Networking/OCNetworking.m

@@ -1992,13 +1992,17 @@
     }];
 }
 
-- (void)putHCUserProfileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
+- (void)putHCUserProfileWithAccount:(NSString *)account serverUrl:(NSString *)serverUrl professions:(NSString *)professions completion:(void (^)(NSString *account, NSString *message, NSInteger errorCode))completion
 {
     tableAccount *tableAccount = [[NCManageDatabase sharedInstance] getAccountWithPredicate:[NSPredicate predicateWithFormat:@"account == %@", account]];
     if (tableAccount == nil) {
         completion(account, NSLocalizedString(@"_error_user_not_available_", nil), k_CCErrorUserNotAvailble);
     }
     
+    // Create JSON
+    NSDictionary *dataDic = @{@"businesstype": professions};
+    NSString *data = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dataDic options:0 error:nil] encoding:NSUTF8StringEncoding];
+
     NSString *serverPath = [NSString stringWithFormat:@"%@/ocs/v2.php/apps/handwerkcloud/api/v1/settings/%@", serverUrl, tableAccount.userID];
     
     OCCommunication *communication = [OCNetworking sharedManager].sharedOCCommunication;
@@ -2006,7 +2010,7 @@
     [communication setCredentialsWithUser:tableAccount.user andUserID:tableAccount.userID andPassword:[CCUtility getPassword:account]];
     [communication setUserAgent:[CCUtility getUserAgent]];
     
-    [communication putHCUserProfile:serverPath data:@"" onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
+    [communication putHCUserProfile:serverPath data:data onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
         
         completion(account, nil, 0);