mhm
This commit is contained in:
parent
a63afaa022
commit
2a44ada1be
11 changed files with 96 additions and 14 deletions
|
|
@ -0,0 +1,23 @@
|
||||||
|
package me.jweissen.aeticket.controller;
|
||||||
|
|
||||||
|
import me.jweissen.aeticket.service.CartService;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/cart")
|
||||||
|
public class CartController {
|
||||||
|
private final CartService cartService;
|
||||||
|
|
||||||
|
public CartController(CartService cartService) {
|
||||||
|
this.cartService = cartService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
public ResponseEntity<Void> addEntry() {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,8 @@ import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/event")
|
@RequestMapping("/event")
|
||||||
public class EventController {
|
public class EventController {
|
||||||
|
|
@ -17,6 +19,16 @@ public class EventController {
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<EventResponseDto> getById(@PathVariable Integer id) {
|
||||||
|
return new ResponseEntity<>(eventService.getById(id), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
public ResponseEntity<List<EventResponseDto>> getAllFuture() {
|
||||||
|
return new ResponseEntity<>(eventService.getAllFuture(), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
public ResponseEntity<Void> create(@RequestBody EventRequestDto event) {
|
public ResponseEntity<Void> create(@RequestBody EventRequestDto event) {
|
||||||
// TODO admin only
|
// TODO admin only
|
||||||
|
|
@ -37,9 +49,4 @@ public class EventController {
|
||||||
eventService.delete(id);
|
eventService.delete(id);
|
||||||
return new ResponseEntity<>(null, HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(null, HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
|
||||||
public ResponseEntity<EventResponseDto> getById(@PathVariable Integer id) {
|
|
||||||
eventService.getById();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package me.jweissen.aeticket.dto.request;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record CartAddRequestDto(Long id, List<CartEntryRequestDto> cartEntries) {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package me.jweissen.aeticket.dto.request;
|
||||||
|
|
||||||
|
public record CartEntryRequestDto(Long id, Integer amount) {
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package me.jweissen.aeticket.dto.response;
|
package me.jweissen.aeticket.dto.response;
|
||||||
|
|
||||||
public record CategoryResponseDto(int id, String name, int price, int stock) {
|
public record CategoryResponseDto(Long id, String name, Double price, Integer stock) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record EventResponseDto(
|
public record EventResponseDto(
|
||||||
int id,
|
Long id,
|
||||||
String name,
|
String name,
|
||||||
Date from,
|
Date from,
|
||||||
Date to,
|
Date to,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package me.jweissen.aeticket.model;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.NonNull;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -13,16 +14,19 @@ import java.util.List;
|
||||||
public class Category {
|
public class Category {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Integer id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
@NonNull
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Double price;
|
@NonNull
|
||||||
|
private Integer price;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private int stock;
|
@NonNull
|
||||||
|
private Integer stock;
|
||||||
|
|
||||||
@ManyToOne(optional = false)
|
@ManyToOne(optional = false)
|
||||||
@JoinColumn(nullable = false)
|
@JoinColumn(nullable = false)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import java.util.List;
|
||||||
public class Event {
|
public class Event {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private int id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,11 @@ package me.jweissen.aeticket.repository;
|
||||||
|
|
||||||
import me.jweissen.aeticket.model.Event;
|
import me.jweissen.aeticket.model.Event;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface EventRepository extends JpaRepository<Event, Integer> {
|
public interface EventRepository extends JpaRepository<Event, Integer> {
|
||||||
|
@Query("SELECT e FROM Event e WHERE e.start > CURRENT_TIMESTAMP")
|
||||||
|
List<Event> findAllFuture();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package me.jweissen.aeticket.service;
|
||||||
|
|
||||||
|
import me.jweissen.aeticket.dto.response.CategoryResponseDto;
|
||||||
|
import me.jweissen.aeticket.model.Category;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CategoryService {
|
||||||
|
public static CategoryResponseDto toDto(Category category) {
|
||||||
|
return new CategoryResponseDto(
|
||||||
|
category.getId(),
|
||||||
|
category.getName(),
|
||||||
|
category.getPrice() / 100.0,
|
||||||
|
category.getStock()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<CategoryResponseDto> toDtos(List<Category> categories) {
|
||||||
|
return categories.stream().map(CategoryService::toDto).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,8 @@ import me.jweissen.aeticket.model.Event;
|
||||||
import me.jweissen.aeticket.repository.EventRepository;
|
import me.jweissen.aeticket.repository.EventRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EventService {
|
public class EventService {
|
||||||
private final EventRepository eventRepository;
|
private final EventRepository eventRepository;
|
||||||
|
|
@ -31,8 +33,12 @@ public class EventService {
|
||||||
event.getStart(),
|
event.getStart(),
|
||||||
event.getEnd(),
|
event.getEnd(),
|
||||||
event.getDescription(),
|
event.getDescription(),
|
||||||
event.getCategories()
|
CategoryService.toDtos(event.getCategories())
|
||||||
)
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<EventResponseDto> toDtos(List<Event> events) {
|
||||||
|
return events.stream().map(EventService::toDto).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void create(EventRequestDto event) {
|
public void create(EventRequestDto event) {
|
||||||
|
|
@ -47,6 +53,10 @@ public class EventService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventResponseDto getById(Integer id) {
|
public EventResponseDto getById(Integer id) {
|
||||||
return eventRepository.getReferenceById(id);
|
return EventService.toDto(eventRepository.getReferenceById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<EventResponseDto> getAllFuture() {
|
||||||
|
return EventService.toDtos(eventRepository.findAllFuture());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue