task(module-web): add UserController
This commit is contained in:
parent
96f1fd7619
commit
933452ecc2
51
module-web/src/main/java/pl/myboardgames/UserController.java
Normal file
51
module-web/src/main/java/pl/myboardgames/UserController.java
Normal file
@ -0,0 +1,51 @@
|
||||
package pl.myboardgames;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@Path("/user")
|
||||
@RequestScoped
|
||||
public class UserController {
|
||||
|
||||
@GET
|
||||
@Produces("application/json; charset=UTF-8")
|
||||
public Response getAllUsers() {
|
||||
|
||||
UserEntity user1 = new UserEntity("test");
|
||||
|
||||
BoardGameEntity board1 = new BoardGameEntity("Dominion");
|
||||
BoardGameEntity board2 = new BoardGameEntity("Agricola");
|
||||
|
||||
user1.addBoard(board1);
|
||||
user1.addBoard(board2);
|
||||
|
||||
List<UserEntity> ret = new ArrayList<>();
|
||||
|
||||
ret.add(user1);
|
||||
|
||||
return Response.status(200).entity(ret).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{id}")
|
||||
@Produces("application/json; charset=UTF-8")
|
||||
public Response getUser(@PathParam("id") String id) {
|
||||
|
||||
UserEntity user1 = new UserEntity("test");
|
||||
|
||||
BoardGameEntity board1 = new BoardGameEntity("Dominion");
|
||||
BoardGameEntity board2 = new BoardGameEntity("Agricola");
|
||||
|
||||
user1.addBoard(board1);
|
||||
user1.addBoard(board2);
|
||||
|
||||
|
||||
return Response.status(200).entity(user1).build();
|
||||
}
|
||||
}
|
@ -1,14 +1,31 @@
|
||||
package pl.myboardgames;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class UserEntity {
|
||||
private String name;
|
||||
private List<BoardGameEntity> boardgames;
|
||||
private String username;
|
||||
private ArrayList<BoardGameEntity> boardgames = new ArrayList();
|
||||
|
||||
|
||||
public UserEntity(String name) {
|
||||
this.username = name;
|
||||
}
|
||||
|
||||
public void addBoard(BoardGameEntity board) {
|
||||
this.boardgames.add(board);
|
||||
}
|
||||
|
||||
public void setBoardgames(ArrayList<BoardGameEntity> boardgames) {
|
||||
this.boardgames = boardgames;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public ArrayList<BoardGameEntity> getBoardgames() {
|
||||
return boardgames;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user