samc
This commit is contained in:
parent
61bdf1e048
commit
74967d1cfa
8 changed files with 74 additions and 8 deletions
5
pom.xml
5
pom.xml
|
|
@ -25,7 +25,10 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
package me.jweissen.aeticket.controller;
|
package me.jweissen.aeticket.controller;
|
||||||
|
|
||||||
|
import me.jweissen.aeticket.dto.response.CartEntryResponseDto;
|
||||||
import me.jweissen.aeticket.service.CartService;
|
import me.jweissen.aeticket.service.CartService;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/cart")
|
@RequestMapping("/cart")
|
||||||
public class CartController {
|
public class CartController {
|
||||||
|
|
@ -16,8 +20,15 @@ public class CartController {
|
||||||
this.cartService = cartService;
|
this.cartService = cartService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*@GetMapping("/list")
|
||||||
|
public ResponseEntity<List<CartEntryResponseDto>> getCartEntries() {
|
||||||
|
return cartService.get
|
||||||
|
}*/
|
||||||
|
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
public ResponseEntity<Void> addEntry() {
|
public ResponseEntity<Void> addEntry() {
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package me.jweissen.aeticket.dto.response;
|
package me.jweissen.aeticket.dto.response;
|
||||||
|
|
||||||
public record CartEntryResponseDto(Integer id, String name, Double price, Integer amount) {
|
public record CartEntryResponseDto(Long id, String name, Double price, Integer amount) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
src/main/java/me/jweissen/aeticket/model/Role.java
Normal file
6
src/main/java/me/jweissen/aeticket/model/Role.java
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
package me.jweissen.aeticket.model;
|
||||||
|
|
||||||
|
public enum Role {
|
||||||
|
ADMIN,
|
||||||
|
USER,
|
||||||
|
}
|
||||||
|
|
@ -4,14 +4,18 @@ import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table
|
@Table
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class User {
|
public class User implements UserDetails {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private int id;
|
private int id;
|
||||||
|
|
@ -39,4 +43,38 @@ public class User {
|
||||||
@OneToMany(mappedBy = "user")
|
@OneToMany(mappedBy = "user")
|
||||||
@JoinColumn(nullable = false)
|
@JoinColumn(nullable = false)
|
||||||
private List<Cart> carts;
|
private List<Cart> carts;
|
||||||
|
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private Role role;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
|
return List.of(new SimpleGrantedAuthority(role.name()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsername() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAccountNonExpired() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAccountNonLocked() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCredentialsNonExpired() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ public class CartEntryService {
|
||||||
return new CartEntryResponseDto(
|
return new CartEntryResponseDto(
|
||||||
category.getId(),
|
category.getId(),
|
||||||
category.getName(),
|
category.getName(),
|
||||||
category.getPrice(),
|
CategoryService.centsToEuros(category.getPrice()),
|
||||||
cartEntry.getAmount()
|
cartEntry.getAmount()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package me.jweissen.aeticket.service;
|
package me.jweissen.aeticket.service;
|
||||||
|
|
||||||
|
import me.jweissen.aeticket.dto.response.CartEntryResponseDto;
|
||||||
import me.jweissen.aeticket.dto.response.CartEventResponseDto;
|
import me.jweissen.aeticket.dto.response.CartEventResponseDto;
|
||||||
import me.jweissen.aeticket.model.Cart;
|
import me.jweissen.aeticket.model.Cart;
|
||||||
import me.jweissen.aeticket.model.Event;
|
import me.jweissen.aeticket.model.Event;
|
||||||
|
|
@ -33,4 +34,7 @@ public class CartService {
|
||||||
CartEntryService.toDtos(cartEntryRepository.getByCartAndEvent(cart.getId(), event.getId()))
|
CartEntryService.toDtos(cartEntryRepository.getByCartAndEvent(cart.getId(), event.getId()))
|
||||||
)).toList();
|
)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//public List<CartEntryResponseDto> getCartByAuthToken() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,18 @@ import java.util.List;
|
||||||
public class CategoryService {
|
public class CategoryService {
|
||||||
public static CategoryResponseDto toDto(Category category) {
|
public static CategoryResponseDto toDto(Category category) {
|
||||||
return new CategoryResponseDto(
|
return new CategoryResponseDto(
|
||||||
category.getId(),
|
category.getId(),
|
||||||
category.getName(),
|
category.getName(),
|
||||||
category.getPrice() / 100.0,
|
centsToEuros(category.getPrice()),
|
||||||
category.getStock()
|
category.getStock()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<CategoryResponseDto> toDtos(List<Category> categories) {
|
public static List<CategoryResponseDto> toDtos(List<Category> categories) {
|
||||||
return categories.stream().map(CategoryService::toDto).toList();
|
return categories.stream().map(CategoryService::toDto).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Double centsToEuros(int cents) {
|
||||||
|
return cents / 100.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue