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

[4조] 황현식 반려동물 추천 프로그램 #9

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

Choon0414
Copy link

No description provided.

Copy link

@Choi-JJunho Choi-JJunho left a comment

Choose a reason for hiding this comment

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

3주차 피드백은 코멘트로 남겨드려봅니다.
추가적인 질문사항 있다면 DM으로 자유롭게 질문주셔도 좋습니다 👍

Comment on lines 17 to 28
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AnimalDTO animalDTO = (AnimalDTO) o;
return animalId == animalDTO.animalId;
}

@Override
public int hashCode() {
return Objects.hash(animalId);
}

Choose a reason for hiding this comment

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

equals & hashcode를 재정의하신 이유가 있을까요?

Copy link
Author

Choose a reason for hiding this comment

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

사용자의 여러 키워드에 대해서 매칭된 동물DTO 집합을 만들 때, 중복되는 동물은 추가하지 않아야해서 equals()와 hashCode() 를 재정의했습니다.

@Setter
public class CreateAccessTokenRequest {
private String refreshToken;
}

Choose a reason for hiding this comment

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

image

github 상에서 빨간색 경고를 띄우고 있네요~ 왜 이런 경고가 발생하고 어떻게 예방할 수 있을지 아래 자료를 참고해보시면 좋을 것 같습니다.

@Getter
@Setter
@Component
@ConfigurationProperties("jwt")

Choose a reason for hiding this comment

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

@ConfigurationProperties("jwt")를 활용하여 property를 묶어서 관리했군요 👍

import java.util.Date;
import java.util.Set;

@Service

Choose a reason for hiding this comment

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

Service 어노테이션을 선택한 이유가 있을까요?
Component와 Service는 어떤 차이가 있을까요

Copy link
Author

Choose a reason for hiding this comment

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

처음엔 tokenProvider도 토큰을 생성하는 동작을 하니까 비즈니스 로직의 일종이라고 생각하고 사용했습니다.
둘 다 기능적으로는 차이가 없지만 @component는 Bean 클래스임을, @service는 비교적 복잡하고 특정한 기능을 하는 클래스임을 명시하기 위해 사용합니다. 알아보고 나니 @component가 더 적절한 것 같아서 수정했습니다.

Comment on lines 42 to 53
.formLogin(formLogin ->
formLogin
.loginPage("/login")
.defaultSuccessUrl("/home", true)
.permitAll()
)// 폼 기반 로그인 설정
.logout(logoutConfig ->
logoutConfig
.logoutSuccessUrl("/login")
.invalidateHttpSession(true)
.permitAll()
)

Choose a reason for hiding this comment

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

이렇게 설정했을 때 JWT 기반 인증방식이 잘 동작하나요??

Copy link
Author

Choose a reason for hiding this comment

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

원래 html과 폼로그인 방식으로 구현하려고 했다가 JWT로 넘어가면서 삭제했습니다!

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter

Choose a reason for hiding this comment

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

시간이 된다면 Setter를 제거해보시는것을 추천드립니다.

조금 길지만 Setter를 왜 지양해야하는지 설명하는 자세한 글이 있어 공유드립니다.
velog - setter 쓰지 말라고만 하고 가버리면 어떡해요

@Builder // SQL 파라미터에 값을 쉽게 넣어주기 위함
@Entity(name = "keywords") // 해당 class에서 사용할 테이블 명
@AllArgsConstructor // 매개변수에 대한 생성자들을 자동 생성
@NoArgsConstructor // 기본생성자를 자동 생성

Choose a reason for hiding this comment

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

Entity를 선언하는 과정에서는 기본 생성자를 필수료 요구합니다.
Entity에 기본 생성자가 왜 필요할까요? 한번 생각해보면 좋을 것 같아 남겨봅니다

Copy link
Author

Choose a reason for hiding this comment

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

JPA는 Entity의 기본 생성자로 객체를 먼저 생성한 뒤, Reflection API를 이용해 값을 넣기 때문에 기본 생성자가 필수입니다. 그리고 지연 로딩을 위해 프록시 객체를 사용하기 때문에 private 생성자는 사용하면 안됩니다.

Comment on lines 27 to 30
public RefreshToken update(String newRefreshToken){
this.refreshToken = newRefreshToken;
return this;
}

Choose a reason for hiding this comment

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

객체의 상태가 업데이트 되었는데 굳이 this를 반환할 이유가 있을까요?

Comment on lines +25 to +36
<form action="/login/proc" method="POST">
<input type="hidden" th:name="${_csrf?.parameterName}" th:value="${_csrf?.token}" />
<div class="mb-3">
<label class="form-label text-white">Email address</label>
<input type="userId" class="form-control" name="userId">
</div>
<div class="mb-3">
<label class="form-label text-white">Password</label>
<input type="password" class="form-control" name="password">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>

Choose a reason for hiding this comment

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

로그인 폼을 만들어주셨네요~ 아마 SpringSecurity를 활용하며 생긴 양식같은데 잘 활용해보시길 바랍니다 🔥

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

@SpringBootTest
class TokenProviderTest {

Choose a reason for hiding this comment

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

오?! SpringBootTest를 작성해주셨네요 👍

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.

2 participants