Skip to content

Commit

Permalink
Merge pull request #149 from UMC-WOWMARKET/feat/like
Browse files Browse the repository at this point in the history
[Refactor] 메인페이지 전체적인 리팩토링
  • Loading branch information
yoonsseo authored Jan 4, 2024
2 parents a9e8709 + 6dc84c9 commit 52fb001
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 130 deletions.
25 changes: 11 additions & 14 deletions src/main/java/wowmarket/wow_server/demand/dto/DemandDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,26 @@
import lombok.NoArgsConstructor;
import wowmarket.wow_server.domain.DemandProject;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Getter
@NoArgsConstructor
public class DemandDto {
private Long project_id;
private String project_name;
private String seller_name;
private LocalDateTime start_date;
private LocalDateTime end_date;
private Long projectId;
private String sellerName;
private String projectName;
private LocalDateTime endDate;
private String thumbnail;
private int achieved; //달성률 분자: 모든 주문상세의 '주문개수' 컬럼의 합
private int goal; //달성률 분모: 상품 테이블에서 프로젝트 번호로 조회하여 해당 프로젝트에 들어있는 상품의 목표치의 합

public DemandDto(DemandProject demandProject, int demandProject_total_count, int demandProject_total_goal) {
this.project_id = demandProject.getId();
this.project_name = demandProject.getProjectName();
this.seller_name = demandProject.getSellerName();
this.start_date = demandProject.getStartDate();
this.end_date = demandProject.getEndDate();
public DemandDto(DemandProject demandProject, int demandProjectTotalCount, int demandProjectTotalGoal) {
this.projectId = demandProject.getId();
this.sellerName = demandProject.getSellerName();
this.projectName = demandProject.getProjectName();
this.endDate = demandProject.getEndDate();
this.thumbnail = demandProject.getThumbnail();
this.achieved = demandProject_total_count;
this.goal = demandProject_total_goal;
this.achieved = demandProjectTotalCount;
this.goal = demandProjectTotalGoal;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

import lombok.Getter;
import lombok.NoArgsConstructor;
import wowmarket.wow_server.sale.dto.SaleDto;

import java.util.List;

@NoArgsConstructor
@Getter
public class DemandResponseDto {
private String univ;
private int total_page;
private int current_page;
private List<DemandDto> project_list;
private String userUniv;
private int totalPage;
private int currentPage;
private List<DemandDto> projectList;

public DemandResponseDto(String univ, int total_page, int current_page, List<DemandDto> newDtos) {
this.univ = univ;
this.total_page = total_page;
this.current_page = current_page;
this.project_list = newDtos;
public DemandResponseDto(String univ, int totalPage, int currentPage, List<DemandDto> newDtos) {
this.userUniv = univ;
this.totalPage = totalPage;
this.currentPage = currentPage;
this.projectList = newDtos;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
import wowmarket.wow_server.domain.User;
import wowmarket.wow_server.repository.DemandItemRepository;
import wowmarket.wow_server.repository.DemandProjectRepository;
import wowmarket.wow_server.repository.UserRepository;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;

Expand All @@ -26,32 +25,31 @@
public class DemandHomeService {
private final DemandProjectRepository demandProjectRepository;
private final DemandItemRepository demandItemRepository;
private final UserRepository userRepository;

public DemandResponseDto findDemandProjectHome(Pageable pageable, String univ, User user) {
String user_univ = "allUniv";
boolean user_univ_check = false;
LocalDate current_date = LocalDate.now(ZoneId.of("Asia/Seoul"));
String userUniv = "allUniv";
boolean userUnivCheck = false;
LocalDateTime currentDate = LocalDateTime.now(ZoneId.of("Asia/Seoul"));

Page<DemandProject> findDemandProjects = new PageImpl<>(new ArrayList<>(), pageable, 0);

if (user != null) {
user_univ_check = user.isUniv_check();
if (user_univ_check) {
user_univ = user.getUniv();
userUnivCheck = user.isUniv_check();
if (userUnivCheck) {
userUniv = user.getUniv();
}
}

if (univ.equals("myUniv")) {
if (user == null) { // 로그인 X
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "로그인이 필요한 서비스입니다.");
} else if (user_univ_check) { // 학교인증 O -> 로그인 O
findDemandProjects = demandProjectRepository.findByUserUniv(current_date, user_univ, pageable);
} else if (userUnivCheck) { // 학교인증 O -> 로그인 O
findDemandProjects = demandProjectRepository.findByUserUniv(currentDate, userUniv, pageable);
} else { // 학교인증 X
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "학교 인증이 필요한 서비스입니다.");
}
} else if (univ.equals("allUniv")) {
findDemandProjects = demandProjectRepository.findAllNotEnd(current_date, pageable);
findDemandProjects = demandProjectRepository.findAllNotEnd(currentDate, pageable);
} else {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "올바른 필터링 값이 아닙니다.");
}
Expand All @@ -60,7 +58,7 @@ public DemandResponseDto findDemandProjectHome(Pageable pageable, String univ, U
demandItemRepository.getTotalOrderCountByDemandProject(demandProject),
demandItemRepository.getTotalGoalByDemandProject(demandProject)));

return new DemandResponseDto(user_univ,
return new DemandResponseDto(userUniv,
demandProjectDtos.getTotalPages(),
demandProjectDtos.getNumber(),
demandProjectDtos.getContent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
import wowmarket.wow_server.domain.User;
import wowmarket.wow_server.repository.DemandItemRepository;
import wowmarket.wow_server.repository.DemandProjectRepository;
import wowmarket.wow_server.repository.UserRepository;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;

Expand All @@ -26,32 +25,31 @@
public class DemandSearchService {
private final DemandProjectRepository demandProjectRepository;
private final DemandItemRepository demandItemRepository;
private final UserRepository userRepository;

public DemandResponseDto findDemandProjectSearch(String search, Pageable pageable, String univ, User user) {
String user_univ = "allUniv";
boolean user_univ_check = false;
LocalDate current_date = LocalDate.now(ZoneId.of("Asia/Seoul"));
String userUniv = "allUniv";
boolean userUnivCheck = false;
LocalDateTime currentDate = LocalDateTime.now(ZoneId.of("Asia/Seoul"));

Page<DemandProject> findDemandProjects = new PageImpl<>(new ArrayList<>(), pageable, 0);

if (user != null) {
user_univ_check = user.isUniv_check();
if (user_univ_check) {
user_univ = user.getUniv();
userUnivCheck = user.isUniv_check();
if (userUnivCheck) {
userUniv = user.getUniv();
}
}

if (univ.equals("myUniv")) {
if (user == null) { // 로그인 X
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "로그인이 필요한 서비스입니다.");
} else if (user_univ_check) { // 학교인증 O -> 로그인 O
findDemandProjects = demandProjectRepository.findBySearchUserUniv(current_date, search, user_univ, pageable);
} else if (userUnivCheck) { // 학교인증 O -> 로그인 O
findDemandProjects = demandProjectRepository.findBySearchUserUniv(currentDate, search, userUniv, pageable);
} else { // 학교인증 X
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "학교 인증이 필요한 서비스입니다.");
}
} else if (univ.equals("allUniv")) {
findDemandProjects = demandProjectRepository.findBySearch(current_date, search, pageable);
findDemandProjects = demandProjectRepository.findBySearch(currentDate, search, pageable);
} else {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "올바른 필터링 값이 아닙니다.");
}
Expand All @@ -60,7 +58,7 @@ public DemandResponseDto findDemandProjectSearch(String search, Pageable pageabl
demandItemRepository.getTotalOrderCountByDemandProject(demandProject),
demandItemRepository.getTotalGoalByDemandProject(demandProject)));

return new DemandResponseDto(user_univ,
return new DemandResponseDto(userUniv,
demandProjectDtos.getTotalPages(),
demandProjectDtos.getNumber(),
demandProjectDtos.getContent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@
import org.springframework.transaction.annotation.Transactional;
import wowmarket.wow_server.domain.DemandProject;

import java.time.LocalDate;
import java.time.LocalDateTime;

public interface DemandProjectRepository extends JpaRepository<DemandProject, Long> {
@Query("SELECT dp FROM DemandProject dp " +
"WHERE dp.isEnd = false " +
"AND dp.startDate <= :current_date AND dp.endDate >= :current_date " +
"AND dp.user.univ = :user_univ")
Page<DemandProject> findByUserUniv(@Param("current_date") LocalDate current_date, @Param("user_univ") String user_univ, Pageable pageable);
"AND dp.startDate <= :currentDate AND dp.endDate >= :currentDate " +
"AND dp.user.univ = :userUniv")
Page<DemandProject> findByUserUniv(@Param("currentDate") LocalDateTime currentDate, @Param("userUniv") String userUniv, Pageable pageable);

@Query("SELECT dp FROM DemandProject dp WHERE dp.isEnd = false " +
"AND dp.startDate <= :current_date AND dp.endDate >= :current_date")
Page<DemandProject> findAllNotEnd(@Param("current_date") LocalDate current_date, Pageable pageable);
"AND dp.startDate <= :currentDate AND dp.endDate >= :currentDate")
Page<DemandProject> findAllNotEnd(@Param("currentDate") LocalDateTime currentDate, Pageable pageable);

@Query("SELECT dp FROM DemandProject dp " +
"WHERE dp.isEnd = false " +
"AND dp.startDate <= :current_date AND dp.endDate >= :current_date " +
"AND dp.startDate <= :currentDate AND dp.endDate >= :currentDate " +
"AND dp.projectName LIKE CONCAT('%', :search, '%') " +
"AND dp.user.univ = :user_univ")
Page<DemandProject> findBySearchUserUniv(@Param("current_date") LocalDate current_date, @Param("search") String search,
@Param("user_univ") String user_univ, Pageable pageable);
"AND dp.user.univ = :userUniv")
Page<DemandProject> findBySearchUserUniv(@Param("currentDate") LocalDateTime currentDate, @Param("search") String search,
@Param("userUniv") String userUniv, Pageable pageable);

@Query("SELECT dp FROM DemandProject dp " +
"WHERE dp.isEnd = false " +
"AND dp.startDate <= :current_date AND dp.endDate >= :current_date " +
"AND dp.startDate <= :currentDate AND dp.endDate >= :currentDate " +
"AND dp.projectName LIKE CONCAT('%', :search, '%')")
Page<DemandProject> findBySearch(@Param("current_date") LocalDate current_date, @Param("search") String search, Pageable pageable);
Page<DemandProject> findBySearch(@Param("currentDate") LocalDateTime currentDate, @Param("search") String search, Pageable pageable);

Page<DemandProject> findDemandProjectByUser_Id(Long seller_id, Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.security.core.parameters.P;
import org.springframework.transaction.annotation.Transactional;
import wowmarket.wow_server.domain.Project;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

public interface ProjectRepository extends JpaRepository<Project, Long> {
@Query("SELECT p FROM Project p " +
"WHERE p.isDel = false AND p.isEnd = false " +
"AND p.startDate <= :current_date AND p.endDate >= :current_date " +
"AND p.user.univ = :user_univ")
Page<Project> findByUserUniv(@Param("user_univ") String user_univ, @Param("current_date") LocalDate current_date, Pageable pageable);
"AND p.startDate <= :currentDate AND p.endDate >= :currentDate " +
"AND p.user.univ = :userUniv")
Page<Project> findByUserUniv(@Param("userUniv") String userUniv, @Param("currentDate") LocalDateTime currentDate, Pageable pageable);

@Query("SELECT p FROM Project p WHERE p.isDel = false AND p.isEnd = false " +
"AND p.startDate <= :current_date AND p.endDate >= :current_date")
Page<Project> findAllNotDelNotEnd(@Param("current_date") LocalDate current_date, Pageable pageable);
"AND p.startDate <= :currentDate AND p.endDate >= :currentDate")
Page<Project> findAllNotDelNotEnd(@Param("currentDate") LocalDateTime currentDate, Pageable pageable);

@Query("SELECT p FROM Project p " +
"WHERE p.isDel = false AND p.isEnd = false " +
"AND p.startDate <= :current_date AND p.endDate >= :current_date " +
"AND p.startDate <= :currentDate AND p.endDate >= :currentDate " +
"AND p.projectName LIKE CONCAT('%', :search, '%') " +
"AND p.user.univ = :user_univ")
Page<Project> findBySearchUserUniv(@Param("current_date") LocalDate current_date, @Param("search") String search,
@Param("user_univ") String user_univ, Pageable pageable);
"AND p.user.univ = :userUniv")
Page<Project> findBySearchUserUniv(@Param("currentDate") LocalDateTime currentDate, @Param("search") String search,
@Param("userUniv") String userUniv, Pageable pageable);

@Query("SELECT p FROM Project p " +
"WHERE p.isDel = false AND p.isEnd = false " +
"AND p.startDate <= :current_date AND p.endDate >= :current_date " +
"AND p.startDate <= :currentDate AND p.endDate >= :currentDate " +
"AND p.projectName LIKE CONCAT('%', :search, '%')")
Page<Project> findBySearch(@Param("current_date") LocalDate current_date, @Param("search") String search, Pageable pageable);
Page<Project> findBySearch(@Param("currentDate") LocalDateTime currentDate, @Param("search") String search, Pageable pageable);

Page<Project> findByUser_Id(Long sellerId, Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
import wowmarket.wow_server.sale.service.SaleHomeService;
import wowmarket.wow_server.sale.service.SaleSearchService;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.TimeZone;

@RestController
@RequestMapping("/sale")
@RequiredArgsConstructor
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/wowmarket/wow_server/sale/dto/SaleDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,26 @@
import lombok.NoArgsConstructor;
import wowmarket.wow_server.domain.Project;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Getter
@NoArgsConstructor
public class SaleDto {
private Long project_id;
private String project_name;
private String seller_name;
private LocalDateTime start_date;
private LocalDateTime end_date;
private Long projectId;
private String sellerName;
private String projectName;
private LocalDateTime endDate;
private String thumbnail;
private int achieved; //달성률 분자: 모든 주문상세의 '주문개수' 컬럼의 합
private int goal; //달성률 분모: 상품 테이블에서 프로젝트 번호로 조회하여 해당 프로젝트에 들어있는 상품의 목표치의 합

public SaleDto(Project project, int project_total_count, int project_total_goal) {
this.project_id = project.getId();
this.project_name = project.getProjectName();
this.seller_name = project.getSellerName();
this.start_date = project.getStartDate();
this.end_date = project.getEndDate();
public SaleDto(Project project, int projectTotalCount, int projectTotalGoal) {
this.projectId = project.getId();
this.sellerName = project.getSellerName();
this.projectName = project.getProjectName();
this.endDate = project.getEndDate();
this.thumbnail = project.getThumbnail();
this.achieved = project_total_count;
this.goal = project_total_goal;
this.achieved = projectTotalCount;
this.goal = projectTotalGoal;
}
}
18 changes: 9 additions & 9 deletions src/main/java/wowmarket/wow_server/sale/dto/SaleResponseDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
@Getter
@NoArgsConstructor
public class SaleResponseDto {
private String univ;
private int total_page;
private int current_page;
private List<SaleDto> project_list;
private String userUniv;
private int totalPage;
private int currentPage;
private List<SaleDto> projectList;

public SaleResponseDto(String user_univ, int total_page, int current_page, List<SaleDto> newDtos) {
this.univ = user_univ;
this.total_page = total_page;
this.current_page = current_page;
this.project_list = newDtos;
public SaleResponseDto(String userUniv, int totalPage, int currentPage, List<SaleDto> newDtos) {
this.userUniv = userUniv;
this.totalPage = totalPage;
this.currentPage = currentPage;
this.projectList = newDtos;
}
}
Loading

0 comments on commit 52fb001

Please sign in to comment.