Skip to content

Commit

Permalink
Merge pull request #1275 from innovationacademy-kr/be/dev/log-interce…
Browse files Browse the repository at this point in the history
…ptor

[BE] log 설정
  • Loading branch information
eunbi9n authored Jul 28, 2023
2 parents 200d9f0 + dbc956b commit 516d662
Show file tree
Hide file tree
Showing 37 changed files with 471 additions and 231 deletions.
1 change: 1 addition & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
implementation 'org.modelmapper:modelmapper:3.1.1'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public class AdminCabinetController {
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public CabinetInfoResponseDto getCabinetInfo(
@PathVariable("cabinetId") Long cabinetId) {
if (cabinetId == null) {
throw new ControllerException(ExceptionStatus.INCORRECT_ARGUMENT);
}
log.info("Called getCabinetInfo: {}", cabinetId);
return cabinetFacadeService.getCabinetInfo(cabinetId);
}
Expand All @@ -68,11 +65,11 @@ public CabinetInfoResponseDto getCabinetInfo(
public void updateCabinetStatusNote(
@PathVariable("cabinetId") Long cabinetId,
@RequestBody HashMap<String, String> body) {
if (cabinetId == null || body == null || body.isEmpty() || !body.containsKey(
log.info("Called updateCabinetStatusNote: {}", cabinetId);
if (body == null || body.isEmpty() || !body.containsKey(
"statusNote")) {
throw new ControllerException(ExceptionStatus.INCORRECT_ARGUMENT);
}
log.info("Called updateCabinetStatusNote: {}", cabinetId);
cabinetFacadeService.updateCabinetStatusNote(cabinetId, body.get("statusNote"));
}

Expand All @@ -88,26 +85,26 @@ public void updateCabinetStatusNote(
public void updateCabinetTitle(
@PathVariable("cabinetId") Long cabinetId,
@RequestBody HashMap<String, String> body) {
if (cabinetId == null || body == null || body.isEmpty() || !body.containsKey("title")) {
log.info("Called updateCabinetTitle: {}", cabinetId);
if (body == null || body.isEmpty() || !body.containsKey("title")) {
throw new ControllerException(ExceptionStatus.INCORRECT_ARGUMENT);
}
log.info("Called updateCabinetTitle: {}", cabinetId);
cabinetFacadeService.updateCabinetTitle(cabinetId, body.get("title"));
}

@PatchMapping("/")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void updateCabinetBundleStatus(
@Valid @RequestBody CabinetStatusRequestDto cabinetStatusRequestDto) {
log.info("Called updateCabinetBundleStatus: {}", cabinetStatusRequestDto);
log.info("Called updateCabinetBundleStatus: {}", cabinetStatusRequestDto.getCabinetIds());
cabinetFacadeService.updateCabinetBundleStatus(cabinetStatusRequestDto);
}

@PatchMapping("/club")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void updateCabinetClubStatus(
@Valid @RequestBody CabinetClubStatusRequestDto cabinetClubStatusRequestDto) {
log.info("Called updateCabinetClubStatus: {}", cabinetClubStatusRequestDto);
log.info("Called updateCabinetClubStatus: {}", cabinetClubStatusRequestDto.getCabinetId());
cabinetFacadeService.updateCabinetClubStatus(cabinetClubStatusRequestDto);
lentFacadeService.startLentClubCabinet(cabinetClubStatusRequestDto.getUserId(),
cabinetClubStatusRequestDto.getCabinetId());
Expand All @@ -126,12 +123,11 @@ public void updateCabinetClubStatus(
public void updateCabinetGrid(
@PathVariable("cabinetId") Long cabinetId,
@RequestBody Map<String, Integer> body) {

if (cabinetId == null || body == null || body.isEmpty() || !body.containsKey("row")
log.info("Called updateCabinetGrid: {}", cabinetId);
if (body == null || body.isEmpty() || !body.containsKey("row")
|| !body.containsKey("col")) {
throw new ControllerException(ExceptionStatus.INCORRECT_ARGUMENT);
}
log.info("Called updateCabinetGrid: {}", cabinetId);
cabinetFacadeService.updateCabinetGrid(cabinetId, body.get("row"), body.get("col"));
}

Expand All @@ -147,11 +143,11 @@ public void updateCabinetGrid(
public void updateCabinetVisibleNum(
@PathVariable("cabinetId") Long cabinetId,
@RequestBody HashMap<String, Integer> body) {
if (cabinetId == null || body == null || body.isEmpty() || !body.containsKey(
log.info("Called updateCabinetVisibleNum: {}", cabinetId);
if (body == null || body.isEmpty() || !body.containsKey(
"visibleNum")) {
throw new ControllerException(ExceptionStatus.INCORRECT_ARGUMENT);
}
log.info("Called updateCabinetVisibleNum: {}", cabinetId);
cabinetFacadeService.updateCabinetVisibleNum(cabinetId, body.get("visibleNum"));
}

Expand All @@ -167,7 +163,7 @@ public void updateCabinetVisibleNum(
// public void updateCabinetBundleStatus(
// @Valid @RequestBody UpdateCabinetsRequestDto updateCabinetsRequestDto,
// @PathVariable("status") CabinetStatus status) {
// log.info("Called updateCabinetBundleStatus: {}", status);
// log.debug("Called updateCabinetBundleStatus: {}", status);
// cabinetFacadeService.updateCabinetBundleStatus(updateCabinetsRequestDto, status);
// }

Expand Down Expand Up @@ -203,9 +199,7 @@ public CabinetPaginationDto getCabinetsByLentType(
@PathVariable("lentType") LentType lentType,
@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
if (lentType == null) {
throw new ControllerException(ExceptionStatus.INCORRECT_ARGUMENT);
}
log.info("Called getCabinetsByLentType: {}", lentType);
return cabinetFacadeService.getCabinetPaginationByLentType(lentType, page, size);
}

Expand All @@ -223,9 +217,7 @@ public CabinetPaginationDto getCabinetsByStatus(
@PathVariable("status") CabinetStatus status,
@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
if (status == null) {
throw new ControllerException(ExceptionStatus.INCORRECT_ARGUMENT);
}
log.info("Called getCabinetsByStatus: {}", status);
return cabinetFacadeService.getCabinetPaginationByStatus(status, page, size);
}

Expand All @@ -243,9 +235,7 @@ public CabinetPaginationDto getCabinetsByVisibleNum(
@PathVariable("visibleNum") Integer visibleNum,
@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
if (visibleNum == null) {
throw new ControllerException(ExceptionStatus.INCORRECT_ARGUMENT);
}
log.info("Called getCabinetsByVisibleNum: {}", visibleNum);
return cabinetFacadeService.getCabinetPaginationByVisibleNum(visibleNum, page, size);
}

Expand All @@ -263,9 +253,7 @@ public LentHistoryPaginationDto getCabinetLentHistories(@Valid
@PathVariable("cabinetId") Long cabinetId,
@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
if (cabinetId == null) {
throw new ControllerException(ExceptionStatus.INCORRECT_ARGUMENT);
}
log.info("Called getCabinetLentHistories: {}", cabinetId);
return cabinetFacadeService.getCabinetLentHistoriesPagination(cabinetId, page, size);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public List<BuildingFloorsDto> getBuildingFloorsResponse() {
public List<CabinetsPerSectionResponseDto> getCabinetsPerSection(
@PathVariable("building") String building,
@PathVariable("floor") Integer floor) {
if (building == null || floor == null) {
throw new ControllerException(ExceptionStatus.INCORRECT_ARGUMENT);
}
log.info("Called getCabinetsPerSection");
log.info("Called getCabinetsPerSection building : {} floor : {}", building, floor);
return cabinetFacadeService.getCabinetsPerSection(building, floor);
}

Expand All @@ -71,10 +68,7 @@ public List<CabinetsPerSectionResponseDto> getCabinetsPerSection(
@AuthGuard(level = AuthLevel.USER_OR_ADMIN)
public CabinetInfoResponseDto getCabinetInfo(
@PathVariable("cabinetId") Long cabinetId) {
if (cabinetId == null) {
throw new ControllerException(ExceptionStatus.INCORRECT_ARGUMENT);
}
log.info("Called getCabinetInfo");
log.info("Called getCabinetInfo {}", cabinetId);
return cabinetFacadeService.getCabinetInfo(cabinetId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.extern.log4j.Log4j2;
import org.ftclub.cabinet.exception.DomainException;
import org.ftclub.cabinet.lent.domain.LentHistory;
import org.ftclub.cabinet.utils.ExceptionUtil;
Expand All @@ -39,6 +40,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@ToString(exclude = {"cabinetPlace", "lentHistories"})
@Log4j2
public class Cabinet {

@Id
Expand Down Expand Up @@ -148,45 +150,54 @@ public boolean isCabinetPlace(CabinetPlace cabinetPlace) {
}

public void specifyCabinetPlace(CabinetPlace cabinetPlace) {
log.info("setCabinetPlace : {}", cabinetPlace);
this.cabinetPlace = cabinetPlace;
}

public void assignVisibleNum(Integer visibleNum) {
log.info("assignVisibleNum : {}", visibleNum);
this.visibleNum = visibleNum;
ExceptionUtil.throwIfFalse(this.isValid(), new DomainException(INVALID_STATUS));
}

public void specifyStatus(CabinetStatus cabinetStatus) {
log.info("specifyStatus : {}", cabinetStatus);
this.status = cabinetStatus;
ExceptionUtil.throwIfFalse(this.isValid(), new DomainException(INVALID_STATUS));
}

public void specifyMaxUser(Integer maxUser) {
log.info("specifyMaxUser : {}", maxUser);
this.maxUser = maxUser;
ExceptionUtil.throwIfFalse(this.isValid(), new DomainException(INVALID_STATUS));
}

public void writeStatusNote(String statusNote) {
log.info("writeStatusNote : {}", statusNote);
this.statusNote = statusNote;
ExceptionUtil.throwIfFalse(this.isValid(), new DomainException(INVALID_STATUS));
}

public void specifyLentType(LentType lentType) {
log.info("specifyLentType : {}", lentType);
this.lentType = lentType;
ExceptionUtil.throwIfFalse(this.isValid(), new DomainException(INVALID_STATUS));
}

public void writeTitle(String title) {
log.info("writeTitle : {}", title);
this.title = title;
ExceptionUtil.throwIfFalse(this.isValid(), new DomainException(INVALID_STATUS));
}

public void coordinateGrid(Grid grid) {
log.info("coordinateGrid : {}", grid);
this.grid = grid;
ExceptionUtil.throwIfFalse(this.isValid(), new DomainException(INVALID_STATUS));
}

public void writeMemo(String memo) {
log.info("writeMemo : {}", memo);
this.memo = memo;
ExceptionUtil.throwIfFalse(this.isValid(), new DomainException(INVALID_STATUS));
}
Expand All @@ -213,6 +224,7 @@ public int hashCode() {
* @param userCount 현재 사용자 수
*/
public void specifyStatusByUserCount(Integer userCount) {
log.info("specifyStatusByUserCount : {}", userCount);
if (this.status.equals(CabinetStatus.BROKEN)) {
throw new DomainException(INVALID_STATUS);
}
Expand All @@ -230,4 +242,4 @@ public void specifyStatusByUserCount(Integer userCount) {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public class CabinetOptionalFetcher {
/*-------------------------------------------FIND-------------------------------------------*/

public Cabinet findCabinet(Long cabinetId) {
log.info("Called findCabinet: {}", cabinetId);
log.debug("Called findCabinet: {}", cabinetId);
return cabinetRepository.findById(cabinetId).orElse(null);
}

public List<ActiveCabinetInfoEntities> findCabinetsActiveLentHistoriesByBuildingAndFloor(String building, Integer floor) {
log.info("Called findCabinetsActiveLentHistoriesByBuildingAndFloor: {}, {}", building, floor);
log.debug("Called findCabinetsActiveLentHistoriesByBuildingAndFloor: {}, {}", building, floor);
return cabinetRepository.findCabinetActiveLentHistoryUserListByBuildingAndFloor(building, floor).stream()
.map(result -> {
Cabinet cabinet = (Cabinet) result[0];
Expand All @@ -58,23 +58,23 @@ public List<ActiveCabinetInfoEntities> findCabinetsActiveLentHistoriesByBuilding
* @throws ServiceException 사물함을 찾을 수 없는 경우
*/
public Cabinet findLentCabinetByUserId(Long userId) {
log.info("Called findLentCabinetByUserId: {}", userId);
log.debug("Called findLentCabinetByUserId: {}", userId);
return cabinetRepository.findLentCabinetByUserId(userId).orElse(null);
}

public List<String> findAllBuildings() {
log.info("Called findAllBuildings");
log.debug("Called findAllBuildings");
return cabinetRepository.findAllBuildings();
}

public List<Integer> findAllFloorsByBuilding(String building) {
log.info("Called findAllFloorsByBuilding: {}", building);
log.debug("Called findAllFloorsByBuilding: {}", building);
return cabinetRepository.findAllFloorsByBuilding(building);
}

// deprecated
public List<String> findAllSectionsByBuildingAndFloor(String building, Integer floor) {
log.info("Called findAllSectionsByBuildingAndFloor: {}, {}", building, floor);
log.debug("Called findAllSectionsByBuildingAndFloor: {}, {}", building, floor);
return cabinetRepository.findAllSectionsByBuildingAndFloor(building, floor);
}

Expand All @@ -90,7 +90,7 @@ public List<String> findAllSectionsByBuildingAndFloor(String building, Integer f
* @throws ServiceException 사물함을 찾을 수 없는 경우
*/
public Cabinet getCabinetForUpdate(Long cabinetId) {
log.info("Called getCabinetForUpdate: {}", cabinetId);
log.debug("Called getCabinetForUpdate: {}", cabinetId);
return cabinetRepository.findByIdForUpdate(cabinetId)
.orElseThrow(() -> new ServiceException(ExceptionStatus.NOT_FOUND_CABINET));
}
Expand All @@ -103,7 +103,7 @@ public Cabinet getCabinetForUpdate(Long cabinetId) {
* @throws ServiceException 사물함을 찾을 수 없는 경우
*/
public Cabinet getCabinet(Long cabinetId) {
log.info("Called getCabinet: {}", cabinetId);
log.debug("Called getCabinet: {}", cabinetId);
return cabinetRepository.findById(cabinetId)
.orElseThrow(() -> new ServiceException(ExceptionStatus.NOT_FOUND_CABINET));
}
Expand All @@ -116,7 +116,7 @@ public Cabinet getCabinet(Long cabinetId) {
* @throws ServiceException 사물함을 찾을 수 없는 경우
*/
public Cabinet getLentCabinetByUserId(Long userId) {
log.info("Called getLentCabinetByUserId: {}", userId);
log.debug("Called getLentCabinetByUserId: {}", userId);
return cabinetRepository.findLentCabinetByUserId(userId)
.orElseThrow(() -> new ServiceException(ExceptionStatus.NOT_FOUND_CABINET));
}
Expand All @@ -129,7 +129,7 @@ public Cabinet getLentCabinetByUserId(Long userId) {
* @throws ServiceException 사물함을 찾을 수 없는 경우
*/
public Cabinet getClubCabinet(Long cabinetId) {
log.info("Called getClubCabinet: {}", cabinetId);
log.debug("Called getClubCabinet: {}", cabinetId);
Cabinet cabinet = getCabinet(cabinetId);
if (!cabinet.isLentType(LentType.CLUB)) {
throw new ServiceException(ExceptionStatus.NOT_FOUND_CABINET);
Expand All @@ -145,28 +145,28 @@ public Cabinet getClubCabinet(Long cabinetId) {
* @throws ServiceException 사물함을 찾을 수 없는 경우
*/
public Location getLocation(Long cabinetId) {
log.info("Called getLocation: {}", cabinetId);
log.debug("Called getLocation: {}", cabinetId);
return cabinetRepository.findLocationById(cabinetId)
.orElseThrow(() -> new ServiceException(ExceptionStatus.NOT_FOUND_CABINET));
}

public Page<Cabinet> findPaginationByLentType(LentType lentType, PageRequest pageable) {
log.info("Called findPaginationByLentType: {}", lentType);
log.debug("Called findPaginationByLentType: {}", lentType);
return cabinetRepository.findPaginationByLentType(lentType, pageable);
}

public Page<Cabinet> findPaginationByStatus(CabinetStatus status, PageRequest pageable) {
log.info("Called findPaginationByStatus: {}", status);
log.debug("Called findPaginationByStatus: {}", status);
return cabinetRepository.findPaginationByStatus(status, pageable);
}

public Page<Cabinet> findPaginationByVisibleNum(Integer visibleNum, PageRequest pageable) {
log.info("Called findPaginationByVisibleNum: {}", visibleNum);
log.debug("Called findPaginationByVisibleNum: {}", visibleNum);
return cabinetRepository.findPaginationByVisibleNum(visibleNum, pageable);
}

public List<Cabinet> findAllCabinetsByLocation(Location location) {
log.info("Called findAllCabinetsByLocation: {}", location);
log.debug("Called findAllCabinetsByLocation: {}", location);
return cabinetRepository.findAllCabinetsByLocation(location);
}

Expand Down
Loading

0 comments on commit 516d662

Please sign in to comment.