This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #265 from SELab-2/development
Dev into main
- Loading branch information
Showing
142 changed files
with
12,784 additions
and
1,983 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
### Checklist | ||
|
||
Remove items if they're not applicable. | ||
|
||
**New feature checklist**: | ||
- [ ] I've added tests for the new feature (100% coverage) | ||
- [ ] I've thoroughly documented the code | ||
- [ ] I've updated the `osoc.yaml` file | ||
|
||
|
||
**Breaking change checklist**: | ||
- [ ] I've updated the existing tests to account for the changes in expected behavior | ||
- [ ] I've updated the documentation to reflect the new behavior | ||
- [ ] I've updated the `osoc.yaml` file |
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 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 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
60 changes: 60 additions & 0 deletions
60
backend/src/main/kotlin/be/osoc/team1/backend/controllers/BaseController.kt
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,60 @@ | ||
package be.osoc.team1.backend.controllers | ||
|
||
import be.osoc.team1.backend.entities.Answer | ||
import be.osoc.team1.backend.entities.Assignment | ||
import be.osoc.team1.backend.entities.Position | ||
import be.osoc.team1.backend.entities.Skill | ||
import be.osoc.team1.backend.entities.StatusSuggestion | ||
import be.osoc.team1.backend.services.AnswerService | ||
import be.osoc.team1.backend.services.AssignmentService | ||
import be.osoc.team1.backend.services.BaseService | ||
import be.osoc.team1.backend.services.PositionService | ||
import be.osoc.team1.backend.services.SkillService | ||
import be.osoc.team1.backend.services.StatusSuggestionService | ||
import org.springframework.security.access.annotation.Secured | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import java.util.UUID | ||
|
||
abstract class BaseController<T, K>(open val service: BaseService<T, K>) { | ||
|
||
/** | ||
* Returns the [T] with the corresponding [id]. If no such [T] exists, returns a | ||
* "404: Not Found" message instead. | ||
*/ | ||
@GetMapping("/{id}") | ||
@Secured("ROLE_COACH") | ||
fun getById(@PathVariable id: K): T = service.getById(id) | ||
} | ||
|
||
abstract class BaseAllController<T, K>(service: BaseService<T, K>) : BaseController<T, K>(service) { | ||
|
||
/** | ||
* Returns all objects of type [T]. | ||
*/ | ||
@GetMapping | ||
@Secured("ROLE_COACH") | ||
fun getAll(): Iterable<T> = service.getAll() | ||
} | ||
|
||
@RestController | ||
@RequestMapping("/assignments") | ||
class AssignmentController(service: AssignmentService) : BaseController<Assignment, UUID>(service) | ||
|
||
@RestController | ||
@RequestMapping("/positions") | ||
class PositionController(service: PositionService) : BaseController<Position, UUID>(service) | ||
|
||
@RestController | ||
@RequestMapping("/statusSuggestions") | ||
class StatusSuggestionController(service: StatusSuggestionService) : BaseController<StatusSuggestion, UUID>(service) | ||
|
||
@RestController | ||
@RequestMapping("/answers") | ||
class AnswerController(service: AnswerService) : BaseController<Answer, UUID>(service) | ||
|
||
@RestController | ||
@RequestMapping("/skills") | ||
class SkillController(service: SkillService) : BaseAllController<Skill, String>(service) |
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
29 changes: 29 additions & 0 deletions
29
backend/src/main/kotlin/be/osoc/team1/backend/controllers/ControllersUtil.kt
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,29 @@ | ||
package be.osoc.team1.backend.controllers | ||
|
||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder | ||
|
||
/** | ||
* Utility method that takes an object that was just created by a service method and it's [id], | ||
* and returns a [ResponseEntity] with the [HttpStatus.CREATED] status containing the [createdObject] in the body. | ||
* Additionally, the location header will be set to the path of the POST request that requested the creation | ||
* of the object, with the given [id] added at the end. | ||
* | ||
* For example, if the path to the POST request is: | ||
* | ||
* `/api/students` | ||
* | ||
* Then the location header will contain: | ||
* | ||
* `/api/students/(INSERT ID)` | ||
*/ | ||
fun <ID, T> getObjectCreatedResponse(id: ID, createdObject: T, status: HttpStatus = HttpStatus.CREATED): ResponseEntity<T> { | ||
val postRequestPath = ServletUriComponentsBuilder.fromCurrentRequest() | ||
val pathWithIdAdded = postRequestPath.path("/{id}").buildAndExpand(id).toUriString() | ||
return ResponseEntity | ||
.status(status) | ||
.header(HttpHeaders.LOCATION, pathWithIdAdded) | ||
.body(createdObject) | ||
} |
Oops, something went wrong.