Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle smell codes, trim text #62

Merged
merged 1 commit into from
Sep 11, 2024
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.backend.elearning.domain.answer;

import jakarta.validation.constraints.NotNull;

public record AnswerVM(
Long id,
@NotNull(message = "answer test must not be null")
String answerText,
String reason,
boolean correct
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/backend/elearning/domain/cart/CartVM.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.backend.elearning.domain.category;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;

public record CategoryPostVM (
Integer id,
@NotBlank(message = "name must not be blank")
@NotEmpty(message = "name must not be empty")
String name,
String description,
boolean isPublish,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class CategoryServiceImpl implements CategoryService{
private final CategoryRepository categoryRepository;


private final String sortBy = "updatedAt";
private static final String sortBy = "updatedAt";
private final CourseRepository courseRepository;
public CategoryServiceImpl(CategoryRepository categoryRepository, CourseRepository courseRepository) {
this.categoryRepository = categoryRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.backend.elearning.domain.coupon;

import jakarta.validation.constraints.NotEmpty;

public record CouponPostVM(

@NotEmpty(message = "coupon code must not be empty")
String code,
int discountPercent,
String startTime,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.backend.elearning.domain.course;
import jakarta.validation.constraints.NotEmpty;

import java.util.Arrays;
import java.util.Objects;

public record CoursePostVM(
Long id,

@NotEmpty(message = "course title must not be empty")
String title,

String headline,

String[] objectives,
Expand All @@ -23,4 +26,51 @@ public record CoursePostVM(

) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CoursePostVM that = (CoursePostVM) o;
return free == that.free &&
Objects.equals(id, that.id) &&
Objects.equals(title, that.title) &&
Objects.equals(headline, that.headline) &&
Arrays.equals(objectives, that.objectives) &&
Arrays.equals(requirements, that.requirements) &&
Arrays.equals(targetAudiences, that.targetAudiences) &&
Objects.equals(description, that.description) &&
Objects.equals(level, that.level) &&
Objects.equals(price, that.price) &&
Objects.equals(image, that.image) &&
Objects.equals(categoryId, that.categoryId) &&
Objects.equals(topicId, that.topicId);
}

@Override
public int hashCode() {
int result = Objects.hash(id, title, headline, description, level, price, image, free, categoryId, topicId);
result = 31 * result + Arrays.hashCode(objectives);
result = 31 * result + Arrays.hashCode(requirements);
result = 31 * result + Arrays.hashCode(targetAudiences);
return result;
}

@Override
public String toString() {
return "CoursePostVM{" +
"id=" + id +
", title='" + title + '\'' +
", headline='" + headline + '\'' +
", objectives=" + Arrays.toString(objectives) +
", requirements=" + Arrays.toString(requirements) +
", targetAudiences=" + Arrays.toString(targetAudiences) +
", description='" + description + '\'' +
", level='" + level + '\'' +
", price=" + price +
", image='" + image + '\'' +
", free=" + free +
", categoryId=" + categoryId +
", topicId=" + topicId +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public class CourseServiceImpl implements CourseService{
private final CartRepository cartRepository;
private final UserService userService;
private final UserRepository userRepository;
private final static String LECTURE_TYPE = "lecture";
private final static String QUIZ_TYPE = "quiz";
private final String sortBy = "updatedAt";
private static final String LECTURE_TYPE = "lecture";
private static final String QUIZ_TYPE = "quiz";
private static final String sortBy = "updatedAt";
public CourseServiceImpl(CourseRepository courseRepository, CategoryRepository categoryRepository, TopicRepository topicRepository, SectionService sectionService, QuizRepository quizRepository, LectureRepository lectureRepository, ReviewService reviewService, LearningLectureRepository learningLectureRepository, LearningQuizRepository learningQuizRepository, LearningCourseRepository learningCourseRepository, OrderDetailRepository orderDetailRepository, CartRepository cartRepository, UserService userService, UserRepository userRepository) {
this.courseRepository = courseRepository;
this.categoryRepository = categoryRepository;
Expand Down Expand Up @@ -143,9 +143,6 @@ public CourseVM create(CoursePostVM coursePostVM) {

@Override
public CourseVM update(CoursePostVM coursePutVM, Long userId, Long courseId) {
// if (oldCourse.getUser().getId() != userId) {
// throw new BadRequestException("You don't have permission to edit this course");
// }
Course oldCourse = courseRepository.findByIdReturnSections(courseId).orElseThrow(() -> new NotFoundException(
Constants.ERROR_CODE.COURSE_NOT_FOUND, courseId
));
Expand Down Expand Up @@ -221,10 +218,8 @@ public CourseVM getCourseById(Long id) {

boolean learning = true;
String email = SecurityContextHolder.getContext().getAuthentication().getName();
if (email != null) {
if (!learningCourseRepository.findByStudentAndCourse(email, courseId).isPresent()) {
learning = false;
}
if (email != null && !learningCourseRepository.findByStudentAndCourse(email, courseId).isPresent()) {
learning = false;
}
return CourseVM.fromModel(course, sections,ratingCount, roundedAverageRating, totalCurriculumCourse.get(),formattedHours, userProfileVM, learning);
}
Expand Down Expand Up @@ -352,7 +347,7 @@ public PageableData<CourseListGetVM> getCoursesByMultiQuery(int pageNum,
return new PageableData(
pageNum,
pageSize,
(int) courses.size(),
courses.size(),
courses.size()/ pageSize,
courseListGetVMS
);
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/com/backend/elearning/domain/course/CourseVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.backend.elearning.utils.DateTimeUtils;

import java.util.List;
import java.util.Arrays;
import java.util.Objects;

public record CourseVM(
Long id,
Expand Down Expand Up @@ -35,6 +37,81 @@ public record CourseVM(
boolean learning,
String breadcrumb
) {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CourseVM that = (CourseVM) o;
return free == that.free &&
isPublish == that.isPublish &&
ratingCount == that.ratingCount &&
Double.compare(that.averageRating, averageRating) == 0 &&
totalLectureCourse == that.totalLectureCourse &&
learning == that.learning &&
Objects.equals(id, that.id) &&
Objects.equals(title, that.title) &&
Objects.equals(headline, that.headline) &&
Objects.equals(slug, that.slug) &&
Arrays.equals(objectives, that.objectives) &&
Arrays.equals(requirements, that.requirements) &&
Arrays.equals(targetAudiences, that.targetAudiences) &&
Objects.equals(description, that.description) &&
Objects.equals(level, that.level) &&
Objects.equals(image, that.image) &&
Objects.equals(createdAt, that.createdAt) &&
Objects.equals(updatedAt, that.updatedAt) &&
Objects.equals(price, that.price) &&
Objects.equals(categoryId, that.categoryId) &&
Objects.equals(topicId, that.topicId) &&
Objects.equals(totalDurationCourse, that.totalDurationCourse) &&
Objects.equals(createdBy, that.createdBy) &&
Objects.equals(sections, that.sections) &&
Objects.equals(user, that.user) &&
Objects.equals(breadcrumb, that.breadcrumb);
}

@Override
public int hashCode() {
int result = Objects.hash(id, title, headline, slug, description, level, image, createdAt, updatedAt, free,
price, isPublish, categoryId, topicId, ratingCount, averageRating, totalLectureCourse,
totalDurationCourse, createdBy, sections, user, learning, breadcrumb);
result = 31 * result + Arrays.hashCode(objectives);
result = 31 * result + Arrays.hashCode(requirements);
result = 31 * result + Arrays.hashCode(targetAudiences);
return result;
}

@Override
public String toString() {
return "CourseVM{" +
"id=" + id +
", title='" + title + '\'' +
", headline='" + headline + '\'' +
", slug='" + slug + '\'' +
", objectives=" + Arrays.toString(objectives) +
", requirements=" + Arrays.toString(requirements) +
", targetAudiences=" + Arrays.toString(targetAudiences) +
", description='" + description + '\'' +
", level='" + level + '\'' +
", image='" + image + '\'' +
", createdAt='" + createdAt + '\'' +
", updatedAt='" + updatedAt + '\'' +
", free=" + free +
", price=" + price +
", isPublish=" + isPublish +
", categoryId=" + categoryId +
", topicId=" + topicId +
", ratingCount=" + ratingCount +
", averageRating=" + averageRating +
", totalLectureCourse=" + totalLectureCourse +
", totalDurationCourse='" + totalDurationCourse + '\'' +
", createdBy='" + createdBy + '\'' +
", sections=" + sections +
", user=" + user +
", learning=" + learning +
", breadcrumb='" + breadcrumb + '\'' +
'}';
}
public static CourseVM fromModel (Course course, List<SectionVM> sections, int ratingCount,
double averageRating,
int totalLectureCourse,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.backend.elearning.domain.media;

import com.backend.elearning.exception.BadRequestException;
import com.cloudinary.Cloudinary;
import com.cloudinary.utils.ObjectUtils;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -47,7 +48,7 @@ public Media saveOrUpdateFile(MultipartFile multipartFile, String uuid, String t
}
return media;
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
throw new BadRequestException(e.getMessage());
}
}

Expand All @@ -62,7 +63,7 @@ public void deleteFile(String uuid) {
try {
cloudinary.uploader().destroy(uuid, ObjectUtils.emptyMap());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
throw new BadRequestException(e.getMessage());
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public List<CourseListGetVM> getTopCourseBestSeller(int limit) {
Page<Long> bestSellerCourses = orderDetailRepository.getBestSellerCourses(pageable);
List<Long> courseIds = bestSellerCourses.getContent();
// convert id to list of CourseListGetVM
List<CourseListGetVM> courseListGetVMS = courseIds.stream().map(id -> {
return courseService.getCourseListGetVMById(id);
}).toList();
List<CourseListGetVM> courseListGetVMS = courseIds.stream().map(id -> courseService.getCourseListGetVMById(id)).toList();
return courseListGetVMS;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.backend.elearning.domain.question;

import com.backend.elearning.domain.answer.AnswerVM;
import jakarta.validation.constraints.NotNull;

import java.util.List;

public record QuestionPostVM(
Long id,
@NotNull(message = "question must not be null")
String title,
Long quizId,
List<AnswerVM> answers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ public interface QuizService {
QuizVM create(QuizPostVM quizPostVM);
QuizVM update(QuizPostVM quizPutVM, Long quizId);
void delete(Long quizId);

// Todo: Delete quiz
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.backend.elearning.domain.review;

import jakarta.validation.constraints.NotNull;

public record ReviewPostVM(
Long courseId,
String content,
int ratingStar
@NotNull(message = "rating star must not be null")
Integer ratingStar
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public class ReviewServiceImpl implements ReviewService {

private final CourseRepository courseRepository;

private final static int fiveStar = 5;
private final static int fourStar = 4;
private final static int threeStar = 3;
private final static int twoStar = 2;
private final static int oneStar = 1;
private static final int fiveStar = 5;
private static final int fourStar = 4;
private static final int threeStar = 3;
private static final int twoStar = 2;
private static final int oneStar = 1;


private final static String sortField = "createdAt";
private static final String sortField = "createdAt";
public ReviewServiceImpl(ReviewRepository reviewRepository, StudentRepository studentRepository, CourseRepository courseRepository) {
this.reviewRepository = reviewRepository;
this.studentRepository = studentRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.backend.elearning.domain.section;

import jakarta.validation.constraints.NotEmpty;

public record SectionPostVM(
Long id,
@NotEmpty
String title,
float number,
String objective,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.backend.elearning.domain.student;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;

public record StudentPutVM(
Long id,
@Email(message = "email invalid format")
String email,
@NotBlank(message = "first name must not be blank")
String firstName,
@NotBlank(message = "last name must not be blank")
String lastName,
String password,
String gender,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.backend.elearning.domain.topic;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;

import java.util.List;

public record TopicPostVM(Integer id,
@NotBlank(message = "name must not be blank")
@NotEmpty(message = "name must not be empty")
String name,
String description,
boolean isPublish,
Expand Down
Loading
Loading