Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/admin tag #112

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.t3t.frontserver.category.adaptor;

import com.t3t.frontserver.category.client.CategoryApiClient;
import com.t3t.frontserver.category.response.CategoryTreeResponse;
import com.t3t.frontserver.common.exception.ApiDataFetchException;
import com.t3t.frontserver.model.response.BaseResponse;
import com.t3t.frontserver.util.FeignClientUtils;
import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

@Slf4j
@Component
@RequiredArgsConstructor
public class CategoryAdaptor {
private final CategoryApiClient categoryApiClient;

public List<CategoryTreeResponse> getCategoryTreeByDepth(Integer startDepth, Integer maxDepth) {
try {
ResponseEntity<BaseResponse<List<CategoryTreeResponse>>> response = categoryApiClient.getCategoryTreeByDepth(startDepth, maxDepth);
if (response.getStatusCode() == HttpStatus.OK) {
return Objects.requireNonNull(response.getBody()).getData();
}
return null;
} catch (FeignException e) {
log.error(e.getMessage());
throw new ApiDataFetchException(FeignClientUtils.getMessageFromFeignException(e));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.t3t.frontserver.category.client.CategoryApiClient;
import com.t3t.frontserver.category.response.CategoryTreeResponse;
import com.t3t.frontserver.category.service.CategoryService;
import com.t3t.frontserver.model.response.BaseResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

Expand All @@ -17,9 +19,17 @@
@Controller
public class CategoryController {
private final CategoryApiClient categoryApiClient;
private final CategoryService categoryService;

@GetMapping("/categories")
ResponseEntity<BaseResponse<List<CategoryTreeResponse>>> getCategoryTreeByDepth(@RequestParam Integer startDepth, @RequestParam Integer maxDepth) {
return categoryApiClient.getCategoryTreeByDepth(startDepth, maxDepth);
}

@GetMapping("/admin/categories")
public String getCategoryListAdmin(Model model) {
List<CategoryTreeResponse> categoryList = categoryService.getCategoryTreeByDepth(1, 2);
model.addAttribute("categoryList", categoryList);
return "admin/page/categoryList";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.t3t.frontserver.category.service;

import com.t3t.frontserver.category.adaptor.CategoryAdaptor;
import com.t3t.frontserver.category.response.CategoryTreeResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class CategoryService {
private final CategoryAdaptor categoryAdaptor;

public List<CategoryTreeResponse> getCategoryTreeByDepth(Integer startDepth, Integer maxDepth) {
return categoryAdaptor.getCategoryTreeByDepth(startDepth, maxDepth);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.t3t.frontserver.participant.adaptor;

import com.t3t.frontserver.common.exception.ApiDataFetchException;
import com.t3t.frontserver.model.response.BaseResponse;
import com.t3t.frontserver.model.response.PageResponse;
import com.t3t.frontserver.participant.client.ParticipantApiClient;
import com.t3t.frontserver.participant.dto.ParticipantDto;
import com.t3t.frontserver.util.FeignClientUtils;
import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Slf4j
@Component
@RequiredArgsConstructor
public class ParticipantAdaptor {
private final ParticipantApiClient participantApiClient;

public PageResponse<ParticipantDto> getParticipantList(int pageNo, int pageSize, String sortBy) {
try {
ResponseEntity<BaseResponse<PageResponse<ParticipantDto>>> response = participantApiClient.getParticipantList(pageNo, pageSize, sortBy);
if (response.getStatusCode() == HttpStatus.OK) {
return Objects.requireNonNull(response.getBody()).getData();
}
return null;
} catch (FeignException e) {
log.error(e.getMessage());
throw new ApiDataFetchException(FeignClientUtils.getMessageFromFeignException(e));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.t3t.frontserver.participant.adaptor;

import com.t3t.frontserver.common.exception.ApiDataFetchException;
import com.t3t.frontserver.model.response.BaseResponse;
import com.t3t.frontserver.model.response.PageResponse;
import com.t3t.frontserver.participant.client.ParticipantApiClient;
import com.t3t.frontserver.participant.dto.ParticipantRoleDto;
import com.t3t.frontserver.util.FeignClientUtils;
import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Slf4j
@Component
@RequiredArgsConstructor
public class ParticipantRoleAdaptor {
private final ParticipantApiClient participantApiClient;

public PageResponse<ParticipantRoleDto> getParticipantRoleList(int pageNo, int pageSize, String sortBy) {
try {
ResponseEntity<BaseResponse<PageResponse<ParticipantRoleDto>>> response = participantApiClient.getParticipantRoleList(pageNo, pageSize, sortBy);
if (response.getStatusCode() == HttpStatus.OK) {
return Objects.requireNonNull(response.getBody()).getData();
}
return null;
} catch (FeignException e) {
log.error(e.getMessage());
throw new ApiDataFetchException(FeignClientUtils.getMessageFromFeignException(e));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.t3t.frontserver.participant.client.ParticipantApiClient;
import com.t3t.frontserver.participant.dto.ParticipantDto;
import com.t3t.frontserver.participant.dto.ParticipantRoleDto;
import com.t3t.frontserver.participant.service.ParticipantService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

Expand All @@ -17,6 +19,7 @@
@Controller
public class ParticipantController {
private final ParticipantApiClient participantApiClient;
private final ParticipantService participantService;

@GetMapping("/participants")
ResponseEntity<BaseResponse<PageResponse<ParticipantDto>>> getParticipantList(
Expand All @@ -35,4 +38,26 @@ ResponseEntity<BaseResponse<PageResponse<ParticipantRoleDto>>> getParticipantRol

return participantApiClient.getParticipantRoleList(pageNo, pageSize, sortBy);
}

@GetMapping("/admin/participants")
public String getParticipantListAdmin(Model model,
@RequestParam(value = "pageNo", defaultValue = "0", required = false) int pageNo,
@RequestParam(value = "pageSize", defaultValue = "10", required = false) int pageSize,
@RequestParam(value = "sortBy", defaultValue = "participantId", required = false) String sortBy) {

PageResponse<ParticipantDto> participantList = participantService.getParticipantList(pageNo, 20, sortBy);

if (participantList != null) {
int blockLimit = 5; // 현재 페이지 앞뒤로 보여줄 개수 설정
int nowPage = participantList.getPageNo() + 1;
int startPage = Math.max(nowPage - blockLimit, 1);
int endPage = Math.min(nowPage + blockLimit, participantList.getTotalPages());

model.addAttribute("nowPage", nowPage);
model.addAttribute("startPage", startPage);
model.addAttribute("endPage", endPage);
model.addAttribute("participantList", participantList.getContent());
}
return "admin/page/participantList";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.t3t.frontserver.participant.controller;

import com.t3t.frontserver.book.model.dto.PublisherDto;
import com.t3t.frontserver.model.response.PageResponse;
import com.t3t.frontserver.participant.dto.ParticipantRoleDto;
import com.t3t.frontserver.participant.service.ParticipantRoleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Slf4j
@RequiredArgsConstructor
@Controller
public class ParticipantRoleController {
private final ParticipantRoleService participantRoleService;

@GetMapping("/admin/participantRoles")
public String getParticipantRoleListAdmin(Model model,
@RequestParam(value = "pageNo", defaultValue = "0", required = false) int pageNo,
@RequestParam(value = "pageSize", defaultValue = "10", required = false) int pageSize,
@RequestParam(value = "sortBy", defaultValue = "participantRoleId", required = false) String sortBy) {

PageResponse<ParticipantRoleDto> participantRoleList = participantRoleService.getParticipantRoleList(pageNo, 20, sortBy);

if (participantRoleList != null) {
int blockLimit = 5; // 현재 페이지 앞뒤로 보여줄 개수 설정
int nowPage = participantRoleList.getPageNo() + 1;
int startPage = Math.max(nowPage - blockLimit, 1);
int endPage = Math.min(nowPage + blockLimit, participantRoleList.getTotalPages());

model.addAttribute("nowPage", nowPage);
model.addAttribute("startPage", startPage);
model.addAttribute("endPage", endPage);
model.addAttribute("participantRoleList", participantRoleList.getContent());
}
return "admin/page/participantRoleList";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.t3t.frontserver.participant.service;

import com.t3t.frontserver.model.response.PageResponse;
import com.t3t.frontserver.participant.adaptor.ParticipantRoleAdaptor;
import com.t3t.frontserver.participant.dto.ParticipantRoleDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ParticipantRoleService {
private final ParticipantRoleAdaptor participantRoleAdaptor;

public PageResponse<ParticipantRoleDto> getParticipantRoleList(int pageNo, int pageSize, String sortBy) {
return participantRoleAdaptor.getParticipantRoleList(pageNo, pageSize, sortBy);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.t3t.frontserver.participant.service;

import com.t3t.frontserver.model.response.PageResponse;
import com.t3t.frontserver.participant.adaptor.ParticipantAdaptor;
import com.t3t.frontserver.participant.dto.ParticipantDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ParticipantService {
private final ParticipantAdaptor participantAdaptor;

public PageResponse<ParticipantDto> getParticipantList(int pageNo, int pageSize, String sortBy) {
return participantAdaptor.getParticipantList(pageNo, pageSize, sortBy);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.t3t.frontserver.publishers.adaptor;

import com.t3t.frontserver.book.model.dto.PublisherDto;
import com.t3t.frontserver.common.exception.ApiDataFetchException;
import com.t3t.frontserver.model.response.BaseResponse;
import com.t3t.frontserver.model.response.PageResponse;
import com.t3t.frontserver.publishers.client.PublisherApiClient;
import com.t3t.frontserver.util.FeignClientUtils;
import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Slf4j
@Component
@RequiredArgsConstructor
public class PublisherAdaptor {
private final PublisherApiClient publisherApiClient;

public PageResponse<PublisherDto> getPublisherList(int pageNo, int pageSize, String sortBy) {
try {
ResponseEntity<BaseResponse<PageResponse<PublisherDto>>> response = publisherApiClient.getPublisherList(pageNo, pageSize, sortBy);
if (response.getStatusCode() == HttpStatus.OK) {
return Objects.requireNonNull(response.getBody()).getData();
}
return null;
} catch (FeignException e) {
log.error(e.getMessage());
throw new ApiDataFetchException(FeignClientUtils.getMessageFromFeignException(e));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import com.t3t.frontserver.model.response.BaseResponse;
import com.t3t.frontserver.model.response.PageResponse;
import com.t3t.frontserver.publishers.client.PublisherApiClient;
import com.t3t.frontserver.publishers.service.PublisherService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

Expand All @@ -17,6 +19,7 @@
public class PublisherController {

private final PublisherApiClient publisherApiClient;
private final PublisherService publisherService;

@GetMapping("/publishers")
public ResponseEntity<BaseResponse<PageResponse<PublisherDto>>> getPublisherList(
Expand All @@ -26,4 +29,26 @@ public ResponseEntity<BaseResponse<PageResponse<PublisherDto>>> getPublisherList

return publisherApiClient.getPublisherList(pageNo, pageSize, sortBy);
}

@GetMapping("/admin/publishers")
public String getPublisherListAdmin(Model model,
@RequestParam(value = "pageNo", defaultValue = "0", required = false) int pageNo,
@RequestParam(value = "pageSize", defaultValue = "10", required = false) int pageSize,
@RequestParam(value = "sortBy", defaultValue = "publisherId", required = false) String sortBy) {

PageResponse<PublisherDto> publisherList = publisherService.getPublisherList(pageNo, 20, sortBy);

if (publisherList != null) {
int blockLimit = 5; // 현재 페이지 앞뒤로 보여줄 개수 설정
int nowPage = publisherList.getPageNo() + 1;
int startPage = Math.max(nowPage - blockLimit, 1);
int endPage = Math.min(nowPage + blockLimit, publisherList.getTotalPages());

model.addAttribute("nowPage", nowPage);
model.addAttribute("startPage", startPage);
model.addAttribute("endPage", endPage);
model.addAttribute("publisherList", publisherList.getContent());
}
return "admin/page/publisherList";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.t3t.frontserver.publishers.service;

import com.t3t.frontserver.book.model.dto.PublisherDto;
import com.t3t.frontserver.model.response.PageResponse;
import com.t3t.frontserver.publishers.adaptor.PublisherAdaptor;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class PublisherService {
private final PublisherAdaptor publisherAdaptor;

public PageResponse<PublisherDto> getPublisherList(int pageNo, int pageSize, String sortBy) {
return publisherAdaptor.getPublisherList(pageNo, pageSize, sortBy);
}
}
Loading
Loading