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/#73 [FE] 관리자페이지 구현 #91

Merged
merged 17 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Expand Up @@ -23,7 +23,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/categories")
@RequestMapping("/api/admin/categories")
public class CategoryController {

private final CategoryService categoryService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import java.time.LocalDateTime;

import com.programmers.pcquotation.domain.customer.entity.Customer;
import jakarta.persistence.*;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import com.programmers.pcquotation.domain.item.service.ImageService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/image")
Expand All @@ -23,6 +25,7 @@ public class ImageController {
@GetMapping("/{filename}")
public Resource getImage(
@PathVariable String filename) {
log.info("Fetching image with filename: {}", filename); // 로그 추가

return imageService.getImageByFilename(filename);
}
Expand All @@ -33,7 +36,7 @@ public ResponseEntity<Resource> getImageFileName(@PathVariable String filename)
// 이미지 Resource 가져오기
Resource resource = imageService.getImageByFilename(filename);
return ResponseEntity.ok()
.contentType(MediaType.IMAGE_PNG) // 또는 적절한 미디어 타입
.contentType(MediaType.IMAGE_JPEG) // 또는 적절한 미디어 타입
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + filename + "\"")
.body(resource);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/items")
@RequestMapping("/api/admin/items")

public class ItemController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public ImageService(
* @return Product Image Resource
*/
public Resource getImageByFilename(String filename) {
log.info("Requested filename: {}", filename);
if (filename == null || filename.isEmpty() || checkInvalidExt(filename)) {
throw new InvalidImageRequestException("Invalid Type Filename");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,37 @@ public List<ItemInfoResponse> getItemList() {
return items.stream()
.map(item -> new ItemInfoResponse(
item.getId(),
item.getCategory().getCategory(),
item.getCategory().getId(),
item.getName(),
item.getImgFilename()
item.getName(), // 부품 이름 (name)
item.getCategory().getId(), // 카테고리 ID
item.getCategory().getCategory(), // 카테고리 이름 (categoryName)
item.getImgFilename() // 이미지 파일명
))
.collect(Collectors.toList());
}

//부품 수정
@Transactional
public ItemUpdateResponse updateItem(Long id, ItemUpdateRequest request) {

Item item = itemRepository.findById(id)
.orElseThrow(() -> new ItemNotFoundException(id));

Category category = categoryRepository.findById(request.categoryId())
.orElseThrow(() -> new IllegalArgumentException("유효하지 않은 카테고리 ID입니다."));

String imgFilename = request.imgFilename();

// imgFilename이 null이거나 비어있다면 기존의 filename을 사용
if (imgFilename == null || imgFilename.isEmpty()) {
imgFilename = item.getImgFilename(); // 기존 이미지 파일 이름을 가져옴
}

item.updateItem(
request.name(),
request.imgFilename(),
imgFilename,
category
);

return new ItemUpdateResponse(id, "부품 수정 완료");

}

//부품 삭제
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public class SecurityConfig {
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(authorizeRequests ->
authorizeRequests
.requestMatchers(HttpMethod.GET, "/seller/api/**")
.hasRole("SELLER")
.requestMatchers(HttpMethod.GET, "/seller")
.requestMatchers(HttpMethod.GET, "/sellers")
.hasRole("SELLER")
.anyRequest()
.permitAll()
Expand Down
Loading