chore(setup): setup java backend #1
@ -1 +1 @@
|
|||||||
rootProject.name = "lf12_starter_backend"
|
rootProject.name = "casino"
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package de.szut.lf8_starter;
|
package de.szut.casino;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class Lf12StarterApplication {
|
public class CasinoApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Lf12StarterApplication.class, args);
|
SpringApplication.run(CasinoApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package de.szut.lf8_starter.config;
|
package de.szut.casino.config;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
package de.szut.lf8_starter.config;
|
package de.szut.casino.config;
|
||||||
|
|
||||||
|
|
||||||
import de.szut.lf8_starter.hello.HelloEntity;
|
import de.szut.casino.hello.HelloEntity;
|
||||||
import de.szut.lf8_starter.hello.HelloRepository;
|
import de.szut.casino.hello.HelloRepository;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
@ -1,4 +1,4 @@
|
|||||||
package de.szut.lf8_starter.exceptionHandling;
|
package de.szut.casino.exceptionHandling;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
@ -1,4 +1,4 @@
|
|||||||
package de.szut.lf8_starter.exceptionHandling;
|
package de.szut.casino.exceptionHandling;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Content;
|
import io.swagger.v3.oas.annotations.media.Content;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
@ -1,4 +1,4 @@
|
|||||||
package de.szut.lf8_starter.exceptionHandling;
|
package de.szut.casino.exceptionHandling;
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
@ -1,4 +1,4 @@
|
|||||||
package de.szut.lf8_starter.security;
|
package de.szut.casino.security;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
@ -1,23 +1,17 @@
|
|||||||
package de.szut.lf8_starter.security;
|
package de.szut.casino.security;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.HttpMethod;
|
|
||||||
import org.springframework.security.config.Customizer;
|
import org.springframework.security.config.Customizer;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
|
|
||||||
import org.springframework.security.core.session.SessionRegistry;
|
import org.springframework.security.core.session.SessionRegistry;
|
||||||
import org.springframework.security.core.session.SessionRegistryImpl;
|
import org.springframework.security.core.session.SessionRegistryImpl;
|
||||||
import org.springframework.security.oauth2.core.oidc.user.OidcUserAuthority;
|
|
||||||
import org.springframework.security.oauth2.core.user.OAuth2UserAuthority;
|
|
||||||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter;
|
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter;
|
||||||
import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter;
|
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
|
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
|
||||||
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
|
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
|
@ -1,98 +0,0 @@
|
|||||||
package de.szut.lf8_starter.hello;
|
|
||||||
|
|
||||||
|
|
||||||
import de.szut.lf8_starter.exceptionHandling.ResourceNotFoundException;
|
|
||||||
import de.szut.lf8_starter.hello.dto.HelloCreateDto;
|
|
||||||
import de.szut.lf8_starter.hello.dto.HelloGetDto;
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Content;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping(value = "hellos")
|
|
||||||
public class HelloController {
|
|
||||||
private final HelloService service;
|
|
||||||
private final HelloMapper helloMapper;
|
|
||||||
|
|
||||||
public HelloController(HelloService service, HelloMapper mappingService) {
|
|
||||||
this.service = service;
|
|
||||||
this.helloMapper = mappingService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "creates a new hello with its id and message")
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(responseCode = "201", description = "created hello",
|
|
||||||
content = {@Content(mediaType = "application/json",
|
|
||||||
schema = @Schema(implementation = HelloGetDto.class))}),
|
|
||||||
@ApiResponse(responseCode = "400", description = "invalid JSON posted",
|
|
||||||
content = @Content),
|
|
||||||
@ApiResponse(responseCode = "401", description = "not authorized",
|
|
||||||
content = @Content)})
|
|
||||||
@PostMapping
|
|
||||||
public HelloGetDto create(@RequestBody @Valid HelloCreateDto helloCreateDto) {
|
|
||||||
HelloEntity helloEntity = this.helloMapper.mapCreateDtoToEntity(helloCreateDto);
|
|
||||||
helloEntity = this.service.create(helloEntity);
|
|
||||||
return this.helloMapper.mapToGetDto(helloEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "delivers a list of hellos")
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(responseCode = "200", description = "list of hellos",
|
|
||||||
content = {@Content(mediaType = "application/json",
|
|
||||||
schema = @Schema(implementation = HelloGetDto.class))}),
|
|
||||||
@ApiResponse(responseCode = "401", description = "not authorized",
|
|
||||||
content = @Content)})
|
|
||||||
@GetMapping
|
|
||||||
public List<HelloGetDto> findAll() {
|
|
||||||
return this.service
|
|
||||||
.readAll()
|
|
||||||
.stream()
|
|
||||||
.map(e -> this.helloMapper.mapToGetDto(e))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "deletes a Hello by id")
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(responseCode = "204", description = "delete successful"),
|
|
||||||
@ApiResponse(responseCode = "401", description = "not authorized",
|
|
||||||
content = @Content),
|
|
||||||
@ApiResponse(responseCode = "404", description = "resource not found",
|
|
||||||
content = @Content)})
|
|
||||||
@DeleteMapping("/{id}")
|
|
||||||
@ResponseStatus(code = HttpStatus.NO_CONTENT)
|
|
||||||
public void deleteHelloById(@PathVariable long id) {
|
|
||||||
var entity = this.service.readById(id);
|
|
||||||
if (entity == null) {
|
|
||||||
throw new ResourceNotFoundException("HelloEntity not found on id = " + id);
|
|
||||||
} else {
|
|
||||||
this.service.delete(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "find hellos by message")
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@ApiResponse(responseCode = "200", description = "List of hellos who have the given message",
|
|
||||||
content = {@Content(mediaType = "application/json",
|
|
||||||
schema = @Schema(implementation = HelloGetDto.class))}),
|
|
||||||
@ApiResponse(responseCode = "404", description = "qualification description does not exist",
|
|
||||||
content = @Content),
|
|
||||||
@ApiResponse(responseCode = "401", description = "not authorized",
|
|
||||||
content = @Content)})
|
|
||||||
@GetMapping("/findByMessage")
|
|
||||||
public List<HelloGetDto> findAllEmployeesByQualification(@RequestParam String message) {
|
|
||||||
return this.service
|
|
||||||
.findByMessage(message)
|
|
||||||
.stream()
|
|
||||||
.map(e -> this.helloMapper.mapToGetDto(e))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package de.szut.lf8_starter.hello;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@Entity
|
|
||||||
@Table(name = "hello")
|
|
||||||
public class HelloEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private long id;
|
|
||||||
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
public HelloEntity(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
|||||||
package de.szut.lf8_starter.hello;
|
|
||||||
|
|
||||||
|
|
||||||
import de.szut.lf8_starter.hello.dto.HelloCreateDto;
|
|
||||||
import de.szut.lf8_starter.hello.dto.HelloGetDto;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class HelloMapper {
|
|
||||||
|
|
||||||
public HelloGetDto mapToGetDto(HelloEntity entity) {
|
|
||||||
return new HelloGetDto(entity.getId(), entity.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
public HelloEntity mapCreateDtoToEntity(HelloCreateDto dto) {
|
|
||||||
var entity = new HelloEntity();
|
|
||||||
entity.setMessage(dto.getMessage());
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package de.szut.lf8_starter.hello;
|
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface HelloRepository extends JpaRepository<HelloEntity, Long> {
|
|
||||||
|
|
||||||
|
|
||||||
List<HelloEntity> findByMessage(String message);
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
package de.szut.lf8_starter.hello;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class HelloService {
|
|
||||||
private final HelloRepository repository;
|
|
||||||
|
|
||||||
public HelloService(HelloRepository repository) {
|
|
||||||
this.repository = repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HelloEntity create(HelloEntity entity) {
|
|
||||||
return this.repository.save(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<HelloEntity> readAll() {
|
|
||||||
return this.repository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
public HelloEntity readById(long id) {
|
|
||||||
Optional<HelloEntity> optionalQualification = this.repository.findById(id);
|
|
||||||
if (optionalQualification.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return optionalQualification.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void delete(HelloEntity entity) {
|
|
||||||
this.repository.delete(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<HelloEntity> findByMessage(String message) {
|
|
||||||
return this.repository.findByMessage(message);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package de.szut.lf8_starter.hello.dto;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class HelloCreateDto {
|
|
||||||
|
|
||||||
@Size(min = 3, message = "at least length of 3")
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
@JsonCreator
|
|
||||||
public HelloCreateDto(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
package de.szut.lf8_starter.hello.dto;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class HelloGetDto {
|
|
||||||
|
|
||||||
private long id;
|
|
||||||
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
|||||||
package de.szut.lf8_starter.welcome;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.security.Principal;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class WelcomeController {
|
|
||||||
|
|
||||||
@GetMapping("/welcome")
|
|
||||||
public String welcome() {
|
|
||||||
return "welcome to lf8_starter";
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/roles")
|
|
||||||
public ResponseEntity<?> getRoles(Authentication authentication) {
|
|
||||||
return ResponseEntity.ok(authentication.getAuthorities());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package de.szut.lf8_starter;
|
package de.szut.casino;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
Loading…
x
Reference in New Issue
Block a user