-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathEventController.java
More file actions
43 lines (35 loc) · 1.48 KB
/
EventController.java
File metadata and controls
43 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.kipper.eventsmicroservice.controllers;
import com.kipper.eventsmicroservice.domain.Event;
import com.kipper.eventsmicroservice.dtos.EventRequestDTO;
import com.kipper.eventsmicroservice.dtos.SubscriptionRequestDTO;
import com.kipper.eventsmicroservice.exceptions.EventFullException;
import com.kipper.eventsmicroservice.exceptions.EventNotFoundException;
import com.kipper.eventsmicroservice.services.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/events")
public class EventController {
@Autowired
private EventService eventService;
@GetMapping
public List<Event> getAllEvents() {
return eventService.getAllEvents();
}
@GetMapping("/upcoming")
public List<Event> getUpcomingEvents() {
return eventService.getUpcomingEvents();
}
@PostMapping
public Event createEvent(@RequestBody EventRequestDTO event) {
return eventService.createEvent(event);
}
@PostMapping("/{eventId}/register")
public ResponseEntity<String> registerParticipant(@PathVariable String eventId, @RequestBody SubscriptionRequestDTO subscriptionRequest) {
eventService.registerParticipant(eventId, subscriptionRequest.participantEmail());
return ResponseEntity.ok("Subscription confirmed successfully");
}
}