Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JWT_SECRET=sFAt7RSBoe6nJ7cSuMFiRtqSLNLkWOfmrSzH0iKFLKvFHSG2VJ6Xn/uzFDDFqENR
49 changes: 17 additions & 32 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,28 @@ services:
networks:
- postgres
restart: unless-stopped
pgadmin:
container_name: elearning-pgui
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
PGADMIN_CONFIG_SERVER_MODE: 'False'
volumes:
- pgadmin:/var/lib/pgadmin
ports:
- "5050:80"
networks:
- postgres
restart: unless-stopped
api:
image: thuanvn2002/elearning-be:latest
ports:
- "8082:8082"
environment:
- SPRING_PROFILES_ACTIVE=prod
networks:
- postgres
depends_on:
- postgres
ui:
image: thuanvn2002/elearning-fe:latest
ports:
- "80:80"
networks:
- postgres
restart: unless-stopped
# api:
# image: thuanvn2002/elearning-be:latest
# ports:
# - "8082:8082"
# environment:
# - SPRING_PROFILES_ACTIVE=prod
# networks:
# - postgres
# depends_on:
# - postgres
# ui:
# image: thuanvn2002/elearning-fe:latest
# ports:
# - "80:80"
# networks:
# - postgres
# restart: unless-stopped
networks:
postgres:
driver: bridge

volumes:
db_data:
pgadmin:


6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
<dependency>
<groupId>me.paulschwarz</groupId>
<artifactId>spring-dotenv</artifactId>
<version>3.0.0</version>
</dependency>

</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
package com.backend.elearning.configuration;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.AuditorAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Optional;

@Configuration
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
@EnableJpaAuditing
public class DatabaseAutoConfig {
@Bean
public AuditorAware<String> auditorAware() {
return () -> {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth == null) return Optional.of("");
return Optional.of(auth.getName());
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
@Getter
@Setter
@Builder
@EntityListeners(value = CustomAuditingEntityListener.class)
public class Answer extends AbstractAuditEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ public AuthenticationVm register(RegistrationPostVm request) {
.build();
student.setVerificationCode(generateVerificationCode());
student.setVerificationCodeExpiresAt(LocalDateTime.now().plusMinutes(15));
student.setCreatedAt(LocalDateTime.now());
student.setUpdatedAt(LocalDateTime.now());
studentRepository.saveAndFlush(student);
sendVerificationEmail(student);
String token = jwtUtil.issueToken(student.getEmail(), ERole.ROLE_STUDENT.name());
Expand Down Expand Up @@ -253,7 +251,6 @@ public void updatePassword(AuthenticationPostVm request) {
.findByEmail(email)
.orElseThrow(() -> new NotFoundException(Constants.ERROR_CODE.USER_NOT_FOUND, request.email()));
student.setPassword(passwordEncoder.encode(request.password()));
student.setUpdatedAt(LocalDateTime.now());
studentRepository.save(student);
} catch (Exception e) {
throw new BadRequestException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
@Getter
@Setter
@Builder
@EntityListeners(value = CustomAuditingEntityListener.class)
public class Category extends AbstractAuditEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public CategoryVM create(CategoryPostVM categoryPostVM) {
.description(categoryPostVM.description())
.publish(categoryPostVM.isPublish())
.build();
category.setCreatedAt(LocalDateTime.now());
category.setUpdatedAt(LocalDateTime.now());
if (categoryPostVM.parentId() != null) {
Category parent = categoryRepository.findById(categoryPostVM.parentId()).orElseThrow(() ->
new NotFoundException(Constants.ERROR_CODE.CATEGORY_NOT_FOUND, categoryPostVM.parentId()));
Expand Down Expand Up @@ -103,7 +101,6 @@ public void update(CategoryPostVM categoryPutVM, Integer categoryId) {
category.setName(categoryPutVM.name());
category.setDescription(categoryPutVM.description());
category.setPublish(categoryPutVM.isPublish());
category.setUpdatedAt(LocalDateTime.now());
if (categoryPutVM.parentId() == null) {
category.setParent(null);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ private List<Event> getByClassroom(Classroom classroom) {
referenceGetVM.setId(reference.getId());
referenceGetVM.setType(EventType.reference);
referenceGetVM.setDescription(reference.getDescription());
referenceGetVM.setCreatedAt(reference.getCreatedAt());
List<ReferenceFileVM> files = referenceFileService.getByReferenceId(reference.getId());
referenceGetVM.setFiles(files);
events.add(referenceGetVM);
Expand All @@ -122,7 +121,6 @@ private List<Event> getByClassroom(Classroom classroom) {
exerciseGetVM.setDescription(exercise.getDescription());
exerciseGetVM.setDeadline(convertLocalDateTimeToString(exercise.getSubmission_deadline()));
exerciseGetVM.setType(EventType.exercise);
exerciseGetVM.setCreatedAt(exercise.getCreatedAt());
List<ExerciseFileVM> files = exerciseFileService.getByExerciseId(exercise.getId());
exerciseGetVM.setFiles(files);
events.add(exerciseGetVM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

@MappedSuperclass
@Getter
@Setter
@EntityListeners(CustomAuditingEntityListener.class)
@EntityListeners(AuditingEntityListener.class)
public class AbstractAuditEntity {

@CreatedDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ public CustomAuditingEntityListener(ObjectFactory<AuditingHandler> handler) {
public CustomAuditingEntityListener() {

}


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.backend.elearning.domain.coupon;
import com.backend.elearning.domain.common.AbstractAuditEntity;
import com.backend.elearning.domain.order.Order;
import jakarta.persistence.*;
import lombok.*;
Expand All @@ -14,7 +15,7 @@
@Setter
@Getter
@Builder
public class Coupon {
public class Coupon extends AbstractAuditEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
@Getter
@Setter
@Builder
@EntityListeners(value = CustomAuditingEntityListener.class)
public class Course extends AbstractAuditEntity {

@Id
Expand All @@ -44,7 +43,7 @@ public class Course extends AbstractAuditEntity {

private String[] targetAudiences;

@Column(length = 1000)
@Column(columnDefinition = "TEXT")
private String description;

private String imageId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ public CourseVM create(CoursePostVM coursePostVM) {
if (!course.isFree()) {
course.setPrice(coursePostVM.price());
}
course.setCreatedAt(LocalDateTime.now());
course.setUpdatedAt(LocalDateTime.now());
return CourseVM.fromModel(courseRepository.save(course), new ArrayList<>(),0, 0.0,0,"", null, false, 0L);
}

Expand Down Expand Up @@ -178,7 +176,6 @@ public CourseVM update(CoursePostVM coursePutVM, Long userId, Long courseId) {
oldCourse.setTargetAudiences(coursePutVM.targetAudiences());
oldCourse.setFree(coursePutVM.free());
oldCourse.setStatus(CourseStatus.UNPUBLISHED);
oldCourse.setUpdatedAt(LocalDateTime.now());
if (!coursePutVM.free()) {
oldCourse.setPrice(coursePutVM.price());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public ExerciseVM create(ExercisePostVM exercisePostVM) {
.classroom(classroom)
.build();

exercise.setCreatedAt(LocalDateTime.now());
exercise.setUpdatedAt(LocalDateTime.now());
Exercise savedExercise = exerciseRepository.saveAndFlush(exercise);
return ExerciseVM.fromModel(savedExercise);
}
Expand All @@ -50,7 +48,6 @@ public ExerciseVM update(ExercisePostVM exercisePostVM, Long referenceId) {
Exercise exercise = exerciseRepository.findById(referenceId).orElseThrow();
exercise.setTitle(exercisePostVM.title());
exercise.setDescription(exercisePostVM.description());
exercise.setUpdatedAt(LocalDateTime.now());
exercise.setSubmission_deadline(deadline);
Exercise savedExercise = exerciseRepository.saveAndFlush(exercise);
return ExerciseVM.fromModel(savedExercise);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.backend.elearning.domain.exerciseFile;

import com.backend.elearning.domain.common.AbstractAuditEntity;
import com.backend.elearning.domain.excercise.Exercise;
import com.backend.elearning.domain.reference.Reference;
import com.backend.elearning.domain.student.Student;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@Setter
@Builder
@ToString
@EntityListeners(value = CustomAuditingEntityListener.class)
public class Lecture extends AbstractAuditEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public LectureVm create(LecturePostVM lecturePostVM) {
.number(lecturePostVM.number())
.section(section)
.build();
lecture.setCreatedAt(LocalDateTime.now());
lecture.setUpdatedAt(LocalDateTime.now());
Lecture savedLecture = lectureRepository.save(lecture);
LectureVm lectureVm = new LectureVm(savedLecture);
return lectureVm;
Expand All @@ -58,7 +56,6 @@ public LectureVm update(LecturePostVM lecturePutVM, Long lectureId) {
lecture.setLectureDetails(lecturePutVM.lectureDetails());
lecture.setDuration(lecturePutVM.duration());
Lecture savedLecture = lectureRepository.saveAndFlush(lecture);
lecture.setUpdatedAt(LocalDateTime.now());
LectureVm lectureVm = new LectureVm(savedLecture);
return lectureVm;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public MeetingVM create(MeetingPostVM meetingPostVM) {
.endTime(endTime)
.classroom(classroom)
.build();
meeting.setCreatedAt(LocalDateTime.now());
meeting.setUpdatedAt(LocalDateTime.now());
Meeting savedMeeting = meetingRepository.saveAndFlush(meeting);
return MeetingVM.fromModel(savedMeeting);
}
Expand All @@ -44,7 +42,6 @@ public MeetingVM update(MeetingPostVM meetingPostVM, Long meetingId) {
meeting.setCode(meetingPostVM.code());
meeting.setStartTime(startTime);
meeting.setEndTime(endTime);
meeting.setUpdatedAt(LocalDateTime.now());
Meeting updatedMeeting = meetingRepository.saveAndFlush(meeting);
return MeetingVM.fromModel(updatedMeeting);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/backend/elearning/domain/note/Note.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.backend.elearning.domain.note;

import com.backend.elearning.domain.common.AbstractAuditEntity;
import com.backend.elearning.domain.lecture.Lecture;
import com.backend.elearning.domain.student.Student;
import jakarta.persistence.*;
Expand All @@ -12,7 +13,7 @@
@Setter
@Getter
@Builder
public class Note {
public class Note extends AbstractAuditEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/backend/elearning/domain/order/Order.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.backend.elearning.domain.order;

import com.backend.elearning.domain.common.AbstractAuditEntity;
import com.backend.elearning.domain.coupon.Coupon;
import com.backend.elearning.domain.student.Student;
import jakarta.persistence.*;
Expand All @@ -16,7 +17,7 @@
@Setter
@Getter
@Builder
public class Order {
public class Order extends AbstractAuditEntity {


@Id
Expand All @@ -31,7 +32,6 @@ public class Order {
@JoinColumn(name = "coupon_id")
private Coupon coupon;

private LocalDateTime createdAt;

@Enumerated(EnumType.STRING)
private EOrderStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public Long createOrder(OrderPostDto orderPostDto) {
Order order = Order.builder()
.status(EOrderStatus.PENDING)
.student(student)
.createdAt(LocalDateTime.now())
.build();
if (coupon != null) {
order.setCoupon(coupon);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.backend.elearning.domain.promotion;

import com.backend.elearning.domain.common.AbstractAuditEntity;
import com.backend.elearning.domain.course.Course;
import jakarta.persistence.*;
import lombok.*;
Expand All @@ -15,7 +16,7 @@
@Getter
@Setter
@Builder
public class Promotion {
public class Promotion extends AbstractAuditEntity {


@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public QuestionLectureVM create(QuestionLecturePostVM questionLecturePostVM) {
.lecture(lecture)
.student(student)
.build();
questionLecture.setCreatedAt(LocalDateTime.now());
questionLecture.setUpdatedAt(LocalDateTime.now());

QuestionLecture savedQuestionLecture = questionLectureRepo.saveAndFlush(questionLecture);
return QuestionLectureVM.fromModel(savedQuestionLecture);
Expand All @@ -64,7 +62,6 @@ public QuestionLectureVM update(QuestionLecturePostVM questionLecturePostVM, Lon
QuestionLecture questionLecture = questionLectureRepo.findById(questionLectureId).orElseThrow();
questionLecture.setTitle(questionLecturePostVM.title());
questionLecture.setDescription(questionLecturePostVM.description());
questionLecture.setUpdatedAt(LocalDateTime.now());
QuestionLecture savedQuestionLecture = questionLectureRepo.saveAndFlush(questionLecture);

return QuestionLectureVM.fromModel(savedQuestionLecture);
Expand Down
Loading
Loading