Browse Source

added profile update feature

Rachelle 6 years ago
parent
commit
81bb185b17

+ 3
- 8
MyPassionProject/src/main/java/com/example/demo/Controller/UserController.java View File

@@ -26,14 +26,9 @@ public class UserController {
26 26
     return userService.getUserById(userId);
27 27
   }
28 28
 
29
-  @PutMapping(value = "/users/{userId}/summary")
30
-  public ResponseEntity<User> updateSummary(@RequestBody String newSummary, @PathVariable Long userId){
31
-    return userService.updateUserSummary(newSummary, userId);
32
-  }
33
-
34
-  @PutMapping(value="/users/{userId}/profileName")
35
-  public ResponseEntity<User> updateProfileName(@RequestBody String newName, @PathVariable Long userId){
36
-      return userService.updateUserProfileName(newName,userId);
29
+  @PutMapping(value = "/users/{userId}")
30
+  public ResponseEntity<User> updateSummary(@RequestBody User user, @PathVariable Long userId){
31
+    return userService.updateUserProfile(user, userId);
37 32
   }
38 33
 
39 34
   @DeleteMapping(value="/users/{userId}")

+ 8
- 0
MyPassionProject/src/main/java/com/example/demo/Entity/User.java View File

@@ -43,4 +43,12 @@ public class User {
43 43
     public void setProfileName(String profileName) {
44 44
         this.profileName = profileName;
45 45
     }
46
+
47
+    public String getSummary() {
48
+        return summary;
49
+    }
50
+
51
+    public String getProfileName() {
52
+        return profileName;
53
+    }
46 54
 }

+ 9
- 10
MyPassionProject/src/main/java/com/example/demo/Service/UserService.java View File

@@ -30,16 +30,15 @@ public class UserService {
30 30
     return new ResponseEntity<>(userRepo.findById(id).get(), HttpStatus.CREATED);
31 31
   }
32 32
 
33
-  public ResponseEntity<User> updateUserSummary (String newSummary, Long userId){
34
-    User userToUpdate = userRepo.getOne(userId);
35
-    userToUpdate.setSummary(newSummary);
36
-    return new ResponseEntity<>(userRepo.save(userToUpdate), HttpStatus.OK);
37
-  }
38
-
39
-  public ResponseEntity<User> updateUserProfileName (String newName, Long userId){
40
-    User userToUpdate = userRepo.getOne(userId);
41
-    userToUpdate.setProfileName(newName);
42
-    return new ResponseEntity<>(userRepo.save(userToUpdate), HttpStatus.OK);
33
+  public ResponseEntity<User> updateUserProfile (User user, Long userId){
34
+    User currentUser = userRepo.getOne(userId);
35
+    if(user.getSummary()!=null) {
36
+      currentUser.setSummary(user.getSummary());
37
+    }
38
+    if(user.getProfileName()!=null){
39
+      currentUser.setProfileName(user.getProfileName());
40
+    }
41
+    return new ResponseEntity<>(userRepo.save(currentUser), HttpStatus.OK);
43 42
   }
44 43
 
45 44
   public ResponseEntity deleteUser(Long id) {

+ 6
- 4
MyPassionProjectClient/src/app/app.module.ts View File

@@ -3,16 +3,17 @@ import { ErrorHandler, NgModule } from '@angular/core';
3 3
 import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
4 4
 import { SplashScreen } from '@ionic-native/splash-screen';
5 5
 import { StatusBar } from '@ionic-native/status-bar';
6
-
7 6
 import { MyApp } from './app.component';
8 7
 import {MenuPageModule} from "../pages/menu/menu.module";
9 8
 import { HttpClientModule } from '../../node_modules/@angular/common/http';
10 9
 import { UsersService } from '../providers/users-service';
10
+import { ProfileModalPage } from '../pages/settings/profile-modal';
11 11
 
12 12
 
13 13
 @NgModule({
14 14
   declarations: [
15
-    MyApp
15
+    MyApp,
16
+    ProfileModalPage
16 17
   ],
17 18
   imports: [
18 19
     BrowserModule,
@@ -22,8 +23,9 @@ import { UsersService } from '../providers/users-service';
22 23
   ],
23 24
   bootstrap: [IonicApp],
24 25
   entryComponents: [
25
-    MyApp
26
-  ],
26
+    MyApp,
27
+    ProfileModalPage,
28
+   ],
27 29
   providers: [
28 30
     StatusBar,
29 31
     SplashScreen,

+ 0
- 7
MyPassionProjectClient/src/pages/friends/friends.ts View File

@@ -1,13 +1,6 @@
1 1
 import { Component } from '@angular/core';
2 2
 import {IonicPage, NavController, NavParams, ToastController} from 'ionic-angular';
3 3
 
4
-/**
5
- * Generated class for the FriendsPage page.
6
- *
7
- * See https://ionicframework.com/docs/components/#navigation for more info on
8
- * Ionic pages and navigation.
9
- */
10
-
11 4
 @IonicPage()
12 5
 @Component({
13 6
   selector: 'page-friends',

+ 0
- 1
MyPassionProjectClient/src/pages/game-search/game-search.ts View File

@@ -11,7 +11,6 @@ export class GameSearchPage {
11 11
     game: any;
12 12
     searchResult: any;
13 13
     searchTerm: '';
14
-    userName: any;
15 14
 
16 15
   constructor(public navCtrl: NavController, public navParams: NavParams, public toastCtrl: ToastController, public bggGames: BggGameSearch) {
17 16
   }

+ 5
- 5
MyPassionProjectClient/src/pages/menu/menu.ts View File

@@ -21,16 +21,16 @@ export interface PageInterface {
21 21
 export class MenuPage {
22 22
   // Basic root for our content view
23 23
   rootPage = 'TabsPage';
24
-  userName: String;
25 24
 
26 25
   // Reference to the app's root nav
27 26
   @ViewChild(Nav) nav: Nav;
28 27
 
29 28
   pages: PageInterface[] = [
30 29
     { title: 'Home', pageName: 'TabsPage', tabComponent: 'ProfilePage', index: 0, icon: 'home' },
31
-    { title: 'Games', pageName: 'TabsPage', tabComponent: 'GamesPage', index: 1, icon: 'search' },
32
-    { title: 'Game Search', pageName: 'TabsPage', tabComponent: 'GameSearchPage', index: 1, icon: 'search' },
33
-    { title: 'Friends', pageName: 'TabsPage', tabComponent: 'FriendsPage', index: 2, icon: 'contacts' },
30
+    { title: 'MyGames', pageName: 'TabsPage', tabComponent: 'GamesPage', index: 1, icon: 'search' },
31
+    { title: 'Game Search', pageName: 'TabsPage', tabComponent: 'GameSearchPage', index: 2, icon: 'search' },
32
+    { title: 'Friends', pageName: 'TabsPage', tabComponent: 'FriendsPage', index: 3, icon: 'contacts' },
33
+    { title: 'Settings', pageName: 'SettingsPage', icon: 'search' },
34 34
   ];
35 35
 
36 36
   constructor(public navCtrl: NavController) {
@@ -41,7 +41,7 @@ export class MenuPage {
41 41
 
42 42
     // The index is equal to the order of our tabs inside tabs.ts
43 43
     if (page.index) {
44
-      params = { tabIndex: page.index, userName: this.userName };
44
+      params = { tabIndex: page.index };
45 45
     }
46 46
 
47 47
     // The active child nav is our Tabs Navigation

+ 1
- 1
MyPassionProjectClient/src/pages/profile/profile.module.ts View File

@@ -5,7 +5,7 @@ import { UsersService } from '../../providers/users-service';
5 5
 
6 6
 @NgModule({
7 7
   declarations: [
8
-    ProfilePage,
8
+    ProfilePage
9 9
   ],
10 10
   imports: [
11 11
     IonicPageModule.forChild(ProfilePage),

+ 1
- 1
MyPassionProjectClient/src/pages/profile/profile.ts View File

@@ -11,7 +11,7 @@ export class ProfilePage {
11 11
   user: any;
12 12
 
13 13
   constructor(public navCtrl: NavController, public navParams: NavParams, public usersService: UsersService) {
14
-    this.user = this.usersService.getUserById().subscribe(user=>this.user = user);  
14
+    this.user = this.usersService.getUserProfile().subscribe(user=>this.user = user);  
15 15
     console.log(this.user);
16 16
   }
17 17
 

+ 30
- 0
MyPassionProjectClient/src/pages/settings/profile-modal.html View File

@@ -0,0 +1,30 @@
1
+<ion-header>
2
+
3
+        <ion-navbar>
4
+          <ion-title>Update Profile</ion-title>
5
+          <ion-buttons end>
6
+                <button ion-button (click)="dismiss()">
7
+                    <span ion-text showWhen="ios,core">Cancel</span>
8
+                    <ion-icon name="md-close" showWhen="android,windows"></ion-icon>
9
+                </button>
10
+            </ion-buttons>
11
+        </ion-navbar>
12
+      
13
+      </ion-header>   
14
+      <ion-content padding>
15
+        <form (submit)=updateProfile()>
16
+          <ion-list>
17
+            <ion-item>
18
+              <ion-label stacked>Profile Name</ion-label>
19
+              <ion-input type="text" [(ngModel)]="user.profileName" name="profilename"></ion-input>
20
+            </ion-item>
21
+            <ion-item>
22
+                <ion-label stacked>Summary</ion-label>
23
+                <ion-textarea type="text" [(ngModel)]="user.summary" name="summary"></ion-textarea>
24
+            </ion-item>
25
+            <div padding>
26
+                <button ion-button color="primary" block clear>Update</button>
27
+            </div>
28
+          </ion-list>
29
+        </form>
30
+      </ion-content>

+ 34
- 0
MyPassionProjectClient/src/pages/settings/profile-modal.ts View File

@@ -0,0 +1,34 @@
1
+import { ViewChild, Component } from "../../../node_modules/@angular/core";
2
+import { UsersService } from "../../providers/users-service";
3
+import {ViewController, ToastController, NavController} from 'ionic-angular';
4
+
5
+@Component({
6
+    templateUrl: './profile-modal.html'
7
+  })
8
+export class ProfileModalPage {
9
+    user: any;
10
+
11
+    constructor(public viewCtrl: ViewController, public toastCtrl: ToastController, public usersService: UsersService, public navCtrl: NavController) {
12
+        this.user = this.usersService.getUserProfile().subscribe(user=>this.user = user);
13
+    } 
14
+    
15
+    updateProfile() {
16
+        console.log(this.user);
17
+        this.usersService.updateProfile(this.user).subscribe(response => {
18
+            let toast = this.toastCtrl.create({
19
+                message: 'Profile updated.',
20
+                duration: 2000
21
+              });
22
+            toast.present();
23
+            this.dismiss();
24
+          }) 
25
+      }
26
+    
27
+      ionViewDidLoad() {
28
+      }
29
+    
30
+      dismiss() {
31
+        this.viewCtrl.dismiss();
32
+      }
33
+    
34
+}

+ 15
- 0
MyPassionProjectClient/src/pages/settings/settings.html View File

@@ -0,0 +1,15 @@
1
+<ion-header>
2
+    <ion-navbar>
3
+      <ion-title>Settings</ion-title>
4
+    </ion-navbar>
5
+  </ion-header>
6
+  <ion-content padding>
7
+      <ion-list>
8
+          <button ion-item (click)="updateProfile()">
9
+            Update Profile
10
+          </button>  
11
+      </ion-list>
12
+  </ion-content>
13
+
14
+
15
+    

+ 14
- 0
MyPassionProjectClient/src/pages/settings/settings.module.ts View File

@@ -0,0 +1,14 @@
1
+import { NgModule } from '@angular/core';
2
+import { IonicPageModule } from 'ionic-angular';
3
+import { SettingsPage } from './settings';
4
+import { ProfileModalPage } from './profile-modal';
5
+
6
+@NgModule({
7
+  declarations: [
8
+    SettingsPage,
9
+  ],
10
+  imports: [
11
+    IonicPageModule.forChild(SettingsPage),
12
+  ],
13
+})
14
+export class SettingsPageModule {}

+ 3
- 0
MyPassionProjectClient/src/pages/settings/settings.scss View File

@@ -0,0 +1,3 @@
1
+page-settings {
2
+
3
+}

+ 24
- 0
MyPassionProjectClient/src/pages/settings/settings.ts View File

@@ -0,0 +1,24 @@
1
+import { Component } from '@angular/core';
2
+import { IonicPage, NavController, NavParams, ModalController } from 'ionic-angular';
3
+import { ProfileModalPage } from './profile-modal';
4
+
5
+@IonicPage()
6
+@Component({
7
+  selector: 'page-settings',
8
+  templateUrl: 'settings.html',
9
+})
10
+export class SettingsPage {
11
+
12
+  constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController) {
13
+  }
14
+
15
+  ionViewDidLoad() {
16
+    console.log('ionViewDidLoad SettingsPage');
17
+  }
18
+    
19
+  updateProfile() {
20
+    let modal = this.modalCtrl.create(ProfileModalPage);
21
+    modal.present();
22
+  }
23
+
24
+}

+ 2
- 2
MyPassionProjectClient/src/pages/tabs/tabs.html View File

@@ -1,6 +1,6 @@
1 1
 <ion-tabs>
2 2
     <ion-tab [root]="profileRoot" tabTitle="Home" tabIcon="home"></ion-tab>
3
-    <ion-tab [root]="gamesRoot" tabTitle="Games" tabIcon="search"></ion-tab>
4
-    <ion-tab [root]="gameSearchRoot" tabTitle="GameSearch" tabIcon="search"></ion-tab>
3
+    <ion-tab [root]="gamesRoot" tabTitle="MyGames" tabIcon="search"></ion-tab>
4
+    <ion-tab [root]="gameSearchRoot" tabTitle="Game Search" tabIcon="search"></ion-tab>
5 5
     <ion-tab [root]="friendsRoot" tabTitle="Friends" tabIcon="contacts"></ion-tab>
6 6
 </ion-tabs>

+ 8
- 5
MyPassionProjectClient/src/providers/users-service.ts View File

@@ -11,10 +11,6 @@ export class UsersService{
11 11
   constructor(public http: HttpClient){
12 12
   }
13 13
 
14
-  getUserById() {
15
-      return this.http.get(this.USERS_API+"/1")
16
-  }
17
-
18 14
   addUser(account): Observable<any>{
19 15
    this.setUser(account);
20 16
     return this.http.post(this.USERS_API,account);
@@ -22,6 +18,13 @@ export class UsersService{
22 18
 
23 19
   setUser(account){
24 20
     this.userName = account.userName;
25
-    console.log(this.userName);
21
+  }
22
+
23
+  updateProfile(profile): Observable<any>{
24
+    return this.http.put(this.USERS_API + "/1", profile);
25
+  }
26
+
27
+  getUserProfile(){
28
+    return this.http.get(this.USERS_API+"/1")
26 29
   }
27 30
 }