Skip to content

Commit

Permalink
refactor(backend):align with google java standards
Browse files Browse the repository at this point in the history
  • Loading branch information
markkovari committed Jul 9, 2024
1 parent a3e0ce5 commit 76bd186
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.greenfoxacademy.backend.controller;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

import com.greenfoxacademy.backend.dtos.RegisterUserDto;
import com.greenfoxacademy.backend.services.UserService;
import lombok.RequiredArgsConstructor;
Expand All @@ -8,11 +12,12 @@
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;
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;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.greenfoxacademy.backend.dtos;


/**
* RegisterResponseDto represents a registration response.
* @param id of the created user
*/
public record RegisterResponseDto(
Integer id
) {
Expand Down
16 changes: 10 additions & 6 deletions backend/src/main/java/com/greenfoxacademy/backend/models/User.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
package com.greenfoxacademy.backend.models;

import jakarta.persistence.*;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* 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
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table (name = "_user")
@Table(name = "_user")
public class User {

@Id
@GeneratedValue
private Integer id;
private String firstName;
private String lastName;
@Column (unique = true)
@Column(unique = true)
private String email;
private String password;

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import java.util.ArrayList;


/**
* Custom validator for password field.
*/
public class PasswordConstraintValidator implements ConstraintValidator<ValidPassword, String> {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
package com.greenfoxacademy.backend.services;


import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* ValidPassword annotation to mark a field as a password which should be validated.
*/
@Documented
@Constraint (validatedBy = PasswordConstraintValidator.class)
@Target ({TYPE, FIELD, ANNOTATION_TYPE})
@Retention (RUNTIME)
@Retention(RUNTIME)
public @interface ValidPassword {


/**
* Message to be displayed when the password is invalid.
*/
String message() default "Invalid Password";


/**
* Groups.
*/
Class<?>[] groups() default {};


/**
* Payload.
*/
Class<? extends Payload>[] payload() default {};

}

0 comments on commit 76bd186

Please sign in to comment.