-
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.
Merge pull request #78 from JimTheCat/CU-8696y76jy_EPIC---API-v3_King…
…a-Traczyk feature: Create BasicUserInfoDto
- Loading branch information
Showing
6 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
backend/src/main/java/meowhub/backend/users/controllers/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,27 @@ | ||
package meowhub.backend.users.controllers; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import meowhub.backend.users.dtos.BasicUserInfoDto; | ||
import meowhub.backend.users.services.UserService; | ||
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 org.webjars.NotFoundException; | ||
|
||
@RestController | ||
@RequestMapping("/api/users") | ||
@RequiredArgsConstructor | ||
public class UserController { | ||
private final UserService userService; | ||
|
||
@GetMapping("get-basic-user-info") | ||
public ResponseEntity<BasicUserInfoDto> getBasicUserInfo(String login) { | ||
try { | ||
userService.getBasicUserInfo(login); | ||
return ResponseEntity.ok(userService.getBasicUserInfo(login)); | ||
} catch (NotFoundException e) { | ||
return ResponseEntity.notFound().build(); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
backend/src/main/java/meowhub/backend/users/dtos/BasicUserInfoDto.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,16 @@ | ||
package meowhub.backend.users.dtos; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
public class BasicUserInfoDto { | ||
private String id; | ||
private String name; | ||
private String surname; | ||
private String login; | ||
private byte[] profilePicture; | ||
} |
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
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
48 changes: 48 additions & 0 deletions
48
backend/src/test/java/meowhub/backend/users/UserRepositoryIntegrationTest.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,48 @@ | ||
package meowhub.backend.users; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import meowhub.backend.InitDataTestConfig; | ||
import meowhub.backend.users.dtos.BasicUserInfoDto; | ||
import meowhub.backend.users.models.User; | ||
import meowhub.backend.users.repositories.UserRepository; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@DataJpaTest | ||
@ActiveProfiles("test") | ||
@RequiredArgsConstructor | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
@Import(InitDataTestConfig.class) | ||
class UserRepositoryIntegrationTest { | ||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Test | ||
void testFindUserByLogin(){ | ||
Optional<User> result = userRepository.findByLogin("admin"); | ||
assertTrue(result.isPresent()); | ||
assertEquals("admin", result.get().getLogin()); | ||
} | ||
|
||
@Test | ||
void testFindBasicUserInfoByLogin() { | ||
Optional<BasicUserInfoDto> result = userRepository.findBasicUserInfoByLogin("admin"); | ||
assertTrue(result.isPresent()); | ||
|
||
assertEquals("admin", result.get().getLogin()); | ||
assertNotNull(result.get().getId()); | ||
assertNotNull(result.get().getName()); | ||
assertNotNull(result.get().getSurname()); | ||
assertNotNull(result.get().getProfilePicture()); | ||
} | ||
} |