40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
package com.rit.ems.controller;
|
|
|
|
import com.rit.ems.model.Venue;
|
|
import com.rit.ems.repository.VenueRepository;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Random;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/venues")
|
|
public class VenueController {
|
|
|
|
@Autowired
|
|
private VenueRepository venueRepository;
|
|
|
|
@GetMapping
|
|
public List<Venue> getAllVenues() {
|
|
return venueRepository.findAll();
|
|
}
|
|
|
|
@PostMapping
|
|
public ResponseEntity<?> createVenue(@RequestBody Venue venue) {
|
|
if (venue.getId() == null) {
|
|
venue.setId("v-" + (System.currentTimeMillis() + new Random().nextInt(1000)));
|
|
}
|
|
venueRepository.save(venue);
|
|
return ResponseEntity.ok(venue);
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
public ResponseEntity<?> deleteVenue(@PathVariable String id) {
|
|
venueRepository.deleteById(id);
|
|
return ResponseEntity.ok(Map.of("message", "Venue deleted successfully"));
|
|
}
|
|
}
|