Skip to content

Commit

Permalink
Merge pull request #1257 from innovationacademy-kr/be/dev/fix_section…
Browse files Browse the repository at this point in the history
…_view_query

[BE] 층별 전체 사물함 조회 뷰 성능 개선
  • Loading branch information
sichoi42 authored Jul 21, 2023
2 parents e73afc5 + a1c9bf4 commit b128d36
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 493 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.ftclub.cabinet.cabinet.controller;

import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.ftclub.cabinet.auth.domain.AuthGuard;
Expand All @@ -16,6 +15,8 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* 일반 사용자가 사물함 서비스를 사용하기 위한 컨트롤러입니다.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
package org.ftclub.cabinet.cabinet.domain;

import static org.ftclub.cabinet.exception.ExceptionStatus.*;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.ftclub.cabinet.exception.DomainException;
import org.ftclub.cabinet.lent.domain.LentHistory;
import org.ftclub.cabinet.utils.ExceptionUtil;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;

import static org.ftclub.cabinet.exception.ExceptionStatus.INVALID_ARGUMENT;
import static org.ftclub.cabinet.exception.ExceptionStatus.INVALID_STATUS;

/**
* 사물함 엔티티
*/
@Entity
@Table(name = "CABINET")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@ToString(exclude = {"cabinetPlace", "lentHistories"})
public class Cabinet {

@Id
Expand Down Expand Up @@ -89,8 +84,14 @@ public class Cabinet {
@JoinColumn(name = "CABINET_PLACE_ID")
private CabinetPlace cabinetPlace;

@OneToMany(mappedBy = "cabinet",
targetEntity = LentHistory.class,
cascade = CascadeType.ALL,
fetch = FetchType.LAZY)
private List<LentHistory> lentHistories;

protected Cabinet(Integer visibleNum, CabinetStatus status, LentType lentType, Integer maxUser,
Grid grid, CabinetPlace cabinetPlace) {
Grid grid, CabinetPlace cabinetPlace) {
this.visibleNum = visibleNum;
this.status = status;
this.lentType = lentType;
Expand All @@ -102,8 +103,8 @@ protected Cabinet(Integer visibleNum, CabinetStatus status, LentType lentType, I
}

public static Cabinet of(Integer visibleNum, CabinetStatus status, LentType lentType,
Integer maxUser,
Grid grid, CabinetPlace cabinetPlace) {
Integer maxUser,
Grid grid, CabinetPlace cabinetPlace) {
Cabinet cabinet = new Cabinet(visibleNum, status, lentType, maxUser, grid, cabinetPlace);
ExceptionUtil.throwIfFalse(cabinet.isValid(), new DomainException(INVALID_ARGUMENT));
return cabinet;
Expand Down Expand Up @@ -185,6 +186,11 @@ public boolean equals(final Object other) {
return this.cabinetId.equals(((Cabinet) other).cabinetId);
}

@Override
public int hashCode() {
return Objects.hash(this.cabinetId);
}

/**
* 대여 시작/종료에 따른 사용자의 수와 현재 상태에 따라 상태를 변경합니다.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package org.ftclub.cabinet.cabinet.domain;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.ftclub.cabinet.exception.DomainException;
import org.ftclub.cabinet.exception.ExceptionStatus;
import org.ftclub.cabinet.utils.ExceptionUtil;

import javax.persistence.Column;
import javax.persistence.Embeddable;

/**
* 건물, 층, 구역에 대한 정보입니다.
*/
@Embeddable
@NoArgsConstructor
@EqualsAndHashCode
@Getter
@ToString
public class Location {

@Column(name = "BUILDING")
Expand All @@ -31,13 +34,13 @@ protected Location(String building, Integer floor, String section) {
this.section = section;
}

private boolean isValid() {
return (this.building != null && this.floor > 0 && this.section != null);
}

public static Location of(String building, Integer floor, String section) {
Location location = new Location(building, floor, section);
ExceptionUtil.throwIfFalse(location.isValid(), new DomainException(ExceptionStatus.INVALID_ARGUMENT));
return location;
}

private boolean isValid() {
return (this.building != null && this.floor > 0 && this.section != null);
}
}
Loading

0 comments on commit b128d36

Please sign in to comment.