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_김영인 3주차 과제(1단계) #197

Open
wants to merge 122 commits into
base: youngini
Choose a base branch
from

Conversation

Youngini
Copy link

1주차 과제를 위한 테스트 코드를 작성하였는데 오류가 발생하였습니다.

관련 오류는 properties 설정 오류 일 수도 있다는 것 까지는 이해했는데 제가 봤을때는 properties 설정에 문제가 없는 듯 보이는데 혹시 어떤 부분이 잘못되었는지 알려주실 수 있으실까요,,?

wotjd243 and others added 30 commits June 24, 2024 08:00
1. ProductController의 createProduct 메서드에서 validateProductDto 메서드를 분리하여 indent depth를 2 이하로 유지
2. 3항 연산자 대신 if-return 패턴을 사용
3. createProduct 메서드의 길이가 15라인 이하가 되도록 함
4. createProduct 메서드는 상품 생성 기능만 수행하도록 했습니다.
5. else 예약어를 사용하지 않고 if 문에서 값을 바로 반환하는 방식으로 구현
Youngini added 18 commits July 9, 2024 14:38
controller 내에서 비밀번호 암호화나 token을 받아오는 부분 등의비지니스 로직을 서비스 내부로 정리했습니다.
토큰을 변환해서 id값을 받아오고 싶은데 parserBuilder에서 계속 오류가 발생해서 저것을 사용하지 않고 어떻게 구현하는 것이 좋을지 고민중
save의 반환값이 서로 달라서 발생한 문제
createdAt을 삭제하면서 관련 코드 모두 삭제
@Youngini Youngini changed the title 경북대 BE_김영인 1주차 과제 경북대 BE_김영인 3주차 과제(1단계) Jul 10, 2024
Copy link

@gongdongho12 gongdongho12 left a comment

Choose a reason for hiding this comment

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

테스트만 오류고 일반 실행은 될까요?
금요일에 체크해야할 리스트로

  • 로그인 이슈
  • 테스트 이슈
  • 오늘 0회차 깃 push 이슈

이정도를 싱크하면 될 것 같은데 혹시 아직 전달이 안된 내용 있으면 이 PR에 내용 업데이트 부탁드립니다

처음 JPA 사용인데도 고생많으셨습니다

build.gradle Outdated
Comment on lines 37 to 39
// 보안 관련 의존성
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.security:spring-security-test'

Choose a reason for hiding this comment

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

스프링 시큐리티는 이번 프로젝트의 주요한 목표는 아니여서 지금처럼 해매고 있다면 기존 강의에서처럼 resolver를 구현해서 등록하면 좋을 것 같습니다

Choose a reason for hiding this comment

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

코드 보니까 사용 안하고 있다면 비활성화 해도 되지 않을까요?

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'

Choose a reason for hiding this comment

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

swagger 사용해보려는 노력 👍🏼

Comment on lines 35 to 39
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService())
.passwordEncoder(passwordEncoder());
}
}

Choose a reason for hiding this comment

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

이 로직 쓰여지지 않고 있지 않나요?
코드 수정하시면서 사용 안하는 코드들은 전부 git에 남으니까 걱정 안하시구 작성주시는게 추후 나중에 같이 작업하는 분이 생기거나 리뷰할 때 비지니스 로직에 더 포커싱할 수 있겠죠?

return ResponseEntity.ok(loginResponse);
} else {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
.header("WWW-Authenticate", "Bearer")

Choose a reason for hiding this comment

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

헤더 키를 WWW-Authenticate가 아니라 Authenticate로 해야하지 않나요?
만약 "WWW-Authenticate"이런 헤더키를 쓴다면 다른 인증부에도 동일한 헤더키를 적용해야 되자나요
그래서 상수 값으로 정의되면 좋을 것 같습니다

Comment on lines 34 to 39
try {
MemberResponse responseDto = memberService.registerMember(requestDto);
return ResponseEntity.status(HttpStatus.CREATED).body(responseDto);
} catch (IllegalArgumentException e) {
return ResponseEntity.status(HttpStatus.CONFLICT).build();
}

Choose a reason for hiding this comment

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

이런 공통 Exception은 ControllerAdvice로 깔끔하게 어떠실까요?

Comment on lines 43 to 47
public ResponseEntity<LoginResponse> login(@RequestBody LoginRequest loginRequest) {
LoginResponse loginResponse = memberService.login(loginRequest);
if (loginResponse.getToken() != null) {
return ResponseEntity.ok(loginResponse);
} else {

Choose a reason for hiding this comment

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

컨트롤러는 로직과 연결하는 레이어인데 토큰을 체크하고 로그인 상태를 체크하고 리스폰스를 분기해주고 있어요
이 부분을 서비스에 넣고 문제가 생길때 Exception을 주면
서비스 + ControllerAdvice로 해소 가능하지 않을까요?

Comment on lines +5 to +42
@Entity
@Table(name = "member")
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long user_id;
@Column(unique = true, nullable = false)
private String email;
@Column(nullable = false)
private String password;

public Member(String mail, String password) {
this.email = mail;
this.password = password;
}

public String getEmail() {
return email;
}

public String getPassword() {
return password;
}

public void setUser_id(long userId) {
this.user_id = userId;
}
public void setEmail(String email) {
this.email = email;
}
public void setPassword(String password) {
this.password = password;
}

public Long getId() {
return user_id;
}
}

Choose a reason for hiding this comment

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

엔티티 사용 👍🏼
image
엔티티 끼리 잘 묶어주셨네요

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long user_id;
@Column(unique = true, nullable = false)

Choose a reason for hiding this comment

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

이메일 중복 방지를 위한 유니크키 반영 💯

Comment on lines +13 to +46
@DataJpaTest
class MemberRepositoryTest {
@Autowired
private MemberRepository memberRepository;

@Test
void save() {
// given
Member member = new Member("test@example.com", "password");

// when
Member savedMember = memberRepository.save(member);

// then
assertThat(savedMember.getId()).isNotNull();
assertThat(savedMember.getEmail()).isEqualTo("test@example.com");
assertThat(savedMember.getPassword()).isEqualTo("password");
}

@Test
void findByEmail() {
// given
Member member = new Member("test@example.com", "password");
memberRepository.save(member);

// when
Optional<Member> foundMember = memberRepository.findByEmail("test@example.com");

// then
assertThat(foundMember).isPresent();
assertThat(foundMember.get().getEmail()).isEqualTo("test@example.com");
assertThat(foundMember.get().getPassword()).isEqualTo("password");
}
}

Choose a reason for hiding this comment

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

JPA는 비지니스 로직과 연계되어 있어 Test를 만들어두는게 좋더라구요 👍🏼
새로운 부분이 많았을텐데 고생많으셨습니다

Comment on lines +19 to +28
Product product = new Product("Test Product", 1000, "https://example.com/image.jpg");

// when
Product savedProduct = productRepository.save(product);

// then
assertThat(savedProduct.getId()).isNotNull();
assertThat(savedProduct.getName()).isEqualTo("Test Product");
assertThat(savedProduct.getImageUrl()).isEqualTo("https://example.com/image.jpg");
assertThat(savedProduct.getPrice()).isEqualTo(1000);

Choose a reason for hiding this comment

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

각각 값을 빼서 비교해도 좋지만 객체를 새로 만들어서 비교해보는 것도 시도해보면 좋을 것 같아요!

sapsalian added a commit to sapsalian/spring-gift-jpa that referenced this pull request Jul 11, 2024
* Initial commit

* 경북대BE_안용진_1주차 과제 (kakao-tech-campus-2nd-step2#197)

* docs(README.md): fill README.md with features that should be implemented

* docs(README.md): add some response details

* feat: add ProductRecord class for storing product information

and some code for testing if record class works well

* feat: dd feature to check existence of record by ID

* feat: add feature to create new id

* feat: change id type from String to long

* feat: add feature to insert records with specified ID

* feat: add feature to insert records with automatically specified ID

* feat: implement post handler method

* feat: implement get request handler

* feat: add feature to handling DELETE request

* refactor: change addNewRecord to throw Exception instead of to return null

* feat: implement feature to handle PUT

* refactor: extract feature that make created response entity to function

* feat: implement feature to handle PATCH

* feat: add global exception handler

* refactor: extract withId method to Record class for creating new objects with specific id

* refactor : reorder methods for better readability and understanding

* docs: add extra features

* refactor: restructure project packages

* Step2 시작

* feat: create necessary files for server side rendering

* feat: add simple table that shows information of products

* feat: make simple edit page

* fix: fix getNewId() to correctly find new id

* fix: ensure null is passed when input is empty

* feat: add simple product add page

* feat: add buttons to manipulate data

* docs: fill README with list of features for step2

* style: apply styling using CSS

* style: apply styling on product add page using CSS

* style: apply styling on product edit page

* Step3 시작

* feat: connect Record get functions to jdbcTemplates

* feat: integrate addNewRecord method with JDBC

* feat: integrate replaceRecord method that update all field of record with jdbc

* feat: Integrate edit record feature with JDBC

* feat: integrate feature deleting record with JDBC

* refactor: edit getNewId not to make overflow

* fix: correct table name typo

* fix: adjust some bug

* feat: set auto schema initialization using schema.sql

* refactor: change field-based injection to constructor-based injection

* refactor: Ensure consistency by updating all Rest methods to use ResponseEntity

* feat: Implement global handler method for all subclasses of Exception

* docs: add TODO comments

* refactor: Remove unused fields

* refactor: Remove unused fields

* refactor: Change all field injections to constructor injections

* refactor: Replace all array structures with List

* feat: Change to generate keys in the database

---------

Co-authored-by: 박재성(Jason) <wotjd243@naver.com>
leaf-upper pushed a commit that referenced this pull request Jul 11, 2024
* Initial commit

* feat: set up the project

* 경북대BE_안용진_2주차 과제(step0) (#74)

* Initial commit

* 경북대BE_안용진_1주차 과제 (#197)

* docs(README.md): fill README.md with features that should be implemented

* docs(README.md): add some response details

* feat: add ProductRecord class for storing product information

and some code for testing if record class works well

* feat: dd feature to check existence of record by ID

* feat: add feature to create new id

* feat: change id type from String to long

* feat: add feature to insert records with specified ID

* feat: add feature to insert records with automatically specified ID

* feat: implement post handler method

* feat: implement get request handler

* feat: add feature to handling DELETE request

* refactor: change addNewRecord to throw Exception instead of to return null

* feat: implement feature to handle PUT

* refactor: extract feature that make created response entity to function

* feat: implement feature to handle PATCH

* feat: add global exception handler

* refactor: extract withId method to Record class for creating new objects with specific id

* refactor : reorder methods for better readability and understanding

* docs: add extra features

* refactor: restructure project packages

* Step2 시작

* feat: create necessary files for server side rendering

* feat: add simple table that shows information of products

* feat: make simple edit page

* fix: fix getNewId() to correctly find new id

* fix: ensure null is passed when input is empty

* feat: add simple product add page

* feat: add buttons to manipulate data

* docs: fill README with list of features for step2

* style: apply styling using CSS

* style: apply styling on product add page using CSS

* style: apply styling on product edit page

* Step3 시작

* feat: connect Record get functions to jdbcTemplates

* feat: integrate addNewRecord method with JDBC

* feat: integrate replaceRecord method that update all field of record with jdbc

* feat: Integrate edit record feature with JDBC

* feat: integrate feature deleting record with JDBC

* refactor: edit getNewId not to make overflow

* fix: correct table name typo

* fix: adjust some bug

* feat: set auto schema initialization using schema.sql

* refactor: change field-based injection to constructor-based injection

* refactor: Ensure consistency by updating all Rest methods to use ResponseEntity

* feat: Implement global handler method for all subclasses of Exception

* docs: add TODO comments

* refactor: Remove unused fields

* refactor: Remove unused fields

* refactor: Change all field injections to constructor injections

* refactor: Replace all array structures with List

* feat: Change to generate keys in the database

---------

Co-authored-by: 박재성(Jason) <wotjd243@naver.com>

* 경북대 BE_안용진 2주차 과제(1단계) (#209)

* feat: Display error messages to users when receiving an error response

* docs: fill README with list of features for step1

* feat: Apply validation using BeanValidation

* build: Add boot-starter-validation dependency

* feat: Add exception handler for MethodArgumentNotValidException

* feat: Implement response handling for 400 errors on admin page

* fix: Correct minor text typos

* 경북대 BE_안용진 2주차 과제 (2, 3단계) (#376)

* 2단계 시작

* feat: Add users table definition to schema.sql

* feat: Add users table definition to schema.sql

* refactor: Update data types to comply with SQL standards

* refactor: Rename model package to entity package

* feat: Implement API to retrieve all users

* feat: add Request Http for test getUsers API

* refactor: add UserService class

* refactor: Modify API request URLs to start with /api

* feat: Add signup

* feat: Respond with 409 Conflict for duplicate email signups

* feat: Add account deletion

* feat: Implement password change functionality (JWT token not yet applied)

* feat: Implement login

* feat: Add exception handler to response 403 for forbidden requests or password errors

* refactor: Redistribute responsibilities

* refactor: Rename JWT package to lowercase

* feat: Apply authentication filter

* feat: Implement TokenEmail Resolver to extract email from token and pass as method argument

* feat: Implement user-specific wishlist retrieval

* feat: Implement wishlist addition

* feat: Implement wishlist deletion

* fix: fix sql typos

* refactor: Update API paths

* refactor: Reorganize packages

* refactor: remove unneccessary folder

---------

Co-authored-by: 박재성(Jason) <wotjd243@naver.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants