Giter VIP home page Giter VIP logo

spring-boot-qna's Introduction

백엔드 개발자 👋

95degree's GitHub stats

활동

tempsnip

  • 아주대학교 교통시스템공학과 졸업
  • 코드스쿼드 코코아 백엔드 과정 2020/11/02~2020/12/04
  • 코드스쿼드 마스터즈 과정 백엔드 2021/01/04 ~ 2021/06/25
  • 쏘카 재직중

spring-boot-qna's People

Contributors

95degree avatar honux77 avatar javajigi avatar jihye-woo avatar

Stargazers

 avatar

spring-boot-qna's Issues

[미션 4] PR 리뷰 반영 - 웹 애플리케이션 관련 리뷰

웹 애플리케이션 관련 리뷰

  • 중복 userId로 회원 가입이 가능한 문제

    • UserRepository에 existsById(long id) 구현 및 적용
  • 사용자 입력에 대한 유효성 검사

    • @Valid 사용?
    • gradle 의존성 추가
      • implementation 'org.springframework.boot:spring-boot-starter-validation'
    • 공식 문서 참고
    • 회원정보 입력 없이도 회원 가입 가능한 문제도 해결 가능 아마도?
  • 수정 완료 후 해당하는 글로 이동

    • QuestionController의 updateQuestion() 리턴하는 url 수정
    • return "redirect:/";return "redirect:/"; + questionId
    • 인자로 받은 questionId가 아닌, questionService.update()에서 리턴받은 값 사용할 것(보안)
  • CSS 깨지는 부분 수정

    • 질문하기 페이지 (qna/show.html)
    • 회원 정보 수정 페이지 (user/updateForm.html)
  • 500 에러 핸들

    • 가입되지 않은 유저가 로그인을 시도할 경우
      • UserController의 signUp() 수정
    • 다른 사람이 작성한 글을 수정 혹은 삭제하려는 경우 / 다른 사람이 회원 정보를 수정할 경우
      • access invalid 관련 custom exception + error 페이지 만들기
      • 혹은 model에 error message 저장한 후 html에서 {{^error_message}}와 같은 처리 필요
  • 회원정보 수정 페이지

    • 이메일 input 태그에 value 옵션 추가
      • value="{{user.email}}" 추가

[미션4] Soft Delete 구현

  • Entity 클래스 수정
    • 필드에 boolean 타입 isActive 변수 추가
    • @Where 어노테이션 추가
      • @where(clause="is_active=1")
    • (+) @SQLDelete 어노테이션 추가

- [ ] Repository 수정

  • delete() 메소드 Override
  • softDelete() 메소드 구현
  •  @Query("UPDATE #{#entityName} a SET a.isActive=false WHERE a.id=?1")
     @Modifying
     void softDelete(Long id);
    
     @Override
     default void delete(User user) {
         softDelete(user.getId());
     }

[미션3]질문 삭제하기 구현

  • 삭제하기는 로그인 사용자와 글쓴이의 사용자 아이디가 같은 경우에만 가능하다.
  • 로그인하지 않은 사용자 또는 자신의 글이 아닌 경우 로그인 화면으로 이동한다.
  • @DeleteMapping을 사용해 매핑하고 구현한다.
  • html에서 form submit을 할 때 와 같이 PUT method를 값으로 전송한다.

[미션3]User와 Question 연결

요구사항

현재 Question의 글쓴이는 User의 name 값을 가지는 것으로 구현했다.
이와 같이 구현하는 경우 User의 name을 수정하는 경우 Question의 글쓴이와 다른 값을 가지는 문제가 발생한다.
이 문제를 해결하기 위해 User의 name이 변경될 때마다 Question의 writer 값을 수정할 수도 있지만 이와 같이 구현할 경우 writer가 같은 이름을 가지는 경우 문제가 될 수 있다.

  • User의 id를 저장하는 방법
    User의 primary key인 id 값을 Question에 저장한다.
    Question을 조회할 때 id 값을 통해 User도 같이 조회한다.

  • @manytoone 매핑을 사용하는 방법
    Question에 다음과 같이 @manytoone 매핑을 한다.

@Entity
public class Question {
	@ManyToOne
	@JoinColumn(foreignKey = @ForeignKey(name = "fk_question_writer"))
	private User writer;

위와 같이 매핑할 경우 Question을 조회할 때 User도 같이 조회한다.

[미션 4] PR 리뷰 반영 - 리펙토링

리펙토링

  • is_active 값 표기 통일
    • @SQLDelete@Where에서 is_active 값 '0' → 0
    • 작은 따옴표 제외하는 형식으로 통일
  • LocalDateTime time 네이밍
    • 조금 더 명확한 이름으로 수정 → createAt, createTime, etc..
  • 퍼머링크 시간 포멧팅
    • {{question.time}} 대신 {{formatDateTime question.time}} 사용
    • show.html에서 '퍼머링크'로 검색
  • @Column 단독 사용 시 불필요
    • 제거
  • Boolean 래퍼 타입 대신 primitive 타입으로 변경
    • Boolean isActive = true; 대신 boolean
  • Answer 빈 라인 제거
  • 전체적으로 코드 포멧팅

[오류] Question 클래스 생성자 오버로딩 오류

QuestionDto를 인자로 받는 Question 클래스 생성자에 오류가 있습니다

  • 오류가 발생하는 Question 생성자 삭제
    • 아래 생성자 삭제
      public Question(QuestionDto questionDto){
              this.writer = questionDto.getWriter();
              this.title = questionDto.getTitle();
              this.contents = questionDto.getContents();
              this.time = questionDto.getTime();
         }
  • 해당 생성자에 의존하는 코드 수정
    • QuestionDto → Entity 전환 문제
    • QuestionDto 클래스 내부에 toEntity() 생성으로 해결
      public Question toEntity(){
          return new Question(writer, title, contents);
      }
    • new Question(quesitonDto) 구조 대신 questionDto.toEntity() 사용

[미션3] 리펙토링

  • id 네이밍

    • id가 어떤 entity와 관련있는지 명확하게 표기
  • 공통 url 묶기 @RequestMapping

  • 사용자 정의 예외 구현

  • 서비스 계층 메소드에 @transactional 추가

[미션3] 리뷰 반영

  • 1. AnswerDto 수정

    • Question 필드 삭제
    • quetionId 추가
  • 2. AnswerResponse 구현

    • AnswerDto에서 question 필드 제외한 나머지를 필드 변수로
  • 3. delete() 수정

    • quetionId 대신 answer.quetion의 id 리턴 받기
  • 4. QuestioService에 save() 생성

  • 5. QuestionController의 delete() 묶어서 Service로

  • 6. Time 타입을 LocalDateTime으로 변경

    • Handlebars CustomHelper로 포맷팅 하기
  • 7.@transactional create() 추가

  • 8. Answer 에서 static 메소드 of() 생성

[미션 4] PR 리뷰 반영 - 코드 관련 리뷰

코드 관련 리뷰

  • QuestionController

    • list() - 메소드 리턴 url 변경
      • return index → return redirect:/
      • HomeController 구현한 뒤 list() 메소드 이동
      • QuestionController에서 RequestMapping()으로 공통 url 묶어주기
    • viewQuestionForm()
      • 한 줄 if 문 중괄호 추가
  • RESTful api - UserController의 updateUser()i

    • UserController의 updateUser()
    • @PutMapping("{id}/update")
    • PUT method가 이미 update의 의미를 내포하고 있기 때문에 url에서 update는 불필요
  • AnswerService

    • verifyAnswer() 불필요
    • sessionedUser.isMatchingUserId(answer.getWriter()); 바로 사용하는 것이 깔끔

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.