Skip to content

Commit

Permalink
Merge branch 'cepdnaclk:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rash0621 authored Oct 10, 2024
2 parents 342b166 + 2263ecb commit f25d3fd
Show file tree
Hide file tree
Showing 12 changed files with 601 additions and 37 deletions.
69 changes: 69 additions & 0 deletions back-end/src/main/java/com/example/demo/Events/Event.java
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;
}
}
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();
}
}
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 back-end/src/main/java/com/example/demo/Events/EventService.java
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.authorizeHttpRequests(authz -> authz

.requestMatchers("/api/v*/registration/**", "/api/v1/news/**", "/api/v1/gallery/**", "/api/v*/files/**",
"/api/v*/registration/login/**", "/oauth2/**","/api/v1/tasks/**", "/api/v1/users/**", "/deliverable/**", "/workplan/**", "/api/project/**")
"/api/v*/registration/login/**", "/oauth2/**","/api/v1/tasks/**", "/api/v1/users/**", "/deliverable/**", "/workplan/**", "/api/project/**", "/api/v1/events/**")

.permitAll()
.anyRequest().authenticated()
Expand Down
Loading

0 comments on commit f25d3fd

Please sign in to comment.