Skip to content

Commit d25827e

Browse files
committed
feat(getRandomUser): endpoint get Random user
1 parent bb65eac commit d25827e

20 files changed

Lines changed: 331 additions & 6 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ This project consumes the public **Random User Generator** API:
158158

159159
- [ ] [Add Sonarqube in the project](https://github.com/XPEHO/spring_boot_java_random_user/issues/2)
160160
- [ ] [Add PostgreSQL database with docker](https://github.com/XPEHO/spring_boot_java_random_user/issues/6)
161-
- [ ] [Add this endpoint get /user/random](https://github.com/XPEHO/spring_boot_java_random_user/issues/5)
161+
- [X] [Add this endpoint get /user/random](https://github.com/XPEHO/spring_boot_java_random_user/issues/5)
162162
- [ ] [Add this endpoint get /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/8)
163163
- [ ] [Add this endpoint put /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/9)
164164
- [ ] [Add this endpoint delete /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/10)

docker-compose.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
services:
2+
postgres:
3+
image: postgres:15-alpine
4+
container_name: xpeho_postgres
5+
environment:
6+
POSTGRES_USER: postgres
7+
POSTGRES_PASSWORD: postgres
8+
POSTGRES_DB: xpeho_db
9+
ports:
10+
- "5432:5432"
11+
volumes:
12+
- postgres_data:/var/lib/postgresql/data
13+
- ./src/main/resources/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql
14+
# INIT DATA
15+
# - ./src/main/resources/data.sql:/docker-entrypoint-initdb.d/02-data.sql
16+
networks:
17+
- xpeho_network
18+
19+
volumes:
20+
postgres_data:
21+
driver: local
22+
23+
networks:
24+
xpeho_network:
25+
driver: bridge
26+

pom.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@
3434
<groupId>org.springframework.boot</groupId>
3535
<artifactId>spring-boot-starter-actuator</artifactId>
3636
</dependency>
37-
<!-- <dependency>-->
38-
<!-- <groupId>org.springframework.boot</groupId>-->
39-
<!-- <artifactId>spring-boot-starter-data-jdbc</artifactId>-->
40-
<!-- </dependency>-->
37+
<dependency>
38+
<groupId>com.squareup.retrofit2</groupId>
39+
<artifactId>converter-gson</artifactId>
40+
<version>2.9.0</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-starter-data-jdbc</artifactId>
45+
</dependency>
4146
<dependency>
4247
<groupId>org.springframework.boot</groupId>
4348
<artifactId>spring-boot-starter-webmvc</artifactId>
4449
</dependency>
45-
4650
<dependency>
4751
<groupId>org.springdoc</groupId>
4852
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.xpeho.spring_boot_java_random_user.data.converters;
2+
3+
import com.xpeho.spring_boot_java_random_user.data.models.RandomUserResultDAO;
4+
import com.xpeho.spring_boot_java_random_user.domain.entities.UserEntity;
5+
import org.springframework.stereotype.Service;
6+
7+
@Service
8+
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;
20+
}
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.xpeho.spring_boot_java_random_user.data.models;
2+
3+
public class RandomUserInfoDAO {
4+
public String seed;
5+
public int results;
6+
public int page;
7+
public String version;
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.xpeho.spring_boot_java_random_user.data.models;
2+
3+
public class RandomUserNameDAO {
4+
public String title;
5+
public String first;
6+
public String last;
7+
}
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;
2+
3+
public class RandomUserPictureDAO {
4+
public String medium;
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.xpeho.spring_boot_java_random_user.data.models;
2+
3+
public class RandomUserResponseDAO {
4+
public RandomUserResultDAO[] results;
5+
public RandomUserInfoDAO info;
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.xpeho.spring_boot_java_random_user.data.models;
2+
3+
public class RandomUserResultDAO {
4+
public String gender;
5+
public RandomUserNameDAO name;
6+
public String email;
7+
public String phone;
8+
public RandomUserPictureDAO picture;
9+
public String nat;
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.xpeho.spring_boot_java_random_user.data.repositories;
2+
3+
import com.xpeho.spring_boot_java_random_user.domain.entities.UserEntity;
4+
import org.springframework.data.repository.CrudRepository;
5+
6+
public interface UserRepository extends CrudRepository<UserEntity, Long> {
7+
}

0 commit comments

Comments
 (0)