Skip to content

Commit

Permalink
Spotless code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgrdich committed May 10, 2024
1 parent bbac777 commit d315685
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ public class SecurityConfiguration {
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {

return http.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(
req -> req.requestMatchers("/login/**", "/register/**", "/forget-password/**")
.permitAll()
.requestMatchers("/paid/**")
.hasAuthority(Role.PAID.name())
.anyRequest()
.authenticated())
.authorizeHttpRequests(req -> req.requestMatchers("/login/**", "/register/**", "/forget-password/**")
.permitAll()
.requestMatchers("/paid/**")
.hasAuthority(Role.PAID.name())
.anyRequest()
.authenticated())
.userDetailsService(userDetailsServiceImp)
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.llm_service.llm_service.controller.user;

import com.llm_service.llm_service.service.jwt.AuthenticationResponse;
import com.llm_service.llm_service.dto.User;
import com.llm_service.llm_service.service.jwt.AuthenticationResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.llm_service.llm_service.controller.user;

import com.llm_service.llm_service.exception.user.UsernameAlreadyExistsException;
import com.llm_service.llm_service.service.jwt.AuthenticationResponse;
import com.llm_service.llm_service.service.jwt.AuthenticationService;
import com.llm_service.llm_service.dto.User;
import com.llm_service.llm_service.exception.user.UserAlreadyExistsException;
import com.llm_service.llm_service.exception.user.UserNotFoundException;
import com.llm_service.llm_service.exception.user.UsernameAlreadyExistsException;
import com.llm_service.llm_service.service.jwt.AuthenticationResponse;
import com.llm_service.llm_service.service.jwt.AuthenticationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.AuthenticationException;

import org.springframework.web.bind.annotation.*;

@CrossOrigin("http://localhost:4040")
Expand All @@ -29,25 +28,25 @@ public UserController(AuthenticationService authenticationService, UserApiMapper

@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "Creates a new user",
content = {@Content(mediaType = "application/json")})
@ApiResponse(
responseCode = "200",
description = "Creates a new user",
content = {@Content(mediaType = "application/json")})
})
@Operation(summary = "register the user")
@PostMapping("/register")
public ResponseEntity<UserResponse> register(@RequestBody UserRequest userRequest)
throws UsernameAlreadyExistsException{
User user= authenticationService.register(userRequest);
throws UsernameAlreadyExistsException {
User user = authenticationService.register(userRequest);
return ResponseEntity.status(HttpStatus.OK).body(userApiMapper.map(user));
}

@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "Logs the user into the system",
content = {@Content(mediaType = "application/json")})
@ApiResponse(
responseCode = "200",
description = "Logs the user into the system",
content = {@Content(mediaType = "application/json")})
})
@Operation(summary = "login phase of the user")
@PostMapping("/login")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.llm_service.llm_service.persistance.entities.Role;
import lombok.*;
import lombok.experimental.SuperBuilder;
import lombok.extern.jackson.Jacksonized;

@Value
Expand All @@ -11,12 +10,16 @@
public class UserRequest {
@NonNull
String username;

@NonNull
String password;

@NonNull
String firstName;

@NonNull
String lastName;

@NonNull
Role role;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class UserNotFoundException extends Exception {
public UserNotFoundException(UUID id) {
super("User with id " + id + " is not found");
}

public UserNotFoundException() {
super("User with is not found");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.llm_service.llm_service.exception.user;

import java.util.UUID;

public class UsernameAlreadyExistsException extends Exception {
public UsernameAlreadyExistsException(String username) {
super("Username with name " + username + " already exists");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.llm_service.llm_service.persistance.repositories.token;

import com.llm_service.llm_service.service.jwt.Token;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import com.llm_service.llm_service.service.jwt.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.llm_service.llm_service.persistance.repositories.token;

import com.llm_service.llm_service.service.jwt.Token;

import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.llm_service.llm_service.persistance.repositories.token;

import com.llm_service.llm_service.persistance.entities.TokenEntity;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import com.llm_service.llm_service.persistance.entities.TokenEntity;
import org.springframework.data.jpa.repository.JpaRepository;

public interface TokenRepository extends JpaRepository<TokenEntity, UUID> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.llm_service.llm_service.persistance.repositories.user;

import com.llm_service.llm_service.dto.User;
import com.llm_service.llm_service.persistance.entities.FullName;
import com.llm_service.llm_service.persistance.entities.UserEntity;
import com.llm_service.llm_service.dto.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.llm_service.llm_service.persistance.repositories.user;

import com.llm_service.llm_service.dto.User;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import com.llm_service.llm_service.dto.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.llm_service.llm_service.persistance.repositories.user;

import com.llm_service.llm_service.dto.User;

import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.llm_service.llm_service.persistance.repositories.user;

import com.llm_service.llm_service.persistance.entities.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional;
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<UserEntity, UUID> {
Optional<UserEntity> findByUsername(String username);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.llm_service.llm_service.service.jwt;

import java.util.List;

import com.llm_service.llm_service.controller.user.LoginRequest;
import com.llm_service.llm_service.controller.user.UserRequest;
import com.llm_service.llm_service.dto.User;
import com.llm_service.llm_service.exception.user.UserNotFoundException;
import com.llm_service.llm_service.exception.user.UsernameAlreadyExistsException;
import com.llm_service.llm_service.persistance.entities.UserEntity;
import com.llm_service.llm_service.persistance.repositories.token.TokenPersistenceManager;
import com.llm_service.llm_service.persistance.repositories.user.UserEntityMapper;
import com.llm_service.llm_service.persistance.repositories.user.UserPersistenceManager;
import com.llm_service.llm_service.dto.User;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.llm_service.llm_service.service.jwt;

import com.llm_service.llm_service.persistance.repositories.token.TokenRepository;
import com.llm_service.llm_service.dto.User;
import com.llm_service.llm_service.persistance.repositories.token.TokenRepository;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.io.Decoders;
Expand All @@ -17,7 +17,6 @@ public class JwtService {
private final String SECRET_KEY = "4bb6d1dfbafb64a681139d1586b6f1160d18159afd57c8c79136d7490630407c";
private final TokenRepository tokenRepository;


public JwtService(TokenRepository tokenRepository) {
this.tokenRepository = tokenRepository;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.llm_service.llm_service.service.jwt;

import java.util.UUID;

import com.llm_service.llm_service.dto.User;
import java.util.UUID;
import lombok.Builder;
import lombok.Value;

Expand Down

0 comments on commit d315685

Please sign in to comment.