mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
Create first new dummy user resource
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package sonia.scm.api.rest.resources;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserDto {
|
||||
private String name;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package sonia.scm.api.rest.resources;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import sonia.scm.user.User;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
UserMapper INSTANCE = Mappers.getMapper( UserMapper.class );
|
||||
|
||||
@Mapping(source = "name", target = "name")
|
||||
UserDto userToUserDto(User user);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package sonia.scm.api.rest.resources;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
|
||||
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||
import com.webcohesion.enunciate.metadata.rs.TypeHint;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import sonia.scm.Manager;
|
||||
import sonia.scm.security.Role;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserException;
|
||||
import sonia.scm.user.UserManager;
|
||||
|
||||
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.*;
|
||||
import java.util.Collection;
|
||||
|
||||
@Singleton
|
||||
@Path("usersnew")
|
||||
public class UserNewResource extends AbstractManagerResource<User, UserException>
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String PATH_PART = "usersnew";
|
||||
|
||||
@Inject
|
||||
public UserNewResource(UserManager userManager) {
|
||||
super(userManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GenericEntity<Collection<User>> createGenericEntity(Collection<User> items) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getId(User user) {
|
||||
return user.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPathPart() {
|
||||
return PATH_PART;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@TypeHint(UserDto.class)
|
||||
@StatusCodes({
|
||||
@ResponseCode(code = 200, condition = "success"),
|
||||
@ResponseCode(code = 403, condition = "forbidden, the current user has no admin privileges"),
|
||||
@ResponseCode(code = 404, condition = "not found, no group with the specified id/name available"),
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
@Override
|
||||
public Response get(@Context Request request, @PathParam("id") String id)
|
||||
{
|
||||
if (SecurityUtils.getSubject().hasRole(Role.ADMIN))
|
||||
{
|
||||
User user = manager.get(id);
|
||||
UserDto userDto = UserMapper.INSTANCE.userToUserDto(user);
|
||||
return Response.ok(userDto).build();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Response.status(Response.Status.FORBIDDEN).build();
|
||||
}
|
||||
}}
|
||||
Reference in New Issue
Block a user