Browse Source

Implementing editing functionality for the institution endpoint.

main
Cauã 1 year ago
parent
commit
4df4093432
  1. 9
      .idea/WPD-Auth.iml
  2. 18
      .idea/compiler.xml
  3. 6
      .idea/encodings.xml
  4. 20
      .idea/jarRepositories.xml
  5. 11
      .idea/misc.xml
  6. 6
      .idea/vcs.xml
  7. 11
      .idea/workspace.xml
  8. 9
      pom.xml
  9. 12
      src/main/java/org/waterproofingdata/wpdauth/controller/UsersController.java
  10. 22
      src/main/java/org/waterproofingdata/wpdauth/service/UsersService.java

9
.idea/WPD-Auth.iml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

18
.idea/compiler.xml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="wpdauth" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="wpdauth" options="-parameters" />
</option>
</component>
</project>

6
.idea/encodings.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
</component>
</project>

20
.idea/jarRepositories.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>

11
.idea/misc.xml

@ -0,0 +1,11 @@
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" default="true" project-jdk-name="16" project-jdk-type="JavaSDK" />
</project>

6
.idea/vcs.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

11
.idea/workspace.xml

@ -5,7 +5,10 @@
</component>
<component name="ChangeListManager">
<list default="true" id="e096f643-4c6b-4769-84b8-63aa85cd1521" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/db/ddl.sql" beforeDir="false" afterPath="$PROJECT_DIR$/db/ddl.sql" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/waterproofingdata/wpdauth/controller/UsersController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/waterproofingdata/wpdauth/controller/UsersController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/org/waterproofingdata/wpdauth/service/UsersService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/org/waterproofingdata/wpdauth/service/UsersService.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -18,6 +21,9 @@
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 0
}]]></component>
<component name="ProjectId" id="2QZB1w4yMqJ44pz7TgaoomMXRlQ" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
@ -29,7 +35,8 @@
"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-PR/WPD-Auth",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",

9
pom.xml

@ -94,8 +94,13 @@
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>provided</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.1.0</version>
</dependency>
</dependencies>
<build>

12
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<Users> 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')")

22
src/main/java/org/waterproofingdata/wpdauth/service/UsersService.java

@ -6,6 +6,7 @@ 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;
@ -48,6 +49,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();

Loading…
Cancel
Save