From 48a261bbf9b6ac0f8b46c0e2880fec0183653929 Mon Sep 17 00:00:00 2001 From: Ilias Mentzelos Date: Sun, 30 Sep 2018 01:17:44 +0300 Subject: [PATCH] Settings page Create settings page where users can change their email and password. Throw error if something fails. Fix csv issues --- database_files/User.csv | 2 +- src/main/client/src/app/app-routing.module.ts | 2 + src/main/client/src/app/app.module.ts | 7 +++- .../app/layout/navbar/navbar.component.html | 3 ++ .../app/shared/settings/email-change.model.ts | 9 +++++ .../shared/settings/password-change.model.ts | 13 +++++++ .../app/shared/settings/settings.service.ts | 22 +++++++++++ .../converter/NotificationConverter.java | 37 ++++++++++--------- .../linkedin/dataentry/DatabaseCsvReader.java | 15 +++++--- 9 files changed, 84 insertions(+), 26 deletions(-) create mode 100644 src/main/client/src/app/shared/settings/email-change.model.ts create mode 100644 src/main/client/src/app/shared/settings/password-change.model.ts create mode 100644 src/main/client/src/app/shared/settings/settings.service.ts diff --git a/database_files/User.csv b/database_files/User.csv index e28716c..40c4b64 100644 --- a/database_files/User.csv +++ b/database_files/User.csv @@ -62,7 +62,7 @@ Id,Name,Surname,Email,Username,Birthdate,DateCreated,Address,PhoneNumber 70,Glori,Snadden,gsnadden1p@1688.com,gsnadden1p,5/29/2018,3/1/2018,86 Spohn Trail,104-865-7034 71,Jaymee,Bayns,jbayns1q@upenn.edu,jbayns1q,12/27/2017,7/30/2018,67105 Twin Pines Hill,568-814-2856 72,Giustina,Wilstead,gwilstead1r@usatoday.com,gwilstead1r,5/2/2018,6/4/2018,3340 Ronald Regan Lane,890-787-5413 -73 ,LeilaStar ,Bruneton ,lbruneton1s@cdc.gov ,lbruneton1s ,5/19/2018 ,10/8/2017 ,3952 Karstens Lane ,252-315-0574 +73 ,LeilaStar ,Bruneton ,lbruneton1s@cdc.gov ,lbruneton1s ,5/19/2018 ,10/8/2017 ,3952 KarstensLane ,252-315-0574 74,Rudolf,Hargraves,rhargraves1t@t-online.de,rhargraves1t,2/18/2018,6/6/2018,43 Pond Street,739-541-4640 75,Edsel,McMechan,emcmechan1u@kickstarter.com,emcmechan1u,10/10/2017,5/10/2018,0 Corscot Road,646-704-5446 76,Dorita,Mathes,dmathes1v@homestead.com,dmathes1v,9/23/2017,11/24/2017,391 Stone Corner Hill,438-619-3889 diff --git a/src/main/client/src/app/app-routing.module.ts b/src/main/client/src/app/app-routing.module.ts index 124fa92..2dbcf97 100644 --- a/src/main/client/src/app/app-routing.module.ts +++ b/src/main/client/src/app/app-routing.module.ts @@ -14,6 +14,7 @@ import {ConversationComponent} from "./chat/conversation/conversation.component" import {ConversationResolver} from "./chat/conversation/conversation.resolver"; import {AdminComponent} from "./admin/admin.component"; import {AdminResolver} from "./admin/admin.resolver"; +import {SettingsComponent} from "./settings/settings.component"; const appRoutes: Routes = [ {path: '', component: HomeComponent, canActivate: [AuthGuard], children: [ @@ -21,6 +22,7 @@ const appRoutes: Routes = [ {path: '', component: NewsfeedComponent, pathMatch: 'full'}, {path: 'connections/:id', component: ConnectionsComponent, pathMatch: 'full'}, {path: 'jobs', component: JobsComponent, pathMatch: 'full'}, + {path: 'settings', component: SettingsComponent, pathMatch: 'full'}, {path: 'admin', component: AdminComponent, pathMatch: 'full', resolve: {users: AdminResolver}}, { path: 'messages', component: ChatComponent, children: [ diff --git a/src/main/client/src/app/app.module.ts b/src/main/client/src/app/app.module.ts index cf53cf3..fbe1edb 100644 --- a/src/main/client/src/app/app.module.ts +++ b/src/main/client/src/app/app.module.ts @@ -23,6 +23,7 @@ import {ExperienceComponent} from './profile/experience/experience.component'; import {EducationComponent} from './profile/education/education.component'; import { AccordionModule, + AlertModule, BsDatepickerModule, BsDropdownModule, BsModalRef, @@ -80,6 +81,8 @@ import {ApplicantsComponent} from "./jobs/applicants/applicants.component"; import {PostCommentComponent} from "./profile/posts/post-comments/post-comments.component"; import {AdminComponent} from './admin/admin.component'; import {AdminResolver} from "./admin/admin.resolver"; +import {SettingsComponent} from './settings/settings.component'; +import {SettingsService} from "./shared/settings/settings.service"; @NgModule({ @@ -121,6 +124,7 @@ import {AdminResolver} from "./admin/admin.resolver"; ChatComponent, ConversationComponent, AdminComponent, + SettingsComponent, ], imports: [ BrowserModule, @@ -136,6 +140,7 @@ import {AdminResolver} from "./admin/admin.resolver"; BsDropdownModule.forRoot(), AccordionModule.forRoot(), TabsModule.forRoot(), + AlertModule.forRoot(), BrowserAnimationsModule, MatCheckboxModule, MatTableModule, @@ -160,7 +165,7 @@ import {AdminResolver} from "./admin/admin.resolver"; providers: [ Globals, AuthGuard, AuthService, RepoService, UserService, JobService, NotificationService, MessageService, EducationService, ExperienceService, SkillService, LikeService, ConnectionService, - PostService, CommentService, BsModalRef, FileUploadService, + PostService, CommentService, BsModalRef, FileUploadService, SettingsService, EducationResolver, ProfileResolver, SkillsResolver, ExperienceResolver, PostsResolver, MyFriendsResolver, UserFriendsResolver, ConversationResolver, AdminResolver, { diff --git a/src/main/client/src/app/layout/navbar/navbar.component.html b/src/main/client/src/app/layout/navbar/navbar.component.html index bf3cfe5..4c7f66d 100644 --- a/src/main/client/src/app/layout/navbar/navbar.component.html +++ b/src/main/client/src/app/layout/navbar/navbar.component.html @@ -34,6 +34,9 @@ [routerLink]="['/profile', username]" title="My Account"> Avatar + +
diff --git a/src/main/client/src/app/shared/settings/email-change.model.ts b/src/main/client/src/app/shared/settings/email-change.model.ts new file mode 100644 index 0000000..05785b1 --- /dev/null +++ b/src/main/client/src/app/shared/settings/email-change.model.ts @@ -0,0 +1,9 @@ +import {FormGroup} from "@angular/forms"; + +export class EmailChange { + newEmail: string; + + constructor(form: FormGroup) { + this.newEmail = form.get('newEmail').value; + } +} diff --git a/src/main/client/src/app/shared/settings/password-change.model.ts b/src/main/client/src/app/shared/settings/password-change.model.ts new file mode 100644 index 0000000..30d399c --- /dev/null +++ b/src/main/client/src/app/shared/settings/password-change.model.ts @@ -0,0 +1,13 @@ +import {FormGroup} from "@angular/forms"; + +export class PasswordChange { + oldPassword: string; + newPassword: string; + newPasswordRepeat: string; + + constructor(form: FormGroup) { + this.oldPassword = form.get('oldPassword').value; + this.newPassword = form.get('newPassword').value; + this.newPasswordRepeat = form.get('newPasswordRepeat').value; + } +} diff --git a/src/main/client/src/app/shared/settings/settings.service.ts b/src/main/client/src/app/shared/settings/settings.service.ts new file mode 100644 index 0000000..fee107e --- /dev/null +++ b/src/main/client/src/app/shared/settings/settings.service.ts @@ -0,0 +1,22 @@ +import {Injectable} from "@angular/core"; +import {RepoService} from "../repo/repo.service"; +import {EmailChange} from "./email-change.model"; +import {PasswordChange} from "./password-change.model"; + +@Injectable() +export class SettingsService { + constructor(private repoService: RepoService) { + } + + updateEmail(dto: EmailChange) { + this.repoService.put("profile/change-email/", dto) + .subscribe(() => { + }, error => console.log(error)); + } + + updatePassword(dto: PasswordChange) { + this.repoService.put("profile/change-pass/", dto) + .subscribe(() => { + }, error => console.log(error)); + } +} diff --git a/src/main/java/com/linkedin/converter/NotificationConverter.java b/src/main/java/com/linkedin/converter/NotificationConverter.java index d4e4cdf..c64aa82 100644 --- a/src/main/java/com/linkedin/converter/NotificationConverter.java +++ b/src/main/java/com/linkedin/converter/NotificationConverter.java @@ -1,6 +1,7 @@ package com.linkedin.converter; import com.linkedin.entities.database.Notification; +import com.linkedin.entities.database.User; import com.linkedin.entities.database.repo.UserRepository; import com.linkedin.entities.model.notifications.NotificationDto; import org.springframework.beans.factory.annotation.Autowired; @@ -8,26 +9,26 @@ @Component public class NotificationConverter { - private final UserRepository userRepository; - private final UserConverter userConverter; + private final UserRepository userRepository; + private final UserConverter userConverter; - @Autowired - public NotificationConverter(UserRepository userRepository, UserConverter userConverter){ + @Autowired + public NotificationConverter(UserRepository userRepository, UserConverter userConverter) { - this.userRepository = userRepository; - this.userConverter = userConverter; - } + this.userRepository = userRepository; + this.userConverter = userConverter; + } - public NotificationDto toNotificationDto(Notification notification){ - NotificationDto notificationDto = new NotificationDto(); - notificationDto.setMessage(notification.getMessage()); - notificationDto.setNotificationId(notification.getNotificationId()); - notificationDto.setStatus(notification.getStatus()); - notificationDto.setType(notification.getType()); - notificationDto.setUser( userConverter.toUserSimpleDto( userRepository.findById(notification.getUserId()).orElse(null) )); - notificationDto.setTargetUserId(notification.getTargetUserId()); - notificationDto.setLikeCommentConnectionId(notification.getLikeCommentConnectionId()); + public NotificationDto toNotificationDto(Notification notification) { + NotificationDto notificationDto = new NotificationDto(); + notificationDto.setMessage(notification.getMessage()); + notificationDto.setNotificationId(notification.getNotificationId()); + notificationDto.setStatus(notification.getStatus()); + notificationDto.setType(notification.getType()); + notificationDto.setUser(userConverter.toUserSimpleDto(userRepository.findById(notification.getUserId()).orElse(new User()))); + notificationDto.setTargetUserId(notification.getTargetUserId()); + notificationDto.setLikeCommentConnectionId(notification.getLikeCommentConnectionId()); - return notificationDto; - } + return notificationDto; + } } diff --git a/src/main/java/com/linkedin/dataentry/DatabaseCsvReader.java b/src/main/java/com/linkedin/dataentry/DatabaseCsvReader.java index 15446ce..f065a11 100644 --- a/src/main/java/com/linkedin/dataentry/DatabaseCsvReader.java +++ b/src/main/java/com/linkedin/dataentry/DatabaseCsvReader.java @@ -34,18 +34,21 @@ */ @Component public class DatabaseCsvReader { - private final String[] FILE_ARRAY = new String[]{"database_files/Login.csv", "database_files/Notification.csv", - "database_files/Job.csv", "database_files/Connection.csv", "database_files/User.csv", + private final String[] FILE_ARRAY = new String[]{"database_files/Login.csv", + "database_files/Notification.csv", + "database_files/Job.csv", "database_files/Connection.csv", + "database_files/User.csv", "database_files/Post.csv", "database_files/Comment.csv", "database_files/Like.csv", - "database_files/ConnectionRequest.csv", "database_files/Message.csv" + "database_files/ConnectionRequest.csv", + "database_files/Message.csv" }; private final String ENTITIES_PACKAGE_NAME = "com.linkedin.entities.database"; private final Repositories repositories; - public final static SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - - public final static SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + public static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); + + public static final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); @Autowired public DatabaseCsvReader(ListableBeanFactory listableBeanFactory) {