Skip to content

Commit

Permalink
Merge pull request #136 from UnivApp/feature/refactor20
Browse files Browse the repository at this point in the history
Feature/refactor20
  • Loading branch information
nyeroni authored Oct 9, 2024
2 parents 4363fc5 + 622e433 commit 0eb3f95
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
import java.util.List;

public interface NewsRepository extends JpaRepository<News, Long> {
List<News> findAllByOrderByPublishedDateDesc();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public NewsResponse getNewsByNewsId(Long newsId) {

@Transactional(readOnly = true)
public List<NewsResponse> getNews() {
List<News> newsList = newsRepository.findAll();
List<News> newsList = newsRepository.findAllByOrderByPublishedDateDesc();

return newsList.stream()
.map(this::convertToDto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Ranking {
private int rankNum;

@Column(name = "ranking_year")
private int rankingYear;
private String rankingYear;

private String universityName;
private String logo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class RankingResponse {
private String displayName;
private String fullName;
private String description;
private int year;
private String year;
private String category;
List<UniversityRankingResponse> universityRankingResponses;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package yerong.wedle.department.domain;

public enum DepartmentType {
NATURAL_SCIENCES("자연과학계열"),
HUMANITIES("인문사회계열"),
ARTS("예체능계열"),
NATURAL_SCIENCES("자연과학계열"),
ENGINEERING("공학계열"),
ARTS("예체능계열"),
MEDICAL_SCIENCES("의학계열");


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import lombok.*;

import java.util.List;

@AllArgsConstructor
@NoArgsConstructor
@Getter
public class DepartmentResponse {

private String name;
private String type;
private List<String> name;

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import yerong.wedle.university.exception.UniversityNotFoundException;
import yerong.wedle.university.repository.UniversityRepository;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -29,7 +30,10 @@ public List<DepartmentResponse> getDepartmentNamesByType(Long universityId, Depa

List<Department> departments = departmentRepository.findByUniversityAndDepartmentType(university, departmentType);
return departments.stream()
.map(this::convertToDto)
.collect(Collectors.groupingBy(Department::getDepartmentType))
.entrySet().stream()
.sorted(Comparator.comparing(entry -> entry.getKey().ordinal()))
.map(entry -> convertToDto(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
}

Expand All @@ -39,15 +43,23 @@ public List<DepartmentResponse> getAllDepartmentNames(Long universityId) {
.orElseThrow(UniversityNotFoundException::new);

List<Department> departments = departmentRepository.findByUniversity(university);

return departments.stream()
.map(this::convertToDto)
.collect(Collectors.groupingBy(Department::getDepartmentType))
.entrySet().stream()
.sorted(Comparator.comparing(entry -> entry.getKey().ordinal()))
.map(entry -> convertToDto(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
}

private DepartmentResponse convertToDto(Department department) {
private DepartmentResponse convertToDto(DepartmentType departmentType, List<Department> departments) {
List<String> departmentNames = departments.stream()
.map(Department::getName)
.collect(Collectors.toList());

return new DepartmentResponse(
department.getName(),
department.getDepartmentType().getDisplayName()
departmentType.getDisplayName(),
departmentNames
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface UniversityRepository extends JpaRepository<University, Long> {
List<University> findByNameContainingOrLocationContaining(String name, String location);

Optional<University> findByName(String universityName);

List<University> findAllByOrderByNameAsc();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import yerong.wedle.competitionRate.dto.CompetitionRateResponse;
import yerong.wedle.competitionRate.repository.CompetitionRateRepository;
import yerong.wedle.department.domain.Department;
import yerong.wedle.department.domain.DepartmentType;
import yerong.wedle.department.dto.DepartmentResponse;
import yerong.wedle.department.repository.DepartmentRepository;
import yerong.wedle.employmentRate.domain.EmploymentRate;
Expand All @@ -24,6 +25,7 @@
import yerong.wedle.university.exception.UniversityNotFoundException;
import yerong.wedle.university.repository.UniversityRepository;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -62,15 +64,15 @@ public UniversityAllResponse getUniversityDetailsById(Long universityId) {
}
@Transactional
public List<UniversityResponse> getAllUniversitiesSummary() {
List<University> universities = universityRepository.findAll();
List<University> universities = universityRepository.findAllByOrderByNameAsc();
return universities.stream()
.map(this::convertToSummaryDto)
.collect(Collectors.toList());
}

@Transactional
public List<UniversityAllResponse> getAllUniversitiesDetails() {
List<University> universities = universityRepository.findAll();
List<University> universities = universityRepository.findAllByOrderByNameAsc();
return universities.stream()
.map(this::convertToDetailDto)
.collect(Collectors.toList());
Expand Down Expand Up @@ -108,7 +110,10 @@ private UniversityAllResponse convertToDetailDto(University university) {
.collect(Collectors.toList());

List<DepartmentResponse> departmentResponses = departments.stream()
.map(department -> new DepartmentResponse(department.getName(), department.getDepartmentType().getDisplayName()))
.collect(Collectors.groupingBy(Department::getDepartmentType))
.entrySet().stream()
.sorted(Comparator.comparing(entry -> entry.getKey().ordinal()))
.map(entry -> convertToDepartmentDto(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());

return new UniversityAllResponse(
Expand All @@ -126,6 +131,18 @@ private UniversityAllResponse convertToDetailDto(University university) {
employmentRateResponses
);
}

private DepartmentResponse convertToDepartmentDto(DepartmentType departmentType, List<Department> departments) {
List<String> departmentNames = departments.stream()
.map(Department::getName)
.collect(Collectors.toList());

return new DepartmentResponse(
departmentType.getDisplayName(),
departmentNames
);
}

private String getCurrentUserId() {
String socialId = SecurityContextHolder.getContext().getAuthentication().getName();

Expand Down

0 comments on commit 0eb3f95

Please sign in to comment.