Skip to content

Commit 49df95c

Browse files
committed
feat(issues): apply issues
1 parent faf4647 commit 49df95c

27 files changed

Lines changed: 459 additions & 147 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
application-local.properties
2+
.env
13
HELP.md
24
target/
35
.mvn/wrapper/maven-wrapper.jar

README.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,55 @@ The interactive API documentation is available via **Swagger UI / OpenAPI**.
3030

3131
## ⚙️ Configuration
3232

33-
The main configuration file is located at:
33+
34+
The main configuration file is:
3435

3536
```
3637
src/main/resources/application.properties
3738
```
3839

39-
### Properties to configure
40+
But for credentials and local overrides, use:
41+
42+
```
43+
src/main/resources/application-local.properties
44+
```
45+
46+
### Example for application.properties
4047

4148
```properties
4249
spring.application.name=spring_boot_java_random_user
43-
44-
# Swagger UI — available at /api
4550
springdoc.swagger-ui.path=/api
46-
47-
# PostgreSQL datasource (add these if you use persistence)
4851
spring.datasource.url=jdbc:postgresql://localhost:5432/<database_name>
49-
spring.datasource.username=<username>
50-
spring.datasource.password=<password>
5152
spring.datasource.driver-class-name=org.postgresql.Driver
5253
```
5354

55+
### Local credentials & security
56+
57+
To avoid exposing database credentials in source code, create a `.env` file at the project root (not versioned):
58+
59+
```
60+
DB_USER=postgres
61+
DB_PASSWORD=postgres
62+
```
63+
64+
Then, in `src/main/resources/application-local.properties`:
65+
66+
```properties
67+
spring.datasource.username=${DB_USER}
68+
spring.datasource.password=${DB_PASSWORD}
69+
```
70+
71+
Both `.env` and `application-local.properties` are in `.gitignore` (already set).
72+
73+
To activate the local profile in IntelliJ or VS Code, add this environment variable to your run configuration:
74+
75+
```
76+
SPRING_PROFILES_ACTIVE=local
77+
```
78+
79+
This way, each developer can use their own credentials without risk of leaking them to GitHub.
80+
81+
5482
> ⚠️ **Common startup error**:
5583
> ```
5684
> Failed to configure a DataSource: 'url' attribute is not specified
@@ -196,7 +224,7 @@ This project consumes the public **Random User Generator** API:
196224

197225
- [x] [Add Sonarqube in the project](https://github.com/XPEHO/spring_boot_java_random_user/issues/2)
198226
- [ ] [Add PostgreSQL database with docker](https://github.com/XPEHO/spring_boot_java_random_user/issues/6)
199-
- [X] [Add this endpoint get /user/random](https://github.com/XPEHO/spring_boot_java_random_user/issues/5)
227+
- [X] [Add this endpoint get /random-users](https://github.com/XPEHO/spring_boot_java_random_user/issues/5)
200228
- [ ] [Add this endpoint get /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/8)
201229
- [ ] [Add this endpoint put /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/9)
202230
- [ ] [Add this endpoint delete /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/10)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<dependency>
4040
<groupId>com.squareup.retrofit2</groupId>
4141
<artifactId>converter-gson</artifactId>
42-
<version>2.9.0</version>
42+
<version>2.11.0</version>
4343
</dependency>
4444
<dependency>
4545
<groupId>org.springframework.boot</groupId>
Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,72 @@
11
package com.xpeho.spring_boot_java_random_user.data.converters;
2-
3-
import com.xpeho.spring_boot_java_random_user.data.models.RandomUserResultDAO;
2+
import com.xpeho.spring_boot_java_random_user.data.models.api.RandomUserResultDAO;
43
import com.xpeho.spring_boot_java_random_user.domain.entities.UserEntity;
4+
import com.xpeho.spring_boot_java_random_user.data.models.db.User;
55
import org.springframework.stereotype.Service;
6+
import com.xpeho.spring_boot_java_random_user.presentation.dto.UserDTO;
7+
68

79
@Service
810
public class UserConverter {
9-
public UserEntity modelToEntity(RandomUserResultDAO model) {
10-
UserEntity entity = new UserEntity();
11-
entity.setGender(model.gender);
12-
entity.setFirstname(model.name.first);
13-
entity.setLastname(model.name.last);
14-
entity.setCivility(model.name.title);
15-
entity.setEmail(model.email);
16-
entity.setPhone(model.phone);
17-
entity.setPicture(model.picture.medium);
18-
entity.setNat(model.nat);
19-
return entity;
11+
// Domain -> DAO
12+
public User toDao(UserEntity entity) {
13+
User user = new User();
14+
user.setId(entity.id());
15+
user.setFirstName(entity.firstname());
16+
user.setLastName(entity.lastname());
17+
user.setEmail(entity.email());
18+
user.setPictureUrl(entity.picture());
19+
return user;
20+
}
21+
// DAO -> Domain
22+
public UserEntity toDomain(User user) {
23+
return new UserEntity(
24+
user.getId(),
25+
// gender
26+
null,
27+
user.getFirstName(),
28+
user.getLastName(),
29+
// civility
30+
null,
31+
user.getEmail(),
32+
// phone
33+
null,
34+
user.getPictureUrl(),
35+
// nat
36+
null
37+
);
38+
}
39+
// API -> Domain
40+
public UserEntity fromApiModel(RandomUserResultDAO model) {
41+
String firstName = model.name != null ? model.name.first : null;
42+
String lastName = model.name != null ? model.name.last : null;
43+
String civility = model.name != null ? model.name.title : null;
44+
String picture = model.picture != null ? model.picture.medium : null;
45+
return new UserEntity(
46+
null,
47+
model.gender,
48+
firstName,
49+
lastName,
50+
civility,
51+
model.email,
52+
model.phone,
53+
picture,
54+
model.nat
55+
);
56+
}
57+
58+
// Domain -> DTO
59+
public UserDTO toDto(UserEntity entity) {
60+
return new UserDTO(
61+
entity.id(),
62+
entity.gender(),
63+
entity.firstname(),
64+
entity.lastname(),
65+
entity.civility(),
66+
entity.email(),
67+
entity.phone(),
68+
entity.picture(),
69+
entity.nat()
70+
);
2071
}
2172
}

src/main/java/com/xpeho/spring_boot_java_random_user/data/models/RandomUserInfoDAO.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/main/java/com/xpeho/spring_boot_java_random_user/data/models/RandomUserResponseDAO.java

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/main/java/com/xpeho/spring_boot_java_random_user/data/models/RandomUserNameDAO.java renamed to src/main/java/com/xpeho/spring_boot_java_random_user/data/models/api/RandomUserNameDAO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.xpeho.spring_boot_java_random_user.data.models;
1+
package com.xpeho.spring_boot_java_random_user.data.models.api;
22

33
public class RandomUserNameDAO {
44
public String title;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.xpeho.spring_boot_java_random_user.data.models.api;
2+
3+
public class RandomUserPictureDAO {
4+
public String medium;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.xpeho.spring_boot_java_random_user.data.models.api;
2+
3+
public class RandomUserResponse {
4+
public RandomUserResultDAO[] results;
5+
}

src/main/java/com/xpeho/spring_boot_java_random_user/data/models/RandomUserResultDAO.java renamed to src/main/java/com/xpeho/spring_boot_java_random_user/data/models/api/RandomUserResultDAO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.xpeho.spring_boot_java_random_user.data.models;
1+
package com.xpeho.spring_boot_java_random_user.data.models.api;
22

33
public class RandomUserResultDAO {
44
public String gender;

0 commit comments

Comments
 (0)