Skip to content

Commit

Permalink
Change Gender Enum to model
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavGarasym committed Oct 26, 2023
1 parent 0e4c608 commit 3c535a3
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 12 deletions.
2 changes: 1 addition & 1 deletion init.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CREATE TYPE gender_enum AS ENUM ('MALE', 'FEMALE');
--CREATE TYPE gender_enum AS ENUM ('MALE', 'FEMALE');
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<artifactId>postgresql</artifactId>
</dependency>

<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>


<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/softserve/teachua/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
Expand All @@ -12,7 +14,12 @@
@EnableScheduling
@EnableJpaAuditing
@EnableAsync
public class Application {
public class Application extends SpringBootServletInitializer {
//@Override
//protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
// return application.sources(Application.class);
//}

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@Getter
@RequiredArgsConstructor
public enum Gender {
public enum Gender1 {
MALE("MALE"),
FEMALE("FEMALE");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
description = "API for major TeachUA endpoints. For DataTransfer and Logs endpoints, please contact dev team.",
version = "v0.1"), servers = {
@Server(description = "localhost", url = "http://localhost:8080/dev"),
@Server(description = "dev server", url = "http://speak-ukrainian.eastus2.cloudapp.azure.com/")})
@Server(description = "dev server", url = "http://speak-ukrainian.eastus2.cloudapp.azure.com/dev/")})
@SecurityScheme(name = "api", scheme = "bearer", bearerFormat = "JWT",
type = SecuritySchemeType.HTTP, in = SecuritySchemeIn.HEADER)
public interface Api {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.softserve.teachua.dto.child;

import com.softserve.teachua.constants.Gender;
//import com.softserve.teachua.constants.Gender;
import com.softserve.teachua.dto.marker.Convertible;
import com.softserve.teachua.model.Gender;
import com.softserve.teachua.utils.validations.CheckRussian;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -14,6 +16,7 @@
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class ChildProfile implements Convertible {
@NotBlank
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.softserve.teachua.dto.child;

import com.softserve.teachua.constants.Gender;
//import com.softserve.teachua.constants.Gender;
import com.softserve.teachua.dto.marker.Convertible;
import com.softserve.teachua.dto.user.ParentResponse;
import com.softserve.teachua.model.Gender;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/softserve/teachua/model/Child.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.softserve.teachua.model;

import com.softserve.teachua.constants.Gender;
////import com.softserve.teachua.constants.Gender;
import com.softserve.teachua.dto.marker.Convertible;
import io.hypersistence.utils.hibernate.type.basic.PostgreSQLEnumType;
////import io.hypersistence.utils.hibernate.type.basic.PostgreSQLEnumType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand Down Expand Up @@ -43,8 +43,10 @@ public class Child implements Convertible {
@Column(name = "age", nullable = false)
private Short age;

@Enumerated(EnumType.STRING)
@Type(PostgreSQLEnumType.class)
@Column(name = "gender", nullable = false, columnDefinition = "gender_enum")
////@Enumerated(EnumType.STRING)
////@Type(PostgreSQLEnumType.class)
////@Column(name = "gender", nullable = false, columnDefinition = "gender_enum")
@ManyToOne
@JoinColumn(name = "value", nullable = false)
private Gender gender;
}
30 changes: 30 additions & 0 deletions src/main/java/com/softserve/teachua/model/Gender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.softserve.teachua.model;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;

@AllArgsConstructor
@NoArgsConstructor
@Data
@With
@Builder
@Entity
@Table(name = "gender")
public class Gender {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column
private String value;

}
2 changes: 1 addition & 1 deletion src/main/java/com/softserve/teachua/model/test/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@Builder
@EqualsAndHashCode(exclude = {"id"})
@Entity
@Table(name = "groups")
@Table(name = "group_cohort")
public class Group {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
Expand Down
81 changes: 81 additions & 0 deletions src/main/resources/application-azure.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
spring.output.ansi.enabled=ALWAYS

# Port
server.port=80
server.error.include-message=always
server.servlet.context-path=${PUBLIC_URL}
server.tomcat.relaxed-query-chars=|,{,},[,]
server.forward-headers-strategy=framework

spring.web.resources.static-locations=classpath:${STATIC_FOLDER}
application.upload.path=${UPLOAD_PATH}
baseURL=${BASE_URL}

# Thymeleaf
spring.thymeleaf.cache=false

# JPA, Hibernate
spring.jpa.hibernate.ddl-auto=update
#spring.jpa.show-sql=true
#spring.jpa.properties.hibernate.format_sql=true
#spring.sql.init.mode=always

# Postgres
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=${DEV2_DATASOURCE_URL}
spring.datasource.username=${DEV2_DATASOURCE_USER}
spring.datasource.password=${DEV2_DATASOURCE_PASSWORD}

#spring.datasource.driver-class-name=org.postgresql.Driver
#spring.datasource.driverClassName=org.h2.Driver
#spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
#spring.datasource.url=jdbc:h2:file:./test.db;DB_CLOSE_DELAY=-1
#spring.datasource.username=sa
#spring.datasource.password=sa

# Flyway
# true to initialize the schema history table.
spring.flyway.baseline-on-migrate=true
#spring.flyway.enabled=true
spring.flyway.enabled=false

# Logging
logs.path=${URL_LOGS}

# JWT
application.jwt.accessSecretKey=${JWT_ACCESS_SECRET_KEY}
application.jwt.refreshSecretKey=${JWT_REFRESH_SECRET_KEY}
application.jwt.accessExpirationTimeInMinutes=30
application.jwt.refreshExpirationTimeInDays=3

# OAuth
authorizedRedirectUris= ${BASE_URL}/oauth2/redirect,myandroidapp://oauth2/redirect,myiosapp://oauth2/redirect

# Spring @mail
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=${USER_EMAIL}
spring.mail.password=${SEND_PASSWORD}
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.transport.protocol=smtp
spring.mail.properties.mail.smtp.starttls.enable=true

# Photo uploading
spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1

# OpenAPI SwaggerUI + Tomcat skipping jar Manifest scan
springdoc.swagger-ui.operationsSorter=method
springdoc.swagger-ui.tagsSorter=alpha
server.tomcat.additional-tld-skip-patterns=*.jar
springdoc.swagger-ui.disable-swagger-default-url=true

# Actuator exposure settings
management.endpoints.web.exposure.exclude=*

# Search statistics settings
statistics.toCache=true
statistics.max-time=2023-10-03 00:00:00
statistics.max-number=1000


3 changes: 3 additions & 0 deletions src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ spring.jpa.hibernate.ddl-auto=update

# Postgres
spring.datasource.driver-class-name=org.postgresql.Driver
##spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=${DEV2_DATASOURCE_URL}
spring.datasource.username=${DEV2_DATASOURCE_USER}
spring.datasource.password=${DEV2_DATASOURCE_PASSWORD}
Expand All @@ -32,6 +33,8 @@ spring.datasource.password=${DEV2_DATASOURCE_PASSWORD}
#spring.datasource.url=jdbc:h2:file:./test.db;DB_CLOSE_DELAY=-1
#spring.datasource.username=sa
#spring.datasource.password=sa
##spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
##spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

# Flyway
# true to initialize the schema history table.
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
insert into gender(value)
values ('MALE'),
('FEMALE');

insert into roles(name)
values ('ROLE_ADMIN'),
('ROLE_USER'),
Expand Down

0 comments on commit 3c535a3

Please sign in to comment.