Browse Source

Adicionando endpoint para criação e edição de uma instituição

main
Cauã 1 year ago
parent
commit
892f244897
  1. 3
      .gitignore
  2. 9
      .idea/WPD-Auth.iml
  3. 19
      .idea/compiler.xml
  4. 6
      .idea/encodings.xml
  5. 20
      .idea/jarRepositories.xml
  6. 16
      .idea/misc.xml
  7. 6
      .idea/vcs.xml
  8. 51
      .idea/workspace.xml
  9. 6
      pom.xml
  10. 12
      src/main/java/org/waterproofingdata/wpdauth/controller/UsersController.java
  11. 25
      src/main/java/org/waterproofingdata/wpdauth/service/UsersService.java
  12. 5
      src/main/resources/application.properties

3
.gitignore

@ -10,6 +10,9 @@
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# .env
.env
# Package Files #
*.jar
*.war

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>

19
.idea/compiler.xml

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<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>

16
.idea/misc.xml

@ -0,0 +1,16 @@
<project version="4">
<component name="EntryPointsManager">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="PutMapping" />
</list>
</component>
<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" 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>

51
.idea/workspace.xml

@ -5,19 +5,36 @@
</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$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" 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" />
<change beforePath="$PROJECT_DIR$/src/main/resources/application.properties" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/application.properties" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Interface" />
<option value="AnnotationType" />
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 8
}</component>
<component name="ProjectId" id="2QZB1w4yMqJ44pz7TgaoomMXRlQ" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
@ -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"
}
}]]></component>
<component name="RecentsManager">
<key name="CreateClassDialog.RecentsKey">
<recent name="org.waterproofingdata.wpdauth.service" />
<recent name="org.waterproofingdata.wpdauth.controller" />
</key>
</component>
<component name="RunManager">
<configuration name="WpdauthApplication" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="org.waterproofingdata.wpdauth.WpdauthApplication" />
<module name="wpdauth" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="org.waterproofingdata.wpdauth.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.WpdauthApplication" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">

6
pom.xml

@ -95,6 +95,12 @@
<version>2.8.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

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;
@ -31,6 +33,16 @@ 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')")
@ApiOperation(

25
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;
@ -49,6 +47,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();
userEducemadenOrg.setUsersid(userid);

5
src/main/resources/application.properties

@ -5,9 +5,8 @@ spring.datasource.hikari.maximumPoolSize=5
## PostgreSQL
spring.datasource.url=jdbc:postgresql://localhost:5432/wpdauth
spring.datasource.username=uwpdauth
spring.datasource.password=<password>
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.default_schema=auth
server.port=8080
@ -17,7 +16,7 @@ security.jwt.token.secret-key=<secret-key>
security.jwt.token.expire-length=300000
spring.mail.host=<host>
spring.mail.port=<port>
spring.mail.port=587
spring.mail.username=<username>
spring.mail.password=<password>
spring.mail.properties.mail.smtp.auth=true

Loading…
Cancel
Save