Skip to content

Commit

Permalink
Merge pull request #4 from Yannx79/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Yannx79 authored Dec 1, 2024
2 parents dcf5fe4 + c0b2d3d commit 9a636ed
Show file tree
Hide file tree
Showing 13 changed files with 345 additions and 13 deletions.
44 changes: 44 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Archivos y directorios de sistema
.DS_Store
Thumbs.db

# Archivos de Git
.git
.gitignore

# Archivos de entorno de desarrollo
.env
.env.local
.env.*.local

# Archivos de configuración de IDEs y editores
.vscode/
.idea/
*.sublime-project
*.sublime-workspace

# Archivos de compilación
/dist/
/build/
/tmp/
/out/

# Directorios de logs
*.log

# Archivos de dependencias en Node.js
node_modules/

# Archivos de dependencias en PHP
/vendor/

# Archivos de dependencias en Python
*.pyc
*.pyo
__pycache__/

# Archivos de Docker
docker-compose.override.yml

# Otros archivos no necesarios
*.md
26 changes: 26 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM eclipse-temurin:21.0.3_9-jdk AS Build

WORKDIR /root

COPY ./pom.xml /root
COPY ./.mvn /root/.mvn
COPY ./mvnw /root

RUN chmod +x mvnw

RUN ./mvnw dependency:go-offline

COPY ./src /root/src

RUN ./mvnw clean install -DskipTests

FROM eclipse-temurin:21.0.3_9-jre AS Run

WORKDIR /root
EXPOSE 8080
COPY --from=build /root/target/Learning-Platform-Reactive-API-0.0.1-SNAPSHOT.jar /root/target/Learning-Platform-Reactive-API-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","/root/target/Learning-Platform-Reactive-API-0.0.1-SNAPSHOT.jar"]

LABEL maintainer="https://www.linkedin.com/in/yannick-yasuhiro-funes-chavez/"
LABEL version="0.0.1"
LABEL description="This container runs Spring Boot with a custom configuration."
26 changes: 26 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM eclipse-temurin:21.0.3_9-jdk AS Build

WORKDIR /root

COPY ./pom.xml /root
COPY ./.mvn /root/.mvn
COPY ./mvnw /root

RUN chmod +x mvnw

RUN ./mvnw dependency:go-offline

COPY ./src /root/src

RUN ./mvnw clean install -DskipTests

FROM eclipse-temurin:21.0.3_9-jre AS Run

WORKDIR /root
EXPOSE 8080
COPY --from=build /root/target/Learning-Platform-Reactive-API-0.0.1-SNAPSHOT.jar /root/target/Learning-Platform-Reactive-API-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","/root/target/Learning-Platform-Reactive-API-0.0.1-SNAPSHOT.jar"]

LABEL maintainer="https://www.linkedin.com/in/yannick-yasuhiro-funes-chavez/"
LABEL version="0.0.1"
LABEL description="This container runs Spring Boot with a custom configuration."
2 changes: 2 additions & 0 deletions config/mysql/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mysqld]
lower_case_table_names=1
48 changes: 48 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: "3.9"
services:

spring-api-image:
# image: nk-learning-platform-reactive-api:latest
# image: yan640/nk-learning-platform-reactive-api:lastest
build:
context: .
dockerfile: Dockerfile.prod
container_name: nk-learning-platform-reactive-api
ports:
- "8080:8080"
volumes:
- .:/app
networks:
- spring-network
depends_on:
- mysql
# environment:
# - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/db_e_learning_platform
# - SPRING_DATASOURCE_USERNAME=nk-yannick
# - SPRING_DATASOURCE_PASSWORD=101010
# restart: on-failure

mysql:
image: mysql
container_name: nk-mysql
environment:
MYSQL_ROOT_PASSWORD: 1234
MYSQL_DATABASE: db_e_learning_platform
MYSQL_USER: nk-yannick
MYSQL_PASSWORD: 101010
ports:
- "3307:3306"
networks:
- spring-network
volumes:
- mysql-volume:/var/lib/mysql
- ./config/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
- ./init-db-scripts:/docker-entrypoint-initdb.d
restart: on-failure

networks:
spring-network:
driver: bridge

volumes:
mysql-volume:
48 changes: 48 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: "3.9"
services:

spring-api-image:
# image: nk-learning-platform-reactive-api:latest
image: yan640/nk-learning-platform-reactive-api:lastest
# build:
# context: .
# dockerfile: Dockerfile.prod
container_name: nk-learning-platform-reactive-api
ports:
- "8080:8080"
volumes:
- .:/app
networks:
- spring-network
depends_on:
- mysql
# environment:
# - SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/db_e_learning_platform
# - SPRING_DATASOURCE_USERNAME=nk-yannick
# - SPRING_DATASOURCE_PASSWORD=101010
# restart: on-failure

mysql:
image: mysql
container_name: nk-mysql
environment:
MYSQL_ROOT_PASSWORD: 1234
MYSQL_DATABASE: db_e_learning_platform
MYSQL_USER: nk-yannick
MYSQL_PASSWORD: 101010
ports:
- "3307:3306"
networks:
- spring-network
volumes:
- mysql-volume:/var/lib/mysql
- ./config/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
- ./init-db-scripts:/docker-entrypoint-initdb.d
restart: on-failure

networks:
spring-network:
driver: bridge

volumes:
mysql-volume:
106 changes: 106 additions & 0 deletions init-db-scripts/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
-- Create the database
CREATE DATABASE IF NOT EXISTS db_e_learning_platform;
USE db_e_learning_platform;

-- Create the Users table
CREATE TABLE IF NOT EXISTS users (
UserID INT AUTO_INCREMENT PRIMARY KEY,
FullName VARCHAR(100) NOT NULL,
Email VARCHAR(100) NOT NULL UNIQUE,
Password VARCHAR(255) NOT NULL,
Role ENUM('Student', 'Instructor', 'Admin') NOT NULL,
CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Create the Courses table
CREATE TABLE IF NOT EXISTS courses (
CourseID INT AUTO_INCREMENT PRIMARY KEY,
Title VARCHAR(100) NOT NULL,
Description TEXT,
InstructorID INT NOT NULL, -- References Users.UserID but no foreign key
CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Create the Lessons table
CREATE TABLE IF NOT EXISTS lessons (
LessonID INT AUTO_INCREMENT PRIMARY KEY,
CourseID INT NOT NULL, -- References Courses.CourseID but no foreign key
Title VARCHAR(100) NOT NULL,
Content TEXT,
VideoURL VARCHAR(255),
CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Create the Enrollments table
CREATE TABLE IF NOT EXISTS enrollments (
EnrollmentID INT AUTO_INCREMENT PRIMARY KEY,
UserID INT NOT NULL, -- References Users.UserID but no foreign key
CourseID INT NOT NULL, -- References Courses.CourseID but no foreign key
EnrolledAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Create the Quizzes table
CREATE TABLE IF NOT EXISTS quizzes (
QuizID INT AUTO_INCREMENT PRIMARY KEY,
CourseID INT NOT NULL, -- References Courses.CourseID but no foreign key
Title VARCHAR(100) NOT NULL,
CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Optional: Insert sample data
INSERT INTO users (FullName, Email, Password, Role) VALUES
('Alice Johnson', '[email protected]', 'password123', 'Instructor'),
('Bob Smith', '[email protected]', 'password123', 'Student');

INSERT INTO courses (Title, Description, InstructorID) VALUES
('Introduction to Python', 'Learn the basics of Python programming.', 1);

INSERT INTO lessons (CourseID, Title, Content, VideoURL) VALUES
(1, 'Lesson 1: Variables and Data Types', 'This lesson covers variables and data types.', 'https://example.com/video1'),
(1, 'Lesson 2: Control Structures', 'This lesson covers loops and conditionals.', 'https://example.com/video2');

INSERT INTO enrollments (UserID, CourseID) VALUES
(2, 1);

INSERT INTO quizzes (CourseID, Title) VALUES
(1, 'Quiz 1: Basic Python Concepts');

-- Additional inserts for Users table
INSERT INTO users (FullName, Email, Password, Role) VALUES
('Charlie Brown', '[email protected]', 'password123', 'Student'),
('Diana Prince', '[email protected]', 'password123', 'Instructor'),
('Ethan Hunt', '[email protected]', 'password123', 'Student'),
('Fiona Gallagher', '[email protected]', 'password123', 'Admin'),
('George Wilson', '[email protected]', 'password123', 'Instructor');

-- Additional inserts for Courses table
INSERT INTO courses (Title, Description, InstructorID) VALUES
('Advanced Python', 'A deeper dive into Python programming concepts.', 2),
('Web Development Basics', 'Learn HTML, CSS, and JavaScript to build websites.', 5),
('Data Science with Python', 'Learn data analysis and visualization with Python.', 1),
('Introduction to Machine Learning', 'An introductory course on machine learning principles.', 2),
('JavaScript for Beginners', 'Learn the fundamentals of JavaScript programming.', 5);

-- Additional inserts for Lessons table
INSERT INTO lessons (CourseID, Title, Content, VideoURL) VALUES
(2, 'Lesson 1: Advanced Functions', 'Understand higher-order functions and decorators.', 'https://example.com/video3'),
(3, 'Lesson 1: HTML Basics', 'Learn about HTML structure and tags.', 'https://example.com/video4'),
(4, 'Lesson 1: Data Visualization', 'Introduction to Matplotlib and Seaborn.', 'https://example.com/video5'),
(5, 'Lesson 1: Linear Regression', 'Basics of linear regression in machine learning.', 'https://example.com/video6'),
(6, 'Lesson 1: Variables and Scopes', 'Learn about variable declaration and scoping in JavaScript.', 'https://example.com/video7');

-- Additional inserts for Enrollments table
INSERT INTO enrollments (UserID, CourseID) VALUES
(2, 2),
(3, 3),
(4, 4),
(3, 5),
(2, 6);

-- Additional inserts for Quizzes table
INSERT INTO quizzes (CourseID, Title) VALUES
(2, 'Quiz 2: Python Advanced Topics'),
(3, 'Quiz 1: HTML and CSS Basics'),
(4, 'Quiz 1: Data Visualization Techniques'),
(5, 'Quiz 1: Machine Learning Fundamentals'),
(6, 'Quiz 1: JavaScript Variables and Functions');
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@

@RestController
@RequestMapping("/courses")
@RequiredArgsConstructor
// @RequiredArgsConstructor // manual injection by docker conflicts
public class CourseController {

private final ICourseService service;

@Qualifier("courseModelMapper")
// @Qualifier("courseModelMapper")
private final ModelMapper modelMapper;

public CourseController(ICourseService service, @Qualifier("courseModelMapper") ModelMapper modelMapper) {
this.service = service;
this.modelMapper = modelMapper;
}

@GetMapping
public Flux<CourseDTO> readAll() {
return service.readAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.nk.learningplatformreactiveapi.dto.EnrollmentDTO;
import com.nk.learningplatformreactiveapi.entities.EnrollmentEntity;
import com.nk.learningplatformreactiveapi.services.ICourseService;
import com.nk.learningplatformreactiveapi.services.IEnrollmentService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -15,14 +16,19 @@

@RestController
@RequestMapping("/enrollments")
@RequiredArgsConstructor
// @RequiredArgsConstructor
public class EnrollmentController {

private final IEnrollmentService service;

@Qualifier("enrollmentModelMapper")
// @Qualifier("enrollmentModelMapper")
private final ModelMapper modelMapper;

public EnrollmentController(IEnrollmentService service, @Qualifier("enrollmentModelMapper") ModelMapper modelMapper) {
this.service = service;
this.modelMapper = modelMapper;
}

@GetMapping
public Flux<EnrollmentDTO> readAll() {
return service.readAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@

@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
// @RequiredArgsConstructor
public class LessonController {

private final ILessonService service;

@Qualifier("lessonModelMapper")
// @Qualifier("lessonModelMapper")
private final ModelMapper modelMapper;

public LessonController(ILessonService service, @Qualifier("lessonModelMapper") ModelMapper modelMapper) {
this.service = service;
this.modelMapper = modelMapper;
}

@GetMapping
public Flux<LessonDTO> readAll() {
return service.readAll()
Expand Down
Loading

0 comments on commit 9a636ed

Please sign in to comment.