generated from cepdnaclk/eYY-XXX-project-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'cepdnaclk:main' into main
- Loading branch information
Showing
12 changed files
with
601 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.example.demo.Events; | ||
|
||
import jakarta.persistence.*; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Date; | ||
|
||
@Entity | ||
@Table(name = "events") | ||
public class Event { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String title; | ||
private String details; | ||
private LocalDate date; | ||
private String time; | ||
private String venue; | ||
|
||
// Getters and Setters | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public String getDetails() { | ||
return details; | ||
} | ||
|
||
public void setDetails(String details) { | ||
this.details = details; | ||
} | ||
|
||
public LocalDate getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(LocalDate date) { | ||
this.date = date; | ||
} | ||
|
||
public String getTime() { | ||
return time; | ||
} | ||
|
||
public void setTime(String time) { | ||
this.time = time; | ||
} | ||
|
||
public String getVenue() { | ||
return venue; | ||
} | ||
|
||
public void setVenue(String venue) { | ||
this.venue = venue; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
back-end/src/main/java/com/example/demo/Events/EventController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.example.demo.Events; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/events") | ||
public class EventController { | ||
|
||
@Autowired | ||
private EventService eventService; | ||
|
||
@GetMapping | ||
public List<Event> getAllEvents() { | ||
return eventService.getAllEvents(); | ||
} | ||
|
||
@PostMapping | ||
public Event createEvent(@RequestBody Event event) { | ||
return eventService.createEvent(event); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<Event> updateEvent(@PathVariable Long id, @RequestBody Event eventDetails) { | ||
Event updatedEvent = eventService.updateEvent(id, eventDetails); | ||
return ResponseEntity.ok(updatedEvent); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteEvent(@PathVariable Long id) { | ||
eventService.deleteEvent(id); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
back-end/src/main/java/com/example/demo/Events/EventRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example.demo.Events; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface EventRepository extends JpaRepository<Event, Long> { | ||
} |
43 changes: 43 additions & 0 deletions
43
back-end/src/main/java/com/example/demo/Events/EventService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.example.demo.Events; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class EventService { | ||
|
||
@Autowired | ||
private EventRepository eventRepository; | ||
|
||
public List<Event> getAllEvents() { | ||
return eventRepository.findAll(); | ||
} | ||
|
||
public Optional<Event> getEventById(Long id) { | ||
return eventRepository.findById(id); | ||
} | ||
|
||
public Event createEvent(Event event) { | ||
return eventRepository.save(event); | ||
} | ||
|
||
public Event updateEvent(Long id, Event eventDetails) { | ||
Event event = eventRepository.findById(id) | ||
.orElseThrow(() -> new RuntimeException("Event not found")); | ||
|
||
event.setTitle(eventDetails.getTitle()); | ||
event.setDetails(eventDetails.getDetails()); | ||
event.setDate(eventDetails.getDate()); | ||
event.setTime(eventDetails.getTime()); | ||
event.setVenue(eventDetails.getVenue()); | ||
|
||
return eventRepository.save(event); | ||
} | ||
|
||
public void deleteEvent(Long id) { | ||
eventRepository.deleteById(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.