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

경북대 BE_김영인 6주차 과제(1단계) #143

Open
wants to merge 28 commits into
base: youngini
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
199525a
feat: setup the project
Youngini Jul 29, 2024
cd6fec9
feat : merge the project
Youngini Jul 29, 2024
6748dfc
docs(README.md) : API 명세서 수정 사항 점검 리스트
Youngini Jul 31, 2024
62b5448
feat(Member) : 일반 회원가입 로직 확인
Youngini Jul 31, 2024
0096f76
feat(Member) : 일반 로그인 로직 확인
Youngini Jul 31, 2024
c3fb376
feat(Product) : 제품 옵션 조회
Youngini Jul 31, 2024
597895b
feat(Product) : 특정 제품의 옵션 조회
Youngini Jul 31, 2024
6363d39
feat(Product) : 특정 카테고리별 상품 목록 조회
Youngini Jul 31, 2024
2e76903
feat(Category) : 모든 카테고리 조회
Youngini Jul 31, 2024
5d6dbed
feat(wish) : 위시 리스트에 추가
Youngini Jul 31, 2024
0ef82ad
feat(wish) : 위시 리스트에서 삭제
Youngini Jul 31, 2024
f5152fb
feat(wish) : 위시 리스트 목록 반환
Youngini Jul 31, 2024
5825161
feat(Order) : 주문 생성
Youngini Jul 31, 2024
2e270c5
refactor : 실행 시 발생하는 오류 수정
Youngini Jul 31, 2024
974ee7a
feat(WebConfig) : Swagger 사용 시 발생하는 HttpMediaTypeNotAcceptableExcepti…
Youngini Jul 31, 2024
55fa3ac
refactor(JoinResponse) : 회원가입 시, 응답 용어 수정
Youngini Jul 31, 2024
f835073
refactor(Order) : 주문생성시, Request와 Response 용어 api 명세서와 일치시킴
Youngini Jul 31, 2024
5fd2840
refactor(Category) :카테고리 목록의, Request와 Response 용어 api 명세서와 일치시킴
Youngini Jul 31, 2024
71432fd
refactor(Product) : Product API의, Request와 Response 용어 api 명세서와 일치시킴
Youngini Jul 31, 2024
38e745e
refactor(Order) : Order API의, Request와 Response 용어 api 명세서와 일치시킴
Youngini Jul 31, 2024
51f5d20
refactor(wish) : wish API의, Request와 Response 용어 api 명세서와 일치시킴
Youngini Jul 31, 2024
3d71aa0
refactor(Member) : 생성자 만듦
Youngini Jul 31, 2024
471460d
refactor(Member) : Json 인식 못하는 문제 해결
Youngini Jul 31, 2024
bff484a
refactor(JwtConfig) : token 생성 오류 해결
Youngini Jul 31, 2024
e61f013
fwat(JwtConfig) : token으로 email 추출
Youngini Jul 31, 2024
3dea571
feat(Entity) : 생성자 만듦
Youngini Jul 31, 2024
f2d5530
build(application.properties) : 디비 실행되도 생성이아니라 업데이트가 되도록 수정
Youngini Jul 31, 2024
ca67821
refactor(Controller) : Pageable 객체 인수를 size, page로 변경
Youngini Jul 31, 2024
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ out/

### Mac OS ###
.DS_Store

### secret-key 설정
src/main/resources/application-secret.properties
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
# spring-gift-point
# spring-gift-point

# 0단계

## API 명세서
https://impossible-repair-22e.notion.site/57ec013f9424421eb2317b11a2b9a29c?v=f3fe7340ebae425bbfa70db78123a663

# 1단계

## 구현할 기능 목록
- [ ] 작성한 API 문서를 기반으로 팀 내에서 지금까지 만든 API를 검토하고 통일하여 변경 사항을 반영
- [x] 일반 회원가입
- [x] 일반 로그인
- [x] 모든 상품 조회
- [x] 특정 제품의 옵션 조회
- [x] 특정 카테고리별 상품 목록조회
- [x] 모든 카테고리 조회
- [x] 위시리스트에 추가
- [x] 위시리스트에서 삭제
- [x] 로그인한 회원의 위시리스트 조회
- [x] 주문 생성

팀 내에서 일관된 기준을 정하여 API 명세를 결정한다.
때로는 클라이언트의 편의를 위해 API 명세를 결정하는 것이 좋다.
18 changes: 18 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ dependencies {
runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springframework.boot:spring-boot-starter-validation:2.7.3'

// JWT 관련 의존성
compileOnly 'io.jsonwebtoken:jjwt-api:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2'

// JPA
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

// 보안 관련 의존성
//implementation 'org.springframework.boot:spring-boot-starter-security'
//implementation 'org.springframework.security:spring-security-test'

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'

// Json
implementation group: 'org.json', name: 'json', version: '20090211'
}

tasks.named('test') {
Expand Down
Binary file added data/test.mv.db
Binary file not shown.
152 changes: 152 additions & 0 deletions data/test.trace.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
2024-08-01 04:48:27.040702+09:00 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "IMAGEURL" not found; SQL statement:
-- Product 테이블에 더미 데이터 삽입
INSERT INTO product (name, price, imageUrl, category_id) VALUES
('Smartphone', 699, 'http://example.com/smartphone.jpg', 1),
('Laptop', 999, 'http://example.com/laptop.jpg', 1),
('T-Shirt', 19, 'http://example.com/tshirt.jpg', 2),
('Coffee Maker', 49, 'http://example.com/coffeemaker.jpg', 3) [42122-224]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:514)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
at org.h2.message.DbException.get(DbException.java:223)
at org.h2.message.DbException.get(DbException.java:199)
at org.h2.table.Table.getColumn(Table.java:759)
at org.h2.command.Parser.parseColumn(Parser.java:1190)
at org.h2.command.Parser.parseColumnList(Parser.java:1175)
at org.h2.command.Parser.parseInsert(Parser.java:1549)
at org.h2.command.Parser.parsePrepared(Parser.java:719)
at org.h2.command.Parser.parse(Parser.java:592)
at org.h2.command.Parser.parse(Parser.java:564)
at org.h2.command.Parser.prepareCommand(Parser.java:483)
at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:639)
at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:559)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1166)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:245)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:231)
at org.h2.server.web.WebApp.getResult(WebApp.java:1345)
at org.h2.server.web.WebApp.query(WebApp.java:1143)
at org.h2.server.web.WebApp.query(WebApp.java:1119)
at org.h2.server.web.WebApp.process(WebApp.java:245)
at org.h2.server.web.WebApp.processRequest(WebApp.java:177)
at org.h2.server.web.JakartaWebServlet.doGet(JakartaWebServlet.java:129)
at org.h2.server.web.JakartaWebServlet.doPost(JakartaWebServlet.java:166)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
Comment on lines +8 to +46

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 trace는 디버깅 하실떄 사용하는 값이라 PR에 첨부하지 않도록 ignore 처리하는게 어떨까요?

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:389)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:904)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:1583)
2024-08-01 04:49:22.693481+09:00 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "IMAGEURL" not found; SQL statement:
-- Product 테이블에 더미 데이터 삽입
INSERT INTO product (name, price, imageUrl, category_id) VALUES
('Smartphone', 699, 'http://example.com/smartphone.jpg', 1),
('Laptop', 999, 'http://example.com/laptop.jpg', 1),
('T-Shirt', 19, 'http://example.com/tshirt.jpg', 2),
('Coffee Maker', 49, 'http://example.com/coffeemaker.jpg', 3) [42122-224]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:514)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:489)
at org.h2.message.DbException.get(DbException.java:223)
at org.h2.message.DbException.get(DbException.java:199)
at org.h2.table.Table.getColumn(Table.java:759)
at org.h2.command.Parser.parseColumn(Parser.java:1190)
at org.h2.command.Parser.parseColumnList(Parser.java:1175)
at org.h2.command.Parser.parseInsert(Parser.java:1549)
at org.h2.command.Parser.parsePrepared(Parser.java:719)
at org.h2.command.Parser.parse(Parser.java:592)
at org.h2.command.Parser.parse(Parser.java:564)
at org.h2.command.Parser.prepareCommand(Parser.java:483)
at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:639)
at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:559)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1166)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:245)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:231)
at org.h2.server.web.WebApp.getResult(WebApp.java:1345)
at org.h2.server.web.WebApp.query(WebApp.java:1143)
at org.h2.server.web.WebApp.query(WebApp.java:1119)
at org.h2.server.web.WebApp.process(WebApp.java:245)
at org.h2.server.web.WebApp.processRequest(WebApp.java:177)
at org.h2.server.web.JakartaWebServlet.doGet(JakartaWebServlet.java:129)
at org.h2.server.web.JakartaWebServlet.doPost(JakartaWebServlet.java:166)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:195)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:164)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:140)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:389)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:904)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1741)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1190)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:1583)
2024-08-01 04:49:58.801112+09:00 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "OPTIONS" not found; SQL statement:
-- Option 테이블에 더미 데이터 삽입
INSERT INTO options (name, quantity, id) VALUES
('64GB Storage', 100, 1), -- Smartphone
('128GB Storage', 50, 1), -- Smartphone
('16GB RAM', 20, 2), -- Laptop
('32GB RAM', 15, 2), -- Laptop
('Size M', 200, 3), -- T-Shirt
('Size L', 150, 3), -- T-Shirt
('Black', 75, 4), -- Coffee Maker
('White', 50, 4) [42102-224]
2024-08-01 04:49:58.805468+09:00 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "OPTIONS" not found; SQL statement:
select * from options [42102-224]
2024-08-01 04:50:16.036865+09:00 jdbc[13]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "OPTIONS" not found; SQL statement:
select * from options [42102-224]
5 changes: 4 additions & 1 deletion src/main/java/gift/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
new SpringApplicationBuilder(Application.class)
.properties("spring.config.location=classpath:/application.properties,classpath:/application-secret.properties")
.run(args);
}
}
51 changes: 51 additions & 0 deletions src/main/java/gift/config/JwtConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gift.config;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.security.Keys;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.stereotype.Component;
import gift.constant.Constants;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Component
public class JwtConfig {

public String generateToken(String email) {
// Create a claims map
Map<String, Object> claims = new HashMap<>();
claims.put("email", email);

// Generate the JWT token
return Jwts.builder()
.setClaims(claims)
.setSubject(email)
.setIssuedAt(new Date())
.setExpiration(new Date(System.currentTimeMillis() + Constants.ONE_DAY_MILLIS))
.signWith(Keys.hmacShaKeyFor(Constants.SECRET_KEY.getBytes()), SignatureAlgorithm.HS256)
.compact();
}

public String extractEmail(String token) {
return extractAllClaims(token).getSubject();
}

public Claims extractAllClaims(String token) {
return Jwts.parser()
.setSigningKey(Keys.hmacShaKeyFor(Constants.SECRET_KEY.getBytes()))
.parseClaimsJws(token)
.getBody();
}

public boolean validateToken(String token, String email) {
final String extractedEmail = extractEmail(token);
return extractedEmail.equals(email) && !isTokenExpired(token);
}

private boolean isTokenExpired(String token) {
return extractAllClaims(token).getExpiration().before(new Date());
}
}
46 changes: 46 additions & 0 deletions src/main/java/gift/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package gift.config;

import gift.resolver.LoginMemberArgumentResolver;
import gift.service.MemberService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {
private final MemberService memberService;

public WebConfig(MemberService memberService) {
this.memberService = memberService;
}

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(new LoginMemberArgumentResolver(memberService));
}

@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_JSON);
}

@Bean
public CharacterEncodingFilter characterEncodingFilter() {
CharacterEncodingFilter filter = new CharacterEncodingFilter();
filter.setEncoding("UTF-8");
filter.setForceEncoding(true);
return filter;
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new MappingJackson2HttpMessageConverter());
}
}
8 changes: 8 additions & 0 deletions src/main/java/gift/constant/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gift.constant;

public class Constants {
public static final String SECRET_KEY = "Yn2kjibddFAWtnPJ2AFlL8WXmohJMCvigQggaEypa5E=";
public static final long ONE_DAY_MILLIS = 86400000;
public static final String AUTHENTICATE_HEADER = "Authenticate";
public static final String BEARER = "Bearer";
}
59 changes: 59 additions & 0 deletions src/main/java/gift/controller/CategoryController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package gift.controller;

import gift.domain.Category;
import gift.dto.CategoryListDto;
import gift.dto.UpdateCategoryDto;
import gift.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/categories")
public class CategoryController {
private final CategoryService categoryService;

@Autowired
public CategoryController(CategoryService categoryService) {
this.categoryService = categoryService;
}

@Operation(summary = "모든 카테고리 조회")
@GetMapping
public ResponseEntity<List<CategoryListDto>> getAllCategories(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
Comment on lines +28 to +29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pageable pageable = PageRequest.of(page, size);
Page<CategoryListDto> categories = categoryService.findAll(pageable);
return ResponseEntity.ok(categories.getContent());
}

/* @GetMapping("/{id}")
public ResponseEntity<Category> getCategoryById(@PathVariable Long id) {
Category category = categoryService.findById(id);
return ResponseEntity.ok(category);
}

@PostMapping
public ResponseEntity<Category> createCategory(@RequestParam String name) {
Category category = categoryService.addCategory(name);
return ResponseEntity.ok(category);
}

@PutMapping("/{id}")
public ResponseEntity<Category> updateCategory(@PathVariable Long id, @RequestBody UpdateCategoryDto updateCategoryDto) {
Category updatedCategory = categoryService.updateCategory(id, updateCategoryDto);
return ResponseEntity.ok(updatedCategory);
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteCategory(@PathVariable Long id) {
categoryService.deleteCategory(id);
return ResponseEntity.noContent().build();
}*/
Comment on lines +35 to +57

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 개인적으로 미사용 API는 다시 살리는게 어려운 건 아니구 git에 전부 기록되어 있어서 삭제하는 방향을 선호하는데요
클린 코드 관점에서 지워보는게 어떠실까요?


}
Loading