Makes some small refactorings and adds postman collection

This commit is contained in:
szsa
2022-04-23 12:48:07 +02:00
parent cfdfcfb8d6
commit ea81148464
4 changed files with 174 additions and 12 deletions

165
postman_collection.json Normal file
View File

@@ -0,0 +1,165 @@
{
"info": {
"_postman_id": "809992e0-63cb-4d98-ae6b-30e259a35348",
"name": "Reactive Timesheet App",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Get user by id",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"username\" : \"John Test\",\r\n \"password\" : \"223eded3\",\r\n \"passwordConfirmation\" : \"223eded3\",\r\n \"role\" : \"LEAD\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8080/users/id/62378d381507b40858b58695",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"users",
"id",
"62378d381507b40858b58695"
]
}
},
"response": []
},
{
"name": "Get user by name",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"username\" : \"John Test\",\r\n \"password\" : \"223eded3\",\r\n \"passwordConfirmation\" : \"223eded3\",\r\n \"role\" : \"LEAD\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8080/users/id/62378d381507b40858b58695",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"users",
"id",
"62378d381507b40858b58695"
]
}
},
"response": []
},
{
"name": "Create user",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"username\" : \"John Test\",\r\n \"password\" : \"223eded3\",\r\n \"passwordConfirmation\" : \"223eded3\",\r\n \"role\" : \"LEAD\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8080/users/",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"users",
""
]
}
},
"response": []
},
{
"name": "Create team",
"request": {
"method": "GET",
"header": []
},
"response": []
},
{
"name": "delete team",
"request": {
"method": "GET",
"header": []
},
"response": []
},
{
"name": "delete user",
"request": {
"method": "GET",
"header": []
},
"response": []
},
{
"name": "creating of the new time entry",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"date\" : \"1999-12-12\",\r\n \"timeFrom\" : \" \",\r\n \"timeTo\" : \" \",\r\n \"user\" : {\r\n \"username\": \"Arnold Test\",\r\n \"password\": \"223eded3\",\r\n \"role\": \"DEVELOPER\"\r\n },\r\n \"category\": \"DEVELOPMENT\" \r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8080/team-entries/",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"team-entries",
""
]
}
},
"response": []
},
{
"name": "get team by id",
"request": {
"method": "GET",
"header": []
},
"response": []
}
]
}

View File

@@ -46,12 +46,10 @@ public class TeamService {
private Mono<GetTeamDto> createTeamWithMembers(CreateTeamDto createTeamDto) {
var teamToInsert = createTeamDto.toTeam();
// at first team is inserted into db and all its member are updated with the new teamId
return teamRepository
.save(teamToInsert)
.save(createTeamDto.toTeam())
.flatMap(insertedTeam -> {
var membersToInsert = createTeamDto
.members()
@@ -64,12 +62,9 @@ public class TeamService {
return userRepository
.saveAll(membersToInsert)
.collectList()
.flatMap(insertedUsers -> {
var teamToInsertWithMembers = insertedTeam.withMembers(insertedUsers);
return teamRepository
.save(teamToInsertWithMembers)
.map(Team::toGetTeamDto);
});
.flatMap(insertedUsers -> teamRepository
.save(insertedTeam.withMembers(insertedUsers))
.map(Team::toGetTeamDto));
});
}
@@ -94,5 +89,4 @@ public class TeamService {
})
.switchIfEmpty(Mono.error(new TeamServiceException("cannot find team to delete")));
}
}

View File

@@ -33,7 +33,7 @@ public class TimeEntryService {
return userRepository
.findById(timeEntryToCheck.user().id())
.hasElement()
.flatMap(isUserPresent -> Boolean.TRUE.equals(isUserPresent)
.flatMap(isUserPresent -> isUserPresent
?
findCollisions(timeEntryToCheck)
:
@@ -41,6 +41,9 @@ public class TimeEntryService {
}
private Mono<CreateTimeEntryDto> findCollisions(CreateTimeEntryDto timeEntryToCheck) {
// TODO proper implementation of collision check (doesn't work at the moment). Create isAvailable() method in TimeEntry domain class
return timeEntryRepository.findAllByUser(timeEntryToCheck.user().toUser())
.filter(entry -> !TimeEntryUtils.toTimeFrom.apply(entry).isAfter(timeEntryToCheck.timeTo())
&& !TimeEntryUtils.toTimeTo.apply(entry).isBefore(timeEntryToCheck.timeFrom()))

View File

@@ -38,7 +38,7 @@ public class UserService {
.flatMap(createUserDto -> userRepository
.findByUsername(createUserDto.username())
.hasElement()
.flatMap(isUserPresent -> Boolean.TRUE.equals(isUserPresent)
.flatMap(isUserPresent -> isUserPresent
?
Mono.error(new UserServiceException("user with username " + createUserDto.username() + " already exists"))
: