From 892f24489758344e6e4c370446386468c8252614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=A3?= Date: Sat, 9 Dec 2023 08:40:55 -0300 Subject: [PATCH] =?UTF-8?q?Adicionando=20endpoint=20para=20cria=C3=A7?= =?UTF-8?q?=C3=A3o=20e=20edi=C3=A7=C3=A3o=20de=20uma=20institui=C3=A7?= =?UTF-8?q?=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++ .idea/WPD-Auth.iml | 9 ++++ .idea/compiler.xml | 19 +++++++ .idea/encodings.xml | 6 +++ .idea/jarRepositories.xml | 20 ++++++++ .idea/misc.xml | 16 ++++++ .idea/vcs.xml | 6 +++ .idea/workspace.xml | 51 +++++++++++++++++-- pom.xml | 10 +++- .../wpdauth/controller/UsersController.java | 14 ++++- .../wpdauth/service/UsersService.java | 25 +++++++-- src/main/resources/application.properties | 7 ++- 12 files changed, 173 insertions(+), 13 deletions(-) create mode 100644 .idea/WPD-Auth.iml create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index c836fce..1f24632 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ # Mobile Tools for Java (J2ME) .mtj.tmp/ +# .env +.env + # Package Files # *.jar *.war diff --git a/.idea/WPD-Auth.iml b/.idea/WPD-Auth.iml new file mode 100644 index 0000000..18ec59d --- /dev/null +++ b/.idea/WPD-Auth.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..9e4d601 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..4140949 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..a468a99 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c99d05a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..9661ac7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 0a77e75..25ff725 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,19 +5,36 @@ - + + + + + + + + + + { + "associatedIndex": 8 +} @@ -29,14 +46,42 @@ "RunOnceActivity.OpenProjectViewOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true", "WebServerToolWindowFactoryState": "false", - "last_opened_file_path": "/Users/diegopajaritograjales/PycharmProjects/WPD-Auth", + "git-widget-placeholder": "main", + "last_opened_file_path": "C:/xampp/htdocs/java-wpd-auth/WPD-Auth", "node.js.detected.package.eslint": "true", "node.js.detected.package.tslint": "true", "node.js.selected.package.eslint": "(autodetect)", "node.js.selected.package.tslint": "(autodetect)", - "nodejs_package_manager_path": "npm" + "nodejs_package_manager_path": "npm", + "settings.editor.selected.configurable": "reference.settings.project.maven.repository.indices" } }]]> + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 14a1474..e17f236 100644 --- a/pom.xml +++ b/pom.xml @@ -94,8 +94,14 @@ gson 2.8.5 provided - - + + + org.jetbrains + annotations + 24.1.0 + compile + + diff --git a/src/main/java/org/waterproofingdata/wpdauth/controller/UsersController.java b/src/main/java/org/waterproofingdata/wpdauth/controller/UsersController.java index 0ab8aac..9da0c7c 100644 --- a/src/main/java/org/waterproofingdata/wpdauth/controller/UsersController.java +++ b/src/main/java/org/waterproofingdata/wpdauth/controller/UsersController.java @@ -8,10 +8,12 @@ import org.waterproofingdata.wpdauth.dto.UsersResponseDTO; import org.waterproofingdata.wpdauth.model.Users; import org.waterproofingdata.wpdauth.service.UsersService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -30,6 +32,16 @@ import io.swagger.annotations.Authorization; public class UsersController { @Autowired private UsersService userService; + + @PutMapping("/update") + public ResponseEntity editUser(@RequestBody Users updatedUser) { + Users editedUser = userService.editUser(updatedUser); + if (editedUser != null) { + return ResponseEntity.ok(editedUser); + } else { + return ResponseEntity.notFound().build(); + } + } @GetMapping(value = "/{id}") @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_INSTITUTION') or hasRole('ROLE_CLIENT')") @@ -156,7 +168,7 @@ public class UsersController { ) { return userService.signup(CustomMapper.map(user, Users.class)); } - + @PostMapping("/activate") @PreAuthorize("hasRole('ROLE_INSTITUTION') or hasRole('ROLE_CLIENT')") @ApiOperation( diff --git a/src/main/java/org/waterproofingdata/wpdauth/service/UsersService.java b/src/main/java/org/waterproofingdata/wpdauth/service/UsersService.java index 307b346..ec917d0 100644 --- a/src/main/java/org/waterproofingdata/wpdauth/service/UsersService.java +++ b/src/main/java/org/waterproofingdata/wpdauth/service/UsersService.java @@ -1,14 +1,12 @@ package org.waterproofingdata.wpdauth.service; -import java.util.List; -import java.util.Optional; import java.util.UUID; import javax.servlet.http.HttpServletRequest; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.mail.javamail.JavaMailSender; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.AuthenticationException; @@ -48,6 +46,27 @@ public class UsersService { @Autowired private AuthenticationManager authenticationManager; + + public Users editUser(@NotNull Users updatedUser) { + Users existingUser = usersRepository.findById(updatedUser.getId()).orElse(null); + if (existingUser != null) { + existingUser.setNickname(updatedUser.getNickname()); + existingUser.setDateofborn(updatedUser.getDateofborn()); + existingUser.setGender(updatedUser.getGender()); + existingUser.setState(updatedUser.getState()); + existingUser.setCity(updatedUser.getCity()); + existingUser.setInstitutiontype(updatedUser.getInstitutiontype()); + existingUser.setInstitution(updatedUser.getInstitution()); + existingUser.setSecurityquestion(updatedUser.getSecurityquestion()); + existingUser.setSecurityanswer(updatedUser.getSecurityanswer()); + existingUser.setTermsofusage(updatedUser.getTermsofusage()); + existingUser.setAvatar(updatedUser.getAvatar()); + existingUser.setActive(updatedUser.getActive()); + + return usersRepository.save(existingUser); + } + return null; + } private void addNewUsersEducemadenOrganization(Integer userid, Integer educemadenorganizationsid, UUID uuid_activationkey, Roles role) { UsersEducemadenOrganizations userEducemadenOrg = new UsersEducemadenOrganizations(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 02e19ea..ed55c87 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,10 +5,9 @@ spring.datasource.hikari.maximumPoolSize=5 ## PostgreSQL spring.datasource.url=jdbc:postgresql://localhost:5432/wpdauth spring.datasource.username=uwpdauth -spring.datasource.password= +spring.datasource.password=root -spring.jpa.hibernate.ddl-auto=none -spring.jpa.properties.hibernate.default_schema=auth +spring.jpa.properties.hibernate.default_schema=auth server.port=8080 @@ -17,7 +16,7 @@ security.jwt.token.secret-key= security.jwt.token.expire-length=300000 spring.mail.host= -spring.mail.port= +spring.mail.port=587 spring.mail.username= spring.mail.password= spring.mail.properties.mail.smtp.auth=true