Last active
July 10, 2022 21:02
-
-
Save garystafford/4d928f3c37ca186f4392e724be79f7ae to your computer and use it in GitHub Desktop.
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
package com.example.athena.tickit.controller; | |
import com.example.athena.tickit.model.saas.Event; | |
import com.example.athena.tickit.service.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(value = "/events") | |
public class EventController { | |
private final EventService service; | |
@Autowired | |
public EventController(EventService service) { | |
this.service = service; | |
} | |
@RequestMapping(method = RequestMethod.GET) | |
public ResponseEntity<List<Event>> findAll( | |
@RequestParam(required = false) Integer limit, | |
@RequestParam(required = false) Integer offset | |
) { | |
List<Event> events = service.findAll(limit, offset); | |
if (events.size() == 0) { | |
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); | |
} | |
return ResponseEntity.status(HttpStatus.OK).body(events); | |
} | |
@RequestMapping(value = "/{id}", method = RequestMethod.GET) | |
public ResponseEntity<Event> findById(@PathVariable("id") int id) { | |
Event event = service.findById(id); | |
if (event == null) { | |
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); | |
} | |
return ResponseEntity.status(HttpStatus.OK).body(event); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment