Merge branch 'main' into task/add-semantic-commit-tutorial-to-readme
This commit is contained in:
commit
5739d31cdf
27 changed files with 2130 additions and 13757 deletions
|
@ -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.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Lf12StarterApplication {
|
||||
public class CasinoApplication {
|
||||
|
||||
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,4 +1,4 @@
|
|||
package de.szut.lf8_starter.exceptionHandling;
|
||||
package de.szut.casino.exceptionHandling;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
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.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.web.bind.annotation.ResponseStatus;
|
|
@ -1,5 +1,7 @@
|
|||
package de.szut.lf8_starter.security;
|
||||
package de.szut.casino.security;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
@ -9,9 +11,6 @@ import org.springframework.stereotype.Component;
|
|||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class KeycloakLogoutHandler implements LogoutHandler {
|
|
@ -1,29 +1,25 @@
|
|||
package de.szut.lf8_starter.security;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
package de.szut.casino.security;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.config.Customizer;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
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.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.JwtGrantedAuthoritiesConverter;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy;
|
||||
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;
|
||||
import org.springframework.security.web.session.HttpSessionEventPublisher;
|
||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
class KeycloakSecurityConfig {
|
|
@ -1,33 +0,0 @@
|
|||
package de.szut.lf8_starter.config;
|
||||
|
||||
|
||||
import de.szut.lf8_starter.hello.HelloEntity;
|
||||
import de.szut.lf8_starter.hello.HelloRepository;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Component
|
||||
public class SampleDataCreator implements ApplicationRunner {
|
||||
|
||||
private HelloRepository repository;
|
||||
|
||||
public SampleDataCreator(HelloRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public void run(ApplicationArguments args) {
|
||||
repository.save(new HelloEntity("Hallo Welt!"));
|
||||
repository.save(new HelloEntity("Schöner Tag heute"));
|
||||
repository.save(new HelloEntity("FooBar"));
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
}
|
|
@ -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.springframework.boot.test.context.SpringBootTest;
|
2107
frontend/bun.lock
Normal file
2107
frontend/bun.lock
Normal file
File diff suppressed because it is too large
Load diff
13383
frontend/package-lock.json
generated
13383
frontend/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -2,11 +2,11 @@
|
|||
"name": "lf10-starter2024",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve --proxy-config src/proxy.conf.json",
|
||||
"build": "ng build",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"test": "ng test"
|
||||
"ng": "bunx @angular/cli",
|
||||
"start": "bunx @angular/cli serve --proxy-config src/proxy.conf.json",
|
||||
"build": "bunx @angular/cli build",
|
||||
"watch": "bunx @angular/cli build --watch --configuration development",
|
||||
"test": "bunx @angular/cli test"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
export class Hello {
|
||||
constructor(public id?: number,
|
||||
public message?: string,
|
||||
) {
|
||||
}
|
||||
}
|
|
@ -1,7 +1,3 @@
|
|||
<h1>LF12 Starter</h1>
|
||||
|
||||
<a href="/hello">hello</a>
|
||||
|
||||
<router-outlet></router-outlet>
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
import { Routes } from '@angular/router';
|
||||
import {HelloListComponent} from "./hello-list/hello-list.component";
|
||||
import {authGuard} from "./auth.guard";
|
||||
import {Routes} from '@angular/router';
|
||||
|
||||
export const routes: Routes = [
|
||||
{ path: 'hello', component: HelloListComponent , canActivate: [authGuard] }
|
||||
];
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
<h3>List of Hellos</h3>
|
||||
<ul>
|
||||
@for(e of employees$ | async; track e.id) {
|
||||
<li>
|
||||
{{e.id }}, {{e.message}}
|
||||
</li>
|
||||
}
|
||||
</ul>
|
|
@ -1,31 +0,0 @@
|
|||
import { Component } from '@angular/core';
|
||||
import {Observable, of} from "rxjs";
|
||||
import {Hello} from "../Hello";
|
||||
import {HttpClient, HttpClientModule, HttpHeaders, provideHttpClient} from "@angular/common/http";
|
||||
import {AsyncPipe} from "@angular/common";
|
||||
import {KeycloakService} from "keycloak-angular";
|
||||
|
||||
@Component({
|
||||
selector: 'app-hello-list',
|
||||
standalone: true,
|
||||
imports: [
|
||||
AsyncPipe
|
||||
],
|
||||
providers: [KeycloakService],
|
||||
templateUrl: './hello-list.component.html',
|
||||
styleUrl: './hello-list.component.css'
|
||||
})
|
||||
export class HelloListComponent {
|
||||
employees$: Observable<Hello[]>;
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
this.employees$ = of([]);
|
||||
this.fetchData();
|
||||
}
|
||||
|
||||
fetchData() {
|
||||
this.employees$ = this.http.get<Hello[]>('/backend/hellos');
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in a new issue