diff --git a/pom.xml b/pom.xml
index 11e3422c..78af1157 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,7 +60,6 @@
mysql-connector-j
-
com.h2database
h2
diff --git a/src/main/java/com/softserve/teachua/dto/child/ChildProfile.java b/src/main/java/com/softserve/teachua/dto/child/ChildProfile.java
index 24e4101a..cbb988db 100644
--- a/src/main/java/com/softserve/teachua/dto/child/ChildProfile.java
+++ b/src/main/java/com/softserve/teachua/dto/child/ChildProfile.java
@@ -28,5 +28,5 @@ public class ChildProfile implements Convertible {
@Range(min = 2, max = 18)
private Short age;
@NotNull
- private Gender gender;
+ private String gender;
}
diff --git a/src/main/java/com/softserve/teachua/model/Child.java b/src/main/java/com/softserve/teachua/model/Child.java
index d9a6373d..4fcf81f7 100644
--- a/src/main/java/com/softserve/teachua/model/Child.java
+++ b/src/main/java/com/softserve/teachua/model/Child.java
@@ -47,6 +47,6 @@ public class Child implements Convertible {
////@Type(PostgreSQLEnumType.class)
////@Column(name = "gender", nullable = false, columnDefinition = "gender_enum")
@ManyToOne
- @JoinColumn(name = "value", nullable = false)
+ @JoinColumn(nullable = false)
private Gender gender;
}
diff --git a/src/main/java/com/softserve/teachua/model/Gender.java b/src/main/java/com/softserve/teachua/model/Gender.java
index 07111d5b..4cd5fe8d 100644
--- a/src/main/java/com/softserve/teachua/model/Gender.java
+++ b/src/main/java/com/softserve/teachua/model/Gender.java
@@ -24,7 +24,7 @@ public class Gender {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
- @Column
+ @Column(nullable = false, unique = true)
private String value;
}
diff --git a/src/main/java/com/softserve/teachua/repository/GenderRepository.java b/src/main/java/com/softserve/teachua/repository/GenderRepository.java
new file mode 100644
index 00000000..23011809
--- /dev/null
+++ b/src/main/java/com/softserve/teachua/repository/GenderRepository.java
@@ -0,0 +1,11 @@
+package com.softserve.teachua.repository;
+
+import com.softserve.teachua.model.Gender;
+import org.springframework.data.jpa.repository.JpaRepository;
+import java.util.List;
+
+public interface GenderRepository extends JpaRepository {
+
+ Gender findGenderByValue(String value);
+
+}
diff --git a/src/main/java/com/softserve/teachua/service/impl/ChildServiceImpl.java b/src/main/java/com/softserve/teachua/service/impl/ChildServiceImpl.java
index 670ef2d6..8c9c43c8 100644
--- a/src/main/java/com/softserve/teachua/service/impl/ChildServiceImpl.java
+++ b/src/main/java/com/softserve/teachua/service/impl/ChildServiceImpl.java
@@ -5,8 +5,10 @@
import com.softserve.teachua.dto.child.ChildResponse;
import com.softserve.teachua.exception.NotExistException;
import com.softserve.teachua.model.Child;
+import com.softserve.teachua.model.Gender;
import com.softserve.teachua.model.User;
import com.softserve.teachua.repository.ChildRepository;
+import com.softserve.teachua.repository.GenderRepository;
import com.softserve.teachua.service.ChildService;
import com.softserve.teachua.service.UserService;
import lombok.RequiredArgsConstructor;
@@ -23,17 +25,22 @@ public class ChildServiceImpl implements ChildService {
private final ChildRepository childRepository;
private final DtoConverter dtoConverter;
private final UserService userService;
+ private final GenderRepository genderRepository;
@Override
@Transactional
public ChildResponse create(ChildProfile childProfile) {
User user = userService.getAuthenticatedUserWithChildren();
log.debug("Got user {}", user);
+ Gender gender = genderRepository.findGenderByValue(childProfile.getGender());
+ log.debug("Got gender {}", gender);
+
Child child = dtoConverter.convertToEntity(childProfile, new Child());
log.debug("Dto converted to entity {}", child);
child.setParent(user);
log.debug("Set parent {}", child);
+ child.setGender(gender);
child = childRepository.save(child);