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>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
package me.jweissen.aeticket.controller;
|
||||
|
||||
import me.jweissen.aeticket.dto.response.CartEntryResponseDto;
|
||||
import me.jweissen.aeticket.service.CartService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/cart")
|
||||
public class CartController {
|
||||
|
|
@ -16,8 +20,15 @@ public class CartController {
|
|||
this.cartService = cartService;
|
||||
}
|
||||
|
||||
/*@GetMapping("/list")
|
||||
public ResponseEntity<List<CartEntryResponseDto>> getCartEntries() {
|
||||
return cartService.get
|
||||
}*/
|
||||
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity<Void> addEntry() {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
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.NonNull;
|
||||
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;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
@Getter
|
||||
@Setter
|
||||
public class User {
|
||||
public class User implements UserDetails {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private int id;
|
||||
|
|
@ -39,4 +43,38 @@ public class User {
|
|||
@OneToMany(mappedBy = "user")
|
||||
@JoinColumn(nullable = false)
|
||||
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(
|
||||
category.getId(),
|
||||
category.getName(),
|
||||
category.getPrice(),
|
||||
CategoryService.centsToEuros(category.getPrice()),
|
||||
cartEntry.getAmount()
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package me.jweissen.aeticket.service;
|
||||
|
||||
import me.jweissen.aeticket.dto.response.CartEntryResponseDto;
|
||||
import me.jweissen.aeticket.dto.response.CartEventResponseDto;
|
||||
import me.jweissen.aeticket.model.Cart;
|
||||
import me.jweissen.aeticket.model.Event;
|
||||
|
|
@ -33,4 +34,7 @@ public class CartService {
|
|||
CartEntryService.toDtos(cartEntryRepository.getByCartAndEvent(cart.getId(), event.getId()))
|
||||
)).toList();
|
||||
}
|
||||
|
||||
//public List<CartEntryResponseDto> getCartByAuthToken() {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public class CategoryService {
|
|||
return new CategoryResponseDto(
|
||||
category.getId(),
|
||||
category.getName(),
|
||||
category.getPrice() / 100.0,
|
||||
centsToEuros(category.getPrice()),
|
||||
category.getStock()
|
||||
);
|
||||
}
|
||||
|
|
@ -20,4 +20,8 @@ public class CategoryService {
|
|||
public static List<CategoryResponseDto> toDtos(List<Category> categories) {
|
||||
return categories.stream().map(CategoryService::toDto).toList();
|
||||
}
|
||||
|
||||
public static Double centsToEuros(int cents) {
|
||||
return cents / 100.0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue