Last active
September 27, 2020 06:57
-
-
Save Patrick5455/cedf9a7b8ef8cf0ac7f5a4dc7ff37c9f to your computer and use it in GitHub Desktop.
Conference Scheduling App
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.conferenceschedulingapp.controllers; | |
import com.conferenceschedulingapp.models.Session; | |
import com.conferenceschedulingapp.repositories.SessionRepo; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.http.HttpStatus; | |
import org.springframework.web.bind.annotation.*; | |
import java.util.List; | |
@RestController | |
@RequestMapping("/api/v1/sessions") | |
public class SessionController { | |
@Autowired | |
private SessionRepo sessionRepo; | |
@GetMapping | |
public List<Session> listSession(){ | |
return sessionRepo.findAll(); | |
} | |
@GetMapping | |
@RequestMapping("{id") | |
public Session getSession(@PathVariable Long id){ | |
return sessionRepo.getOne(id); | |
} | |
@PostMapping | |
@ResponseStatus(HttpStatus.CREATED) // to specify the type of response we are doing and override the default 100 response | |
public Session createSession(@RequestBody final Session session){ | |
// save an object and flush it to the database | |
return sessionRepo.saveAndFlush(session); | |
} | |
@RequestMapping(value = ("{id}"), method = RequestMethod.DELETE) | |
public void deleteSession(@PathVariable Long id){ | |
// Also need to check for children records before deleting | |
sessionRepo.deleteById(id); | |
} | |
package com.conferenceschedulingapp.controllers; | |
import com.conferenceschedulingapp.models.Speaker; | |
import com.conferenceschedulingapp.repositories.SpeakerRepo; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.http.HttpStatus; | |
import org.springframework.web.bind.annotation.*; | |
import java.util.List; | |
@RestController | |
@RequestMapping("/api/v1/speakers") | |
public class SpeakerController { | |
@Autowired | |
private SpeakerRepo speakerRepo; | |
@GetMapping | |
public List<Speaker> listSpeakers(){ | |
return speakerRepo.findAll(); | |
} | |
@GetMapping | |
@RequestMapping("{id}") | |
public Speaker getSpeaker(@PathVariable Long id){ | |
return speakerRepo.getOne(id); | |
} | |
@PostMapping | |
@ResponseStatus(HttpStatus.CREATED) // to specify the type of response we are doing and override the default 100 response | |
public Speaker createSpeaker(@RequestBody final Speaker speaker){ | |
return speakerRepo.saveAndFlush(speaker); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment