-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,083 additions
and
85 deletions.
There are no files selected for viewing
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
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
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
This file was deleted.
Oops, something went wrong.
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
36 changes: 36 additions & 0 deletions
36
src/main/java/io/codeka/gaia/controller/JobRestController.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.codeka.gaia.controller; | ||
|
||
import io.codeka.gaia.bo.Job; | ||
import io.codeka.gaia.repository.JobRepository; | ||
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/jobs") | ||
public class JobRestController { | ||
|
||
private JobRepository jobRepository; | ||
|
||
@Autowired | ||
public JobRestController(JobRepository jobRepository) { | ||
this.jobRepository = jobRepository; | ||
} | ||
|
||
@GetMapping(params = "stackId") | ||
public List<Job> jobs(@RequestParam String stackId){ | ||
return this.jobRepository.findAllByStackId(stackId); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public Job job(@PathVariable String id){ | ||
return this.jobRepository.findById(id).orElseThrow(JobNotFoundException::new); | ||
} | ||
|
||
} | ||
|
||
@ResponseStatus(HttpStatus.NOT_FOUND) | ||
class JobNotFoundException extends RuntimeException{ | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/io/codeka/gaia/controller/ModuleRestController.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.codeka.gaia.controller; | ||
|
||
import io.codeka.gaia.bo.TerraformModule; | ||
import io.codeka.gaia.repository.TerraformModuleRepository; | ||
import io.codeka.gaia.teams.bo.User; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.access.annotation.Secured; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Rest controller for the module API | ||
*/ | ||
@RestController | ||
@RequestMapping("/api/modules") | ||
public class ModuleRestController { | ||
|
||
private TerraformModuleRepository moduleRepository; | ||
|
||
@Autowired | ||
public ModuleRestController(TerraformModuleRepository moduleRepository) { | ||
this.moduleRepository = moduleRepository; | ||
} | ||
|
||
@GetMapping("") | ||
public List<TerraformModule> findAllModules(User user){ | ||
if(user.isAdmin()){ | ||
return moduleRepository.findAll(); | ||
} | ||
return moduleRepository.findAllByAuthorizedTeamsContaining(user.getTeam()); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public TerraformModule findModule(@PathVariable String id, User user){ | ||
if(user.isAdmin()){ | ||
return moduleRepository.findById(id).orElseThrow(ModuleNotFoundException::new); | ||
} | ||
return moduleRepository.findByIdAndAuthorizedTeamsContaining(id, user.getTeam()).orElseThrow(ModuleNotFoundException::new); | ||
} | ||
|
||
@Secured("ROLE_ADMIN") | ||
@PutMapping("/{id}") | ||
public TerraformModule saveModule(@PathVariable String id, @RequestBody TerraformModule module){ | ||
return moduleRepository.save(module); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/io/codeka/gaia/controller/StackRestController.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.codeka.gaia.controller; | ||
|
||
import io.codeka.gaia.bo.Stack; | ||
import io.codeka.gaia.repository.StackRepository; | ||
import io.codeka.gaia.teams.bo.Team; | ||
import io.codeka.gaia.teams.bo.User; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@RestController | ||
@RequestMapping("/api/stacks") | ||
public class StackRestController { | ||
|
||
private StackRepository stackRepository; | ||
|
||
@Autowired | ||
public StackRestController(StackRepository stackRepository) { | ||
this.stackRepository = stackRepository; | ||
} | ||
|
||
@GetMapping | ||
public List<Stack> listStacks(User user){ | ||
if(user.isAdmin()){ | ||
return stackRepository.findAll(); | ||
} | ||
return stackRepository.findByOwnerTeam(user.getTeam()); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public Stack getStack(@PathVariable String id, User user){ | ||
if(user.isAdmin()){ | ||
return stackRepository.findById(id).orElseThrow(StackNotFoundException::new); | ||
} | ||
return stackRepository.findByIdAndOwnerTeam(id, user.getTeam()).orElseThrow(StackNotFoundException::new); | ||
} | ||
|
||
@PostMapping() | ||
public Stack save(@RequestBody Stack stack, Team userTeam){ | ||
stack.setOwnerTeam(userTeam); | ||
stack.setId(UUID.randomUUID().toString()); | ||
return stackRepository.save(stack); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public Stack update(@PathVariable String id, @RequestBody Stack stack){ | ||
return stackRepository.save(stack); | ||
} | ||
|
||
} | ||
|
||
@ResponseStatus(HttpStatus.NOT_FOUND) | ||
class StackNotFoundException extends RuntimeException { | ||
} |
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
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
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
Oops, something went wrong.