generated from alkemyTech/base-ong-server-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OT276-36] Endpoint para listar Usuarios (#28)
* Added getList() method to UserService * Implementation of getList() method in UserServiceImpl * Creation of UserResponse in response package * Creation of UserControllerMapper in mapper package * Creation of UserController in controller package * Added configuration for path '/v1/users' in SecurityConfig * Added Transactional to getList() in UserServiceImpl * Switch to JpaRepository in UserRepository * Refactor of getUsers() method in UserController * Added '@IterableMapping' to UserControllerMapper and Reformat Code to UserController
- Loading branch information
Showing
7 changed files
with
100 additions
and
5 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
4 changes: 2 additions & 2 deletions
4
src/main/java/com/alkemy/ong/core/repository/UserRepository.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,10 +1,10 @@ | ||
package com.alkemy.ong.core.repository; | ||
|
||
import com.alkemy.ong.core.model.User; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface UserRepository extends CrudRepository<User, Long> { | ||
public interface UserRepository extends JpaRepository<User, Long> { | ||
Optional<User> findByEmail(String email); | ||
} |
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,8 +1,12 @@ | ||
package com.alkemy.ong.core.usecase; | ||
|
||
|
||
import com.alkemy.ong.core.model.User; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
|
||
import java.util.List; | ||
|
||
public interface UserService extends UserDetailsService { | ||
|
||
List<User> getList(); | ||
|
||
} |
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/alkemy/ong/ports/input/rs/controller/UserController.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,34 @@ | ||
package com.alkemy.ong.ports.input.rs.controller; | ||
|
||
import com.alkemy.ong.core.model.User; | ||
import com.alkemy.ong.core.usecase.UserService; | ||
import com.alkemy.ong.ports.input.rs.mapper.UserControllerMapper; | ||
import com.alkemy.ong.ports.input.rs.response.UserResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
import static com.alkemy.ong.ports.input.rs.api.ApiConstants.USERS_URI; | ||
|
||
@RestController | ||
@RequestMapping(USERS_URI) | ||
@RequiredArgsConstructor | ||
public class UserController { | ||
|
||
private final UserService service; | ||
private final UserControllerMapper mapper; | ||
|
||
@GetMapping | ||
public ResponseEntity<List<UserResponse>> getUsers() { | ||
|
||
List<User> list = service.getList(); | ||
List<UserResponse> response = mapper.userListToUserResponseList(list); | ||
|
||
return ResponseEntity.ok().body(response); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/alkemy/ong/ports/input/rs/mapper/UserControllerMapper.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,20 @@ | ||
package com.alkemy.ong.ports.input.rs.mapper; | ||
|
||
import com.alkemy.ong.core.model.User; | ||
import com.alkemy.ong.ports.input.rs.response.UserResponse; | ||
import org.mapstruct.IterableMapping; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Named; | ||
|
||
import java.util.List; | ||
|
||
@Mapper | ||
public interface UserControllerMapper extends CommonMapper { | ||
|
||
@Named("userToUserResponse") | ||
UserResponse userToUserResponse(User user); | ||
|
||
@Named("userListToUserResponseList") | ||
@IterableMapping(qualifiedByName = "userToUserResponse") | ||
List<UserResponse> userListToUserResponseList(List<User> users); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/alkemy/ong/ports/input/rs/response/UserResponse.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,27 @@ | ||
package com.alkemy.ong.ports.input.rs.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class UserResponse { | ||
|
||
private Long id; | ||
|
||
@JsonProperty("first_Name") | ||
private String firstName; | ||
|
||
@JsonProperty("last_Name") | ||
private String lastName; | ||
|
||
private String email; | ||
|
||
private String photo; | ||
|
||
} |