Skip to content

Commit

Permalink
refactor: code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Mar 24, 2023
1 parent d8cabb0 commit 268ea52
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 142 deletions.
101 changes: 48 additions & 53 deletions src/main/java/com/dashboardbe/api/controller/OrderController.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.dashboardbe.api.controller;

import com.dashboardbe.aop.LoginCheck;
import com.dashboardbe.api.dto.*;
import com.dashboardbe.api.dto.ContentsOrderDTO;
import com.dashboardbe.api.dto.WeeklyVisitsDTO;
import com.dashboardbe.api.repository.AdminRepository;
import com.dashboardbe.api.service.OrderService;
import com.dashboardbe.common.SessionUtil;
import com.dashboardbe.common.response.BaseResponseBody;
import com.dashboardbe.domain.Admin;
import com.dashboardbe.domain.Category;
import com.dashboardbe.domain.MedicalDepartment;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -18,13 +15,11 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.tokens.ScalarToken;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Optional;

@CrossOrigin(origins = "*", allowedHeaders = "*")
@CrossOrigin(origins = "*", allowedHeaders = "*")
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/order")
Expand All @@ -44,16 +39,16 @@ public ResponseEntity<BaseResponseBody<List<String>>> selectWeeklyHospital(
HttpSession session
) {

List<String> memberOrderHospitalDTOList = orderService.selectMemberHospital();
List<String> memberOrderHospitalDTOList = orderService.selectMemberHospital();

return new ResponseEntity<BaseResponseBody<List<String>>>(
new BaseResponseBody<List<String>>(
HttpStatus.OK.value(),
"성공",
memberOrderHospitalDTOList
),
HttpStatus.OK
);
return new ResponseEntity<BaseResponseBody<List<String>>>(
new BaseResponseBody<List<String>>(
HttpStatus.OK.value(),
"성공",
memberOrderHospitalDTOList
),
HttpStatus.OK
);

}

Expand All @@ -67,16 +62,16 @@ public ResponseEntity<BaseResponseBody<List<MedicalDepartment>>> selectWeeklyDep
HttpSession session
) {

List<MedicalDepartment> memberOrderDepartmentDTOList = orderService.selectMemberDepartment();
List<MedicalDepartment> memberOrderDepartmentDTOList = orderService.selectMemberDepartment();

return new ResponseEntity<BaseResponseBody<List<MedicalDepartment>>>(
new BaseResponseBody<List<MedicalDepartment>>(
HttpStatus.OK.value(),
"성공",
memberOrderDepartmentDTOList
),
HttpStatus.OK
);
return new ResponseEntity<BaseResponseBody<List<MedicalDepartment>>>(
new BaseResponseBody<List<MedicalDepartment>>(
HttpStatus.OK.value(),
"성공",
memberOrderDepartmentDTOList
),
HttpStatus.OK
);

}

Expand All @@ -90,16 +85,16 @@ public ResponseEntity<BaseResponseBody<List<ContentsOrderDTO>>> selectWeeklyCont
HttpSession session
) {

List<ContentsOrderDTO> contentsOrderDTOList = orderService.selectContent();
List<ContentsOrderDTO> contentsOrderDTOList = orderService.selectContent();

return new ResponseEntity<BaseResponseBody<List<ContentsOrderDTO>>>(
new BaseResponseBody<List<ContentsOrderDTO>>(
HttpStatus.OK.value(),
"성공",
contentsOrderDTOList
),
HttpStatus.OK
);
return new ResponseEntity<BaseResponseBody<List<ContentsOrderDTO>>>(
new BaseResponseBody<List<ContentsOrderDTO>>(
HttpStatus.OK.value(),
"성공",
contentsOrderDTOList
),
HttpStatus.OK
);

}

Expand All @@ -113,16 +108,16 @@ public ResponseEntity<BaseResponseBody<List<WeeklyVisitsDTO>>> selectWeeklyVisit
HttpSession session
) {

List<WeeklyVisitsDTO> weeklyVisitsDTOList = orderService.selectWeeklyVisits();
List<WeeklyVisitsDTO> weeklyVisitsDTOList = orderService.selectWeeklyVisits();

return new ResponseEntity<BaseResponseBody<List<WeeklyVisitsDTO>>>(
new BaseResponseBody<List<WeeklyVisitsDTO>>(
HttpStatus.OK.value(),
"성공",
weeklyVisitsDTOList
),
HttpStatus.OK
);
return new ResponseEntity<BaseResponseBody<List<WeeklyVisitsDTO>>>(
new BaseResponseBody<List<WeeklyVisitsDTO>>(
HttpStatus.OK.value(),
"성공",
weeklyVisitsDTOList
),
HttpStatus.OK
);

}

Expand All @@ -140,16 +135,16 @@ public ResponseEntity<BaseResponseBody<List<Long>>> selectContentsChanges(
// // 올바른 관리자라면
// if (optionalAdmin.isPresent()) {

List<Long> changes = orderService.selectContentChanges();
List<Long> changes = orderService.selectContentChanges();

return new ResponseEntity<BaseResponseBody<List<Long>>>(
new BaseResponseBody<List<Long>>(
HttpStatus.OK.value(),
"성공",
changes
),
HttpStatus.OK
);
return new ResponseEntity<BaseResponseBody<List<Long>>>(
new BaseResponseBody<List<Long>>(
HttpStatus.OK.value(),
"성공",
changes
),
HttpStatus.OK
);

// } else {
// return new ResponseEntity<BaseResponseBody<List<Long>>>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
package com.dashboardbe.api.controller;

import com.dashboardbe.aop.LoginCheck;
import com.dashboardbe.api.dto.original.OriginalContentsDTO;
import com.dashboardbe.api.dto.original.OriginalWeeklyInfoDTO;
import com.dashboardbe.api.dto.original.WeeklyInfoResponseDTO;
import com.dashboardbe.api.repository.AdminRepository;
import com.dashboardbe.api.service.OriginalService;
import com.dashboardbe.common.SessionUtil;
import com.dashboardbe.common.response.BaseResponseBody;
import com.dashboardbe.domain.Admin;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.lang.model.util.Elements;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Optional;

@CrossOrigin(origins = "*", allowedHeaders = "*")
@CrossOrigin(origins = "*", allowedHeaders = "*")
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/original")
Expand All @@ -41,17 +35,17 @@ public ResponseEntity<BaseResponseBody<WeeklyInfoResponseDTO>> selectWeeklyInfo(
HttpSession session
) {

WeeklyInfoResponseDTO weeklyInfo = originalService.selectWeeklyInfo();
WeeklyInfoResponseDTO weeklyInfo = originalService.selectWeeklyInfo();

return new ResponseEntity<BaseResponseBody<WeeklyInfoResponseDTO>>(
new BaseResponseBody<WeeklyInfoResponseDTO>(
HttpStatus.OK.value(),
"성공",
weeklyInfo
return new ResponseEntity<BaseResponseBody<WeeklyInfoResponseDTO>>(
new BaseResponseBody<WeeklyInfoResponseDTO>(
HttpStatus.OK.value(),
"성공",
weeklyInfo

),
HttpStatus.OK
);
),
HttpStatus.OK
);

}

Expand All @@ -74,16 +68,16 @@ public ResponseEntity<BaseResponseBody<List<OriginalContentsDTO.Res>>> selectCon

OriginalContentsDTO.Req request = new OriginalContentsDTO.Req(countYn, searchWord);

List<OriginalContentsDTO.Res> ContentsInfo = originalService.selectContentsInfo(request);
List<OriginalContentsDTO.Res> ContentsInfo = originalService.selectContentsInfo(request);

return new ResponseEntity<BaseResponseBody<List<OriginalContentsDTO.Res>>>(
new BaseResponseBody<List<OriginalContentsDTO.Res>>(
HttpStatus.OK.value(),
"성공",
ContentsInfo
),
HttpStatus.OK
);
return new ResponseEntity<BaseResponseBody<List<OriginalContentsDTO.Res>>>(
new BaseResponseBody<List<OriginalContentsDTO.Res>>(
HttpStatus.OK.value(),
"성공",
ContentsInfo
),
HttpStatus.OK
);

// } else {
// return new ResponseEntity<BaseResponseBody<List<OriginalContentsDTO.Res>>>(
Expand Down
103 changes: 53 additions & 50 deletions src/main/java/com/dashboardbe/api/repository/OrderRepository.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.dashboardbe.api.repository;

import com.dashboardbe.api.dto.*;
import com.dashboardbe.api.dto.ContentsChangesDTO;
import com.dashboardbe.api.dto.ContentsOrderDTO;
import com.dashboardbe.api.dto.WeeklyVisitsDTO;
import com.dashboardbe.api.dto.YestWeekReqDTO;
import com.dashboardbe.domain.*;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Projections;
Expand Down Expand Up @@ -50,7 +53,7 @@ public List<MedicalDepartment> selectDepartmentInMemberAnalysis(YestWeekReqDTO y

QMemberAnalysis m = QMemberAnalysis.memberAnalysis;

return (List<MedicalDepartment>) jpaQueryFactory
return jpaQueryFactory
.select(
m.medicalDepartment.as("medicalDepartment")
)
Expand Down Expand Up @@ -95,42 +98,42 @@ public List<WeeklyVisitsDTO> findWeeklyVisitsInMember(YestWeekReqDTO yestWeekReq

WeeklyVisitsDTO.class,

ExpressionUtils.as(
JPAExpressions
.select(c.contents.count())
.from(c)
.where(c.visitDate.between(yestWeekReqDTO.getYestWeek(), yestWeekReqDTO.getYestDay())),
"ContentsHits"
),

ExpressionUtils.as(
JPAExpressions
.select(m.name.count())
.from(m)
.where(m.createTime.between(yestWeekReqDTO.getYestWeek(), yestWeekReqDTO.getYestDay())),
"all"
),

ExpressionUtils.as(
JPAExpressions
.select(m.name.count())
.from(m)
.where(
m.createTime.between(yestWeekReqDTO.getYestWeek(), yestWeekReqDTO.getYestDay()),
m.isMember.eq("N")
),
"quit"
),

ExpressionUtils.as(
JPAExpressions
.select(m.name.count())
.from(m)
.where(
m.createTime.between(LocalDateTime.now().minusDays(2), LocalDateTime.now().minusDays(1))
),
"newbie"
)
ExpressionUtils.as(
JPAExpressions
.select(c.contents.count())
.from(c)
.where(c.visitDate.between(yestWeekReqDTO.getYestWeek(), yestWeekReqDTO.getYestDay())),
"ContentsHits"
),

ExpressionUtils.as(
JPAExpressions
.select(m.name.count())
.from(m)
.where(m.createTime.between(yestWeekReqDTO.getYestWeek(), yestWeekReqDTO.getYestDay())),
"all"
),

ExpressionUtils.as(
JPAExpressions
.select(m.name.count())
.from(m)
.where(
m.createTime.between(yestWeekReqDTO.getYestWeek(), yestWeekReqDTO.getYestDay()),
m.isMember.eq("N")
),
"quit"
),

ExpressionUtils.as(
JPAExpressions
.select(m.name.count())
.from(m)
.where(
m.createTime.between(LocalDateTime.now().minusDays(2), LocalDateTime.now().minusDays(1))
),
"newbie"
)

)

Expand All @@ -152,20 +155,20 @@ public List<ContentsChangesDTO.Req> findYestContentChanges(YestWeekReqDTO yestWe
ContentsChangesDTO.Req.class,

// Math.toIntExact(
ExpressionUtils.as(
JPAExpressions
.select(m.category.count())
.from(m)
.where(m.visitDate.between(yestWeekReqDTO.getYestWeek(), yestWeekReqDTO.getYestDay())),
"thisWeek"),
ExpressionUtils.as(
JPAExpressions
.select(m.category.count())
.from(m)
.where(m.visitDate.between(yestWeekReqDTO.getYestWeek(), yestWeekReqDTO.getYestDay())),
"thisWeek"),
// ),
// Math.toIntExact(
ExpressionUtils.as(
JPAExpressions
.select(m.category.count())
.from(m)
.where(m.visitDate.between(yestWeekReqDTO.getPastWeek(), yestWeekReqDTO.getYestWeek())),
"pastWeek")
ExpressionUtils.as(
JPAExpressions
.select(m.category.count())
.from(m)
.where(m.visitDate.between(yestWeekReqDTO.getPastWeek(), yestWeekReqDTO.getYestWeek())),
"pastWeek")
// )

)
Expand Down
Loading

0 comments on commit 268ea52

Please sign in to comment.