Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrum 46 #26

Merged
merged 21 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
43369b2
chore: add dependencies for passford validation
AnnaUgrai Jul 6, 2024
305ca67
chore: create password strength validation
AnnaUgrai Jul 6, 2024
0021dc7
chore: definitely not messing up things for watchdog
markkovari Jul 6, 2024
ff201f7
fix: reenable email validation
markkovari Jul 6, 2024
a7548a7
test(register-API): scenarios for email and password
markkovari Jul 6, 2024
28a9b57
test(register): add sucessfull registration scenario
markkovari Jul 6, 2024
7238fc5
Merge pull request #23 from gfa-cc-after/SCRUM-46-tests-and-modificat…
ramesz6 Jul 8, 2024
90334de
fix: excluded common validatin to make validation work
AnnaUgrai Jul 9, 2024
de321db
style: fixed intentation
AnnaUgrai Jul 9, 2024
b662a8a
chore: add passwordvalidation to the frontend
AnnaUgrai Jul 9, 2024
2982b46
fix: delete json form backend
AnnaUgrai Jul 9, 2024
d13df33
revert: package.json remove react-scripts
markkovari Jul 9, 2024
e27bb84
Merge remote-tracking branch 'origin/main' into SCRUM-46
markkovari Jul 9, 2024
a3e0ce5
fix(backend): add throws exception to test suites
markkovari Jul 9, 2024
76bd186
refactor(backend):align with google java standards
markkovari Jul 9, 2024
6b5dffa
refactor(backend): align with Google Java Coding standards
markkovari Jul 9, 2024
43f86b1
refactor: use single import files and move static imports to the top
carlos-ponton Jul 9, 2024
0a412e8
refactor: split string message to lines with less than 100 characters
carlos-ponton Jul 9, 2024
5c58f26
fix: correct string message space to pass the test
carlos-ponton Jul 9, 2024
375e595
fix: correctindentation level 12 to 8 in UserControllerTest
Hsbalazs Jul 10, 2024
a2fbbe5
fix: line length in row 224 reduced under 100 in UserControllerTest
Hsbalazs Jul 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 104 additions & 103 deletions backend/pom.xml
Original file line number Diff line number Diff line change
@@ -1,110 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.greenfoxacademy</groupId>
<artifactId>backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>backend</name>
<description>backend</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.greenfoxacademy</groupId>
<artifactId>backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>backend</name>
<description>backend</description>
<url/>
</scm>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>3.2.0</version>
</dependency>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<!-- <dependency>-->
<!-- <groupId>commons-validator</groupId>-->
<!-- <artifactId>commons-validator</artifactId>-->
<!-- <version>1.9.0</version>-->
<!-- </dependency>-->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* This is the main class of the application.
*/
@SpringBootApplication
public class BackendApplication {

public static void main(String[] args) {
SpringApplication.run(BackendApplication.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*/
@Controller
public class HealthCheckController {
@GetMapping("/health-check")
@GetMapping ("/health-check")
public ResponseEntity<String> healthCheck() {
return new ResponseEntity<>("OK", HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,67 @@

import com.greenfoxacademy.backend.dtos.RegisterUserDto;
import com.greenfoxacademy.backend.services.UserService;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;


/**
* REST controller where endpoints are handled.
*/
@RestController
@RequiredArgsConstructor
@CrossOrigin(origins = "http://localhost:8080")
public class UserController {
private final UserService userService;

@CrossOrigin(origins = "http://localhost:5173")
@PostMapping("/register")
public ResponseEntity<?> registerUser(@RequestBody RegisterUserDto registerUserDto) {
if (!userService.emailValidation(registerUserDto.getEmail())) {
return ResponseEntity.badRequest().body("Email is not valid!");
} else if (userService.existsByEmail(registerUserDto.getEmail())) {
return ResponseEntity.badRequest().body("Email is already exist!");
} else {
userService.register(registerUserDto);
return ResponseEntity.ok().build();
/**
* This method registers a new user.
*
* @param registerUserDto the user to be registered
*
* @return a response entity with the status code and the location of the new user
*/
@CrossOrigin (origins = "http://localhost:5173")
@PostMapping ("/register")
public ResponseEntity<?> registerUser(@Validated @RequestBody RegisterUserDto registerUserDto) {
try {
URI uri = URI.create("/users/" + userService.register(registerUserDto).id());
return ResponseEntity.created(uri).build();
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}
}

/**
* This method handles validation exceptions.
*
* @param ex the exception to be handled
*
* @return a map with the field name and the error message
*/
@ResponseStatus (HttpStatus.BAD_REQUEST)
@ExceptionHandler (MethodArgumentNotValidException.class)
public Map<String, String> handleValidationExceptions(MethodArgumentNotValidException ex) {
Map<String, String> errors = new HashMap<>();
ex.getBindingResult().getAllErrors().forEach((error) -> {
String fieldName = ((FieldError) error).getField();
String errorMessage = error.getDefaultMessage();
errors.put(fieldName, errorMessage);
});
return errors;
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.greenfoxacademy.backend.dtos;


/**
* RegisterResponseDto represents a registration response.
*
* @param id of the created user
*
*/

public record RegisterResponseDto(
Integer id
) {
public RegisterResponseDto {
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package com.greenfoxacademy.backend.dtos;

import com.greenfoxacademy.backend.services.ValidPassword;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
* Data Transfer Object for User Entity.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class RegisterUserDto {
@NotBlank
private String firstName;
@NotBlank
private String lastName;
@Email
private String email;
@ValidPassword
private String password;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.greenfoxacademy.backend.models;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
Expand All @@ -11,7 +12,7 @@

/**
* Represents a user entity in the system. This class is a data model
* that maps to the user table in the database
* that maps to the user table in the database.
*/
@Data
@Builder
Expand All @@ -26,8 +27,8 @@ public class User {
private Integer id;
private String firstName;
private String lastName;
@Column(unique = true)
private String email;
private String password;


}
Loading
Loading