Add UserController class for user management endpoints
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
package com.humanbooster.controller;
|
||||||
|
|
||||||
|
import com.humanbooster.config.HibernateConfig;
|
||||||
|
import com.humanbooster.dao.UserDao;
|
||||||
|
import com.humanbooster.model.User;
|
||||||
|
import jakarta.ws.rs.*;
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Path("/users")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
SessionFactory sessionFactory = HibernateConfig.getSessionFactory();
|
||||||
|
|
||||||
|
private final UserDao dao = new UserDao(sessionFactory);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
public List<User> getAll() {
|
||||||
|
return dao.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{id}")
|
||||||
|
public User getById(@PathParam("id") Long id) {
|
||||||
|
return dao.read(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
public void create(User person) {
|
||||||
|
dao.create(person);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/{id}")
|
||||||
|
public void update(@PathParam("id") Long id, User user) {
|
||||||
|
user.setId(id);
|
||||||
|
dao.update(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
@Path("/{id}")
|
||||||
|
public void delete(@PathParam("id") Long id) {
|
||||||
|
System.out.println();
|
||||||
|
dao.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user