Skip to content

Commit

Permalink
MySQL added. Gender updated
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavGarasym committed Oct 26, 2023
1 parent 6d7212d commit f2866b1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<artifactId>mysql-connector-j</artifactId>
</dependency>


<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public class ChildProfile implements Convertible {
@Range(min = 2, max = 18)
private Short age;
@NotNull
private Gender gender;
private String gender;
}
2 changes: 1 addition & 1 deletion src/main/java/com/softserve/teachua/model/Child.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/main/java/com/softserve/teachua/model/Gender.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Gender {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column
@Column(nullable = false, unique = true)
private String value;

}
Original file line number Diff line number Diff line change
@@ -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, Long> {

Gender findGenderByValue(String value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit f2866b1

Please sign in to comment.