-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
77 additions
and
7 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
23 changes: 17 additions & 6 deletions
23
src/main/java/ch/fhnw/deardevbackend/controller/TeamController.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 |
---|---|---|
@@ -1,25 +1,36 @@ | ||
package ch.fhnw.deardevbackend.controller; | ||
|
||
import ch.fhnw.deardevbackend.controller.exceptions.ErrorResponse; | ||
import ch.fhnw.deardevbackend.controller.exceptions.YappiException; | ||
import ch.fhnw.deardevbackend.dto.CreateTeamDTO; | ||
import ch.fhnw.deardevbackend.dto.JoinTeamDTO; | ||
import ch.fhnw.deardevbackend.entities.Team; | ||
import ch.fhnw.deardevbackend.services.TeamService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("v1/") | ||
@RequestMapping("v1/team") | ||
public class TeamController { | ||
|
||
@Autowired | ||
private TeamService teamService; | ||
|
||
@PostMapping("/team/create") | ||
@PostMapping("/create") | ||
public ResponseEntity<Team> createTeam(@RequestBody CreateTeamDTO request) { | ||
Team createdTeam = teamService.createTeam(request); | ||
return ResponseEntity.ok().body(createdTeam); | ||
} | ||
|
||
@PostMapping("/join") | ||
public ResponseEntity<Team> joinTeam(@RequestBody JoinTeamDTO request) { | ||
Team team = teamService.joinTeam(request); | ||
return ResponseEntity.ok().body(team); | ||
} | ||
|
||
@ExceptionHandler(YappiException.class) | ||
public ResponseEntity<ErrorResponse> handleYappiException(YappiException ex) { | ||
return ResponseEntity.badRequest().body(new ErrorResponse(ex.getMessage())); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/ch/fhnw/deardevbackend/controller/exceptions/ErrorResponse.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,10 @@ | ||
package ch.fhnw.deardevbackend.controller.exceptions; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
public class ErrorResponse { | ||
private String message; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/ch/fhnw/deardevbackend/controller/exceptions/YappiException.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,12 @@ | ||
package ch.fhnw.deardevbackend.controller.exceptions; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@EqualsAndHashCode(callSuper = true) | ||
@Data | ||
@AllArgsConstructor | ||
public class YappiException extends RuntimeException { | ||
private final String message; | ||
} |
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,9 @@ | ||
package ch.fhnw.deardevbackend.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class JoinTeamDTO { | ||
private String code; | ||
private int userId; | ||
} |
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