Last active
April 2, 2019 17:52
-
-
Save dapperAuteur/e0c9abd1a55ddf6fcfd9af6862c4e056 to your computer and use it in GitHub Desktop.
this is the controller and repository
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.intraedge.project.prok.controllers; | |
import java.util.List; | |
import javax.validation.Valid; | |
import org.bson.types.ObjectId; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.web.bind.annotation.PathVariable; | |
import org.springframework.web.bind.annotation.RequestBody; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestMethod; | |
import org.springframework.web.bind.annotation.RestController; | |
import com.intraedge.project.prok.domain.League; | |
import com.intraedge.project.prok.repositories.LeagueRepository; | |
@RestController | |
//@RequestMapping("/leagues") | |
public class LeagueController { | |
@Autowired | |
private LeagueRepository leagueRepository; | |
@RequestMapping(value="/leagues", method=RequestMethod.GET) | |
public List<League> getLeagues(){ | |
return leagueRepository.findAll(); | |
} | |
@RequestMapping(value="/{id}", method=RequestMethod.GET) | |
public League getLeagueById(@PathVariable("id") ObjectId _id) { | |
return leagueRepository.findBy_id(_id); | |
} | |
@RequestMapping(value="/{id}", method=RequestMethod.PUT) | |
public League modifyLeagueById(@PathVariable("id") ObjectId _id, @Valid @RequestBody League league) { | |
league.set_id(_id); | |
leagueRepository.save(league); | |
return league; | |
} | |
@RequestMapping(value="/", method=RequestMethod.POST) | |
public League createLeague(@Valid @RequestBody League league) { | |
league.set_id(ObjectId.get()); | |
leagueRepository.save(league); | |
return league; | |
} | |
@RequestMapping(value="/{id}", method=RequestMethod.DELETE) | |
public void deleteLeague(@PathVariable ObjectId _id) { | |
leagueRepository.delete(leagueRepository.findBy_id(_id)); | |
} | |
} | |
//Repository LeagueRepository | |
package com.intraedge.project.prok.repositories; | |
import org.bson.types.ObjectId; | |
import org.springframework.data.mongodb.repository.MongoRepository; | |
import com.intraedge.project.prok.domain.League; | |
public interface LeagueRepository extends MongoRepository<League, String> { | |
League findBy_id(ObjectId _id); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment