Skip to content

Commit faf4647

Browse files
committed
feat(getRandomUser): endpoint get Random user
1 parent b061ba3 commit faf4647

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
@@ -196,7 +196,7 @@ This project consumes the public **Random User Generator** API:
196196

197197
- [x] [Add Sonarqube in the project](https://github.com/XPEHO/spring_boot_java_random_user/issues/2)
198198
- [ ] [Add PostgreSQL database with docker](https://github.com/XPEHO/spring_boot_java_random_user/issues/6)
199-
- [ ] [Add this endpoint get /user/random](https://github.com/XPEHO/spring_boot_java_random_user/issues/5)
199+
- [X] [Add this endpoint get /user/random](https://github.com/XPEHO/spring_boot_java_random_user/issues/5)
200200
- [ ] [Add this endpoint get /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/8)
201201
- [ ] [Add this endpoint put /user/{id}](https://github.com/XPEHO/spring_boot_java_random_user/issues/9)
202202
- [ ] [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
@@ -36,15 +36,19 @@
3636
<groupId>org.springframework.boot</groupId>
3737
<artifactId>spring-boot-starter-actuator</artifactId>
3838
</dependency>
39-
<!-- <dependency>-->
40-
<!-- <groupId>org.springframework.boot</groupId>-->
41-
<!-- <artifactId>spring-boot-starter-data-jdbc</artifactId>-->
42-
<!-- </dependency>-->
39+
<dependency>
40+
<groupId>com.squareup.retrofit2</groupId>
41+
<artifactId>converter-gson</artifactId>
42+
<version>2.9.0</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-starter-data-jdbc</artifactId>
47+
</dependency>
4348
<dependency>
4449
<groupId>org.springframework.boot</groupId>
4550
<artifactId>spring-boot-starter-webmvc</artifactId>
4651
</dependency>
47-
4852
<dependency>
4953
<groupId>org.springdoc</groupId>
5054
<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)