Skip to content

Commit

Permalink
[api-server-v1] feat: Controller - Log 포맷 공통 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
gdtknight committed Oct 5, 2023
1 parent 0df5fa5 commit c03618c
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kr.joberchip.server.v1.block.controller;

import java.util.UUID;

import kr.joberchip.server.v1._config.security.CustomUserDetails;
import kr.joberchip.server.v1._utils.ApiResponse;
import kr.joberchip.server.v1.block.controller.dto.BlockResponseDTO;
Expand All @@ -10,7 +9,6 @@
import kr.joberchip.server.v1.page.service.SharePagePrivilegeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

Expand All @@ -23,39 +21,54 @@ public class ImageBlockController {
private final SharePagePrivilegeService sharePagePrivilegeService;

@PostMapping
public ResponseEntity<ApiResponse.Result<BlockResponseDTO>> createImageBlock(
@AuthenticationPrincipal CustomUserDetails loginUser,
@PathVariable UUID pageId,
@RequestBody ImageBlockDTO imageBlockDTO) {
public ApiResponse.Result<BlockResponseDTO> createImageBlock(
@AuthenticationPrincipal CustomUserDetails loginUser,
@PathVariable UUID pageId,
@RequestBody ImageBlockDTO imageBlockDTO) {

log.info("[ImageBlockController][POST] Current Username : {}", loginUser.user().getUsername());
log.info("[ImageBlockController][POST] Current Page Id : {}", pageId);
log.info("[ImageBlockController][POST] {}", imageBlockDTO);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

BlockResponseDTO response = imageBlockService.createImageBlock(pageId, imageBlockDTO);

return ResponseEntity.ok(ApiResponse.success(response));
return ApiResponse.success(response);
}

@PutMapping("/{blockId}")
public ResponseEntity<ApiResponse.Result<BlockResponseDTO>> modifyImageBlock(
@AuthenticationPrincipal CustomUserDetails loginUser,
@PathVariable UUID pageId,
@PathVariable UUID blockId,
@RequestBody ImageBlockDTO imageBlockDTO) {
public ApiResponse.Result<BlockResponseDTO> modifyImageBlock(
@AuthenticationPrincipal CustomUserDetails loginUser,
@PathVariable UUID pageId,
@PathVariable UUID blockId,
@RequestBody ImageBlockDTO imageBlockDTO) {

log.info("[ImageBlockController][PUT] Current Username : {}", loginUser.user().getUsername());
log.info("[ImageBlockController][PUT] Current Page Id : {}", pageId);
log.info("[ImageBlockController][PUT] Target Block Id : {}", blockId);
log.info("[ImageBlockController][PUT] {}", imageBlockDTO);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);
BlockResponseDTO response = imageBlockService.modifyImageBlock(pageId, blockId, imageBlockDTO);

return ResponseEntity.ok(ApiResponse.success(response));
BlockResponseDTO response = imageBlockService.modifyImageBlock(blockId, imageBlockDTO);

return ApiResponse.success(response);
}

@DeleteMapping("/{blockId}")
public ResponseEntity<ApiResponse.Result<Object>> deleteImageBlock(
@AuthenticationPrincipal CustomUserDetails loginUser,
@PathVariable UUID pageId,
@PathVariable UUID blockId) {
public ApiResponse.Result<Object> deleteImageBlock(
@AuthenticationPrincipal CustomUserDetails loginUser,
@PathVariable UUID pageId,
@PathVariable UUID blockId) {

log.info("[ImageBlockController][DELETE] Current Username : {}", loginUser.user().getUsername());
log.info("[ImageBlockController][DELETE] Current Page Id : {}", pageId);
log.info("[ImageBlockController][DELETE] Target Block Id : {}", blockId);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);
imageBlockService.deleteImageBlock(pageId, blockId);

return ResponseEntity.ok(ApiResponse.success());
return ApiResponse.success();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package kr.joberchip.server.v1.block.controller;

import java.util.UUID;
import kr.joberchip.server.v1._config.security.CustomUserDetails;
import kr.joberchip.server.v1._utils.ApiResponse;
import kr.joberchip.server.v1.block.controller.dto.BlockResponseDTO;
import kr.joberchip.server.v1.block.controller.dto.LinkBlockDTO;
import kr.joberchip.server.v1.block.service.LinkBlockService;
import kr.joberchip.server.v1.page.service.SharePagePrivilegeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@Slf4j
Expand All @@ -16,33 +18,57 @@
@RequestMapping("/v1/page/{pageId}/linkBlock")
public class LinkBlockController {
private final LinkBlockService linkBlockService;
private final SharePagePrivilegeService sharePagePrivilegeService;

@PostMapping
public ResponseEntity<ApiResponse.Result<Object>> createLinkBlock(
@PathVariable UUID pageId, @RequestBody LinkBlockDTO createLinkBlock) {
public ApiResponse.Result<BlockResponseDTO> createLinkBlock(
@AuthenticationPrincipal CustomUserDetails loginUser,
@PathVariable UUID pageId,
@RequestBody LinkBlockDTO linkBlockDTO) {

log.info("[LinkBlockController][POST] Current Username : {}", loginUser.user().getUsername());
log.info("[LinkBlockController][POST] Current Page Id : {}", pageId);
log.info("[LinkBlockController][POST] {}", linkBlockDTO);

BlockResponseDTO responseDTO = linkBlockService.createLinkBlock(pageId, createLinkBlock);
sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

return ResponseEntity.ok(ApiResponse.success(responseDTO));
BlockResponseDTO response = linkBlockService.createLinkBlock(pageId, linkBlockDTO);

return ApiResponse.success(response);
}

@PutMapping("/{blockId}")
public ResponseEntity<ApiResponse.Result<Object>> modifyLinkBlock(
public ApiResponse.Result<Object> modifyLinkBlock(
@AuthenticationPrincipal CustomUserDetails loginUser,
@PathVariable UUID pageId,
@PathVariable UUID blockId,
@RequestBody LinkBlockDTO modifyRequestDTO) {
@RequestBody LinkBlockDTO linkBlockDTO) {

log.info("[LinkBlockController][PUT] Current Username : {}", loginUser.user().getUsername());
log.info("[LinkBlockController][PUT] Current Page Id : {}", pageId);
log.info("[LinkBlockController][PUT] Target Block Id : {}", blockId);
log.info("[LinkBlockController][PUT] {}", linkBlockDTO);

BlockResponseDTO responseDTO = linkBlockService.modifyLinkBlock(pageId, blockId, modifyRequestDTO);
sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

return ResponseEntity.ok(ApiResponse.success(responseDTO));
BlockResponseDTO responseDTO = linkBlockService.modifyLinkBlock(blockId, linkBlockDTO);

return ApiResponse.success(responseDTO);
}

@DeleteMapping("/{blockId}")
public ResponseEntity<ApiResponse.Result<Object>> deleteLinkBlock(
@PathVariable UUID pageId, @PathVariable UUID blockId) {
public ApiResponse.Result<Object> deleteLinkBlock(
@AuthenticationPrincipal CustomUserDetails loginUser,
@PathVariable UUID pageId,
@PathVariable UUID blockId) {

log.info("[LinkBlockController][DELETE] Current Username : {}", loginUser.user().getUsername());
log.info("[LinkBlockController][DELETE] Current Page Id : {}", pageId);
log.info("[LinkBlockController][DELETE] Target Block Id : {}", blockId);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);
linkBlockService.deleteLinkBlock(pageId, blockId);

return ResponseEntity.ok(ApiResponse.success());
return ApiResponse.success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public ApiResponse.Result<Object> createMapBlock(
@PathVariable UUID pageId,
@RequestBody @Valid MapBlockDTO.Create newMapBlock,
Errors errors) {

log.info("[MapBlockController][POST] Current Username : {}", loginUser.user().getUsername());
log.info("[MapBlockController][POST] Current Page Id : {}", pageId);
log.info("[MapBlockController][POST] {}", newMapBlock);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);
BlockResponseDTO response = mapBlockService.createMapBlock(pageId, newMapBlock);
return ApiResponse.success(response);
Expand All @@ -40,8 +45,16 @@ public ApiResponse.Result<BlockResponseDTO> modifyMapBlock(
@PathVariable UUID pageId,
@PathVariable UUID blockId,
@RequestBody MapBlockDTO.Modify modifiedMapBlock) {

log.info("[MapBlockController][PUT] Current Username : {}", loginUser.user().getUsername());
log.info("[MapBlockController][PUT] Current Page Id : {}", pageId);
log.info("[MapBlockController][PUT] Target Block Id : {}", blockId);
log.info("[MapBlockController][PUT] {}", modifiedMapBlock);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

BlockResponseDTO response = mapBlockService.modifyMapBlock(pageId, blockId, modifiedMapBlock);

return ApiResponse.success(response);
}

Expand All @@ -50,6 +63,11 @@ public ApiResponse.Result<Object> deleteMapBlock(
@AuthenticationPrincipal CustomUserDetails loginUser,
@PathVariable UUID pageId,
@PathVariable UUID blockId) {

log.info("[MapBlockController][DELETE] Current Username : {}", loginUser.user().getUsername());
log.info("[MapBlockController][DELETE] Current Page Id : {}", pageId);
log.info("[MapBlockController][DELETE] Target Block Id : {}", blockId);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);
mapBlockService.deleteMapBlock(pageId, blockId);
return ApiResponse.success();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package kr.joberchip.server.v1.block.controller;

import java.util.UUID;

import kr.joberchip.core.page.types.PrivilegeType;
import kr.joberchip.server.v1._config.security.CustomUserDetails;
import kr.joberchip.server.v1._utils.ApiResponse;
import kr.joberchip.server.v1.block.controller.dto.BlockResponseDTO;
Expand All @@ -11,7 +9,6 @@
import kr.joberchip.server.v1.page.service.SharePagePrivilegeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

Expand All @@ -24,19 +21,20 @@ public class TemplateBlockController {
private final SharePagePrivilegeService sharePagePrivilegeService;

@PostMapping
public ResponseEntity<ApiResponse.Result<Object>> createTemplateBlock(
public ApiResponse.Result<Object> createTemplateBlock(
@AuthenticationPrincipal CustomUserDetails loginUser,
@PathVariable UUID pageId,
@RequestBody TemplateBlockDTO templateBlockDTO) {
log.info("[TemplateBlockController] Page Id : {}", pageId);
log.info("[TemplateBlockController] TemplateBlockDTO : {}", templateBlockDTO);

log.info("[TemplateBlockController][POST] Current Username : {}", loginUser.user().getUsername());
log.info("[TemplateBlockController][POST] Current Page Id : {}", pageId);
log.info("[TemplateBlockController][POST] {}", templateBlockDTO);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

templateBlockService.createTemplateBlock(
loginUser.user().getUserId(), pageId, templateBlockDTO);
BlockResponseDTO response = templateBlockService.createTemplateBlock(pageId, templateBlockDTO);

return ResponseEntity.ok(ApiResponse.success());
return ApiResponse.success(response);
}

@PutMapping("/{blockId}")
Expand All @@ -46,16 +44,14 @@ public ApiResponse.Result<BlockResponseDTO> modifyTemplateBlock(
@PathVariable UUID blockId,
@RequestBody TemplateBlockDTO templateBlockDTO) {

log.info("[TemplateBlockController] Login User : {}", loginUser.user());
log.info("[TemplateBlockController] Page Id : {}", pageId);
log.info("[TemplateBlockController] Template Block Id : {}", blockId);
log.info("[TemplateBlockController] TemplateBlockDTO : {}", templateBlockDTO);
log.info("[TemplateBlockController][PUT] Current Username : {}", loginUser.user().getUsername());
log.info("[TemplateBlockController][PUT] Current Page Id : {}", pageId);
log.info("[TemplateBlockController][PUT] Target Block Id : {}", blockId);
log.info("[TemplateBlockController][PUT] {}", templateBlockDTO);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

BlockResponseDTO response =
templateBlockService.modifyTemplateBlock(
loginUser.user().getUserId(), pageId, blockId, templateBlockDTO);
BlockResponseDTO response = templateBlockService.modifyTemplateBlock(blockId, templateBlockDTO);

return ApiResponse.success(response);
}
Expand All @@ -66,9 +62,9 @@ public ApiResponse.Result<Object> deleteTemplateBlock(
@PathVariable UUID pageId,
@PathVariable UUID blockId) {

log.info("[TemplateBlockController] Login User : {}", loginUser.user());
log.info("[TemplateBlockController] Page Id : {}", pageId);
log.info("[TemplateBlockController] Template Block Id : {}", blockId);
log.info("[TemplateBlockController][DELETE] Current Username : {}", loginUser.user().getUsername());
log.info("[TemplateBlockController][DELETE] Current Page Id : {}", pageId);
log.info("[TemplateBlockController][DELETE] Target Block Id : {}", blockId);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public ApiResponse.Result<BlockResponseDTO> createTextBlock(
@AuthenticationPrincipal CustomUserDetails loginUser,
@PathVariable UUID pageId,
@RequestBody TextBlockDTO textBlockDTO) {
log.info("[TextBlockController] Login User : {}", loginUser);
log.info("[TextBlockController] Current Page Id : {}", pageId);

log.info("[TextBlockController][POST] Current Username : {}", loginUser.user().getUsername());
log.info("[TextBlockController][POST] Current Page Id : {}", pageId);
log.info("[TextBlockController][POST] {}", textBlockDTO);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

Expand All @@ -43,8 +45,10 @@ public ApiResponse.Result<BlockResponseDTO> modifyTextBlock(
@PathVariable UUID blockId,
@RequestBody TextBlockDTO textBlockDTO) {

log.info("[TextBlockController] Login User : {}", loginUser);
log.info("[TextBlockController] Current Page Id : {}", pageId);
log.info("[TextBlockController][PUT] Current Username : {}", loginUser.user().getUsername());
log.info("[TextBlockController][PUT] Current Page Id : {}", pageId);
log.info("[TextBlockController][PUT] Target Block Id : {}", blockId);
log.info("[TextBlockController][PUT] {}", textBlockDTO);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

Expand All @@ -59,8 +63,9 @@ public ApiResponse.Result<Object> deleteTextBlock(
@PathVariable UUID pageId,
@PathVariable UUID blockId) {

log.info("[TextBlockController] Login User : {}", loginUser);
log.info("[TextBlockController] Current Page Id : {}", pageId);
log.info("[TextBlockController][DELETE] Current Username : {}", loginUser.user().getUsername());
log.info("[TextBlockController][DELETE] Current Page Id : {}", pageId);
log.info("[TextBlockController][DELETE] Target Block Id : {}", blockId);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public ApiResponse.Result<BlockResponseDTO> createVideoBlock(
@PathVariable UUID pageId,
VideoBlockDTO videoBlockRequestDTO) {

log.info("[TextBlockController] Login User : {}", loginUser);
log.info("[TextBlockController] Current Page Id : {}", pageId);
log.info("[VideoBlockController][POST] Current Username : {}", loginUser.user().getUsername());
log.info("[VideoBlockController][POST] Current Page Id : {}", pageId);
log.info("[VideoBlockController][POST] {}", videoBlockRequestDTO);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

Expand All @@ -44,8 +45,10 @@ public ApiResponse.Result<BlockResponseDTO> modifyVideoBlock(
@PathVariable UUID blockId,
VideoBlockDTO videoBlockRequestDTO) {

log.info("[TextBlockController] Login User : {}", loginUser);
log.info("[TextBlockController] Current Page Id : {}", pageId);
log.info("[VideoBlockController][PUT] Current Username : {}", loginUser.user().getUsername());
log.info("[VideoBlockController][PUT] Current Page Id : {}", pageId);
log.info("[VideoBlockController][PUT] Target Block Id : {}", blockId);
log.info("[VideoBlockController][PUT] {}", videoBlockRequestDTO);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

Expand All @@ -60,8 +63,9 @@ public ApiResponse.Result<Object> deleteVideoBlock(
@PathVariable UUID pageId,
@PathVariable UUID blockId) {

log.info("[TextBlockController] Login User : {}", loginUser);
log.info("[TextBlockController] Current Page Id : {}", pageId);
log.info("[VideoBlockController][DELETE] Current Username : {}", loginUser.user().getUsername());
log.info("[VideoBlockController][DELETE] Current Page Id : {}", pageId);
log.info("[VideoBlockController][DELETE] Target Block Id : {}", blockId);

sharePagePrivilegeService.checkEditPrivilege(loginUser.user().getUserId(), pageId);

Expand Down

0 comments on commit c03618c

Please sign in to comment.