Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
java-version: "21"
cache: "maven"

- name: Check code formatting
working-directory: ./apigateway
run: ./mvnw spotless:check

- name: Build with Maven
working-directory: ./apigateway
run: ./mvnw verify -DskipTests
75 changes: 75 additions & 0 deletions CODE_FORMATTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Code Formatting Guide

## Overview

This project enforces consistent code formatting using **Spotless** with **Google Java Format**. All Java code must adhere to the Google Java Style Guide to maintain code quality and consistency across contributions.

## Automated Formatting Checks

### CI/CD Enforcement

Every pull request automatically runs a formatting check in the CI pipeline. **Pull requests will fail if code is not properly formatted.**

The CI workflow includes:
```bash
./mvnw spotless:check
```

This ensures that all merged code follows the established formatting standards.

## Local Development

### Check Formatting

To check if your code is properly formatted:

```bash
cd apigateway
./mvnw spotless:check
```

**On Windows:**
```powershell
cd apigateway
.\mvnw.cmd spotless:check
```

### Apply Formatting

To automatically format all Java files:

```bash
cd apigateway
./mvnw spotless:apply
```

**On Windows:**
```powershell
cd apigateway
.\mvnw.cmd spotless:apply
```

### Pre-commit Best Practice

**Always run `mvnw spotless:apply` before committing your changes** to avoid CI failures.

## What Gets Formatted

The Spotless configuration formats:

- ✅ All Java source files (`src/main/java/**/*.java`)
- ✅ All Java test files (`src/test/java/**/*.java`)

### Formatting Rules Applied

1. **Google Java Format** - Standard Google style formatting
2. **Import Organization** - Imports ordered as: `java`, `javax`, `org`, `com`, `vaultweb`
3. **Unused Import Removal** - Automatically removes unused imports
4. **Trailing Whitespace** - Removes trailing whitespace from lines
5. **End with Newline** - Ensures files end with a newline character

## References

- [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html)
- [Spotless Maven Plugin](https://github.com/diffplug/spotless/tree/main/plugin-maven)
- [Google Java Format](https://github.com/google/google-java-format)
27 changes: 27 additions & 0 deletions apigateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,33 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.41.1</version>
<configuration>
<java>
<googleJavaFormat>
<version>1.22.0</version>
<style>GOOGLE</style>
</googleJavaFormat>
<removeUnusedImports />
<importOrder>
<order>java,javax,org,com,vaultweb</order>
</importOrder>
<trimTrailingWhitespace />
<endWithNewline />
</java>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
@SpringBootApplication
public class ApiGatewayApplication {

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

public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package vaultweb.apigateway.config;

public class GatewayAuthConfig {
}
public class GatewayAuthConfig {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,53 @@
@RequestMapping("/auth")
public class GatewayAuthController {

@GetMapping("/me")
public String getMyData(){
return "My Data!";
}

@PostMapping("/login")
public String login(){
return "login";
}

@PostMapping("/register")
public String register(){
return "register";

}

@PostMapping("/logout")
public String logout(){
return "logout";
}

@PostMapping("change-username")
public String changeUsername(){
return "changeUsername";
}

@PostMapping("change-email")
public String changeEmail(){
return "changeEmail";
}

@PostMapping("change-password")
public String changePassword(){
return "changePassword";
}

@PostMapping("/switch-jwt")
public String switchJwtToken(){
return "switchJwtToken";
}

@PostMapping("/reset-password")
public String resetPassword(){
return "resetPassword";
}

@PostMapping("/verify-email")
public String verifyEmail(){
return "verifyEmail";
}

@GetMapping("/me")
public String getMyData() {
return "My Data!";
}

@PostMapping("/login")
public String login() {
return "login";
}

@PostMapping("/register")
public String register() {
return "register";
}

@PostMapping("/logout")
public String logout() {
return "logout";
}

@PostMapping("change-username")
public String changeUsername() {
return "changeUsername";
}

@PostMapping("change-email")
public String changeEmail() {
return "changeEmail";
}

@PostMapping("change-password")
public String changePassword() {
return "changePassword";
}

@PostMapping("/switch-jwt")
public String switchJwtToken() {
return "switchJwtToken";
}

@PostMapping("/reset-password")
public String resetPassword() {
return "resetPassword";
}

@PostMapping("/verify-email")
public String verifyEmail() {
return "verifyEmail";
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package vaultweb.apigateway.controller;

public class GatewayCloudController {
}
public class GatewayCloudController {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package vaultweb.apigateway.controller;

public class GatewayPasswordManagerController {
}
public class GatewayPasswordManagerController {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package vaultweb.apigateway.exceptions;

public class GlobalExceptionHandler {
}
public class GlobalExceptionHandler {}
16 changes: 8 additions & 8 deletions apigateway/src/main/java/vaultweb/apigateway/model/User.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package vaultweb.apigateway.model;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -13,11 +13,11 @@
@AllArgsConstructor
@NoArgsConstructor
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
private String email;
private String password;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

}
private String name;
private String email;
private String password;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package vaultweb.apigateway.service;

public class AuthService {
}
public class AuthService {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package vaultweb.apigateway.service;

public class RoutingService {
}
public class RoutingService {}
47 changes: 25 additions & 22 deletions apigateway/src/main/java/vaultweb/apigateway/util/BcryptUtil.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
package vaultweb.apigateway.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import static org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder.BCryptVersion.$2B;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class BcryptUtil {
private static final int BCRYPT_ROUNDS = 12;
private static final BCryptPasswordEncoder.BCryptVersion BCRYPT_VERSION = $2B;
private static final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(BCRYPT_VERSION, BCRYPT_ROUNDS);
private static final int BCRYPT_ROUNDS = 12;
private static final BCryptPasswordEncoder.BCryptVersion BCRYPT_VERSION = $2B;
private static final BCryptPasswordEncoder encoder =
new BCryptPasswordEncoder(BCRYPT_VERSION, BCRYPT_ROUNDS);

/**
* Encodes the password using the bcrypt algorithm.
* @param password to be encoded
* @return hashed version of the password
*/
public String encode(final String password) {
return encoder.encode(password);
}
/**
* Encodes the password using the bcrypt algorithm.
*
* @param password to be encoded
* @return hashed version of the password
*/
public String encode(final String password) {
return encoder.encode(password);
}

/**
* Checks if two passwords are equivalent.
* @param password that is unencrypted
* @param hashedPassword from database
* @return true if the passwords are the same
*/
public boolean matches(final String password, final String hashedPassword) {
return encoder.matches(password, hashedPassword);
}
/**
* Checks if two passwords are equivalent.
*
* @param password that is unencrypted
* @param hashedPassword from database
* @return true if the passwords are the same
*/
public boolean matches(final String password, final String hashedPassword) {
return encoder.matches(password, hashedPassword);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package vaultweb.apigateway.util;

public class JwtUtil {
}
public class JwtUtil {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
@SpringBootTest
class ApigatewayApplicationTests {

@Test
void contextLoads() {

}

@Test
void contextLoads() {}
}