Skip to content

Commit

Permalink
[BE] NPE 핸들링 및 TODO patch 테스트 서버 배포 (#628)
Browse files Browse the repository at this point in the history
* refactor: todo patch시 pair_room_id 사라지는 문제 해결

* fix: jwt NPE 핸들링

---------

Co-authored-by: fram1998 <[email protected]>
  • Loading branch information
reddevilmidzy and koust6u authored Sep 26, 2024
1 parent e3a543b commit 26fa241
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;

Expand Down Expand Up @@ -36,7 +35,7 @@ public boolean isValid(final String token) {
try {
verify(token);
return true;
} catch (final JwtException e) {
} catch (final Exception e) {
return false;
}
}
Expand Down
20 changes: 14 additions & 6 deletions backend/src/main/java/site/coduo/todo/repository/TodoEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,26 @@ public TodoEntity(final Todo todo, final PairRoomEntity pairRoom) {
this.isChecked = todo.getIsChecked().isChecked();
}

public void updateContent(final String content) {
this.content = content;
}

public void toggleTodoChecked() {
this.isChecked = !this.isChecked;
}

public Todo toDomain() {
return new Todo(this.id, this.content, this.sort, this.isChecked);
}

@Override
public String toString() {
return "TodoEntity{" +
"id=" + id +
", pairRoomEntity=" + pairRoomEntity +
", content='" + content + '\'' +
", sort=" + sort +
", isChecked=" + isChecked +
'}';
"id=" + id +
", pairRoomEntity=" + pairRoomEntity +
", content='" + content + '\'' +
", sort=" + sort +
", isChecked=" + isChecked +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
import org.springframework.data.jpa.repository.JpaRepository;

import site.coduo.pairroom.repository.PairRoomEntity;
import site.coduo.todo.exception.TodoNotFoundException;

public interface TodoRepository extends JpaRepository<TodoEntity, Long> {

default TodoEntity fetchById(Long id) {
return findById(id).orElseThrow(() -> new TodoNotFoundException("존재하지 않은 todo id입니다." + id));
}

List<TodoEntity> findAllByPairRoomEntityOrderBySortAsc(PairRoomEntity pairRoomEntity);

Optional<TodoEntity> findTopByPairRoomEntityOrderBySortDesc(PairRoomEntity pairRoomEntity);
Expand Down
18 changes: 6 additions & 12 deletions backend/src/main/java/site/coduo/todo/service/TodoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,15 @@ private TodoSort getLastTodoSort(final PairRoomEntity pairRoom) {
}

public void updateTodoContent(final Long todoId, final String content) {
final Todo todo = todoRepository.findById(todoId)
.map(TodoEntity::toDomain)
.orElseThrow(() -> new TodoNotFoundException("존재하지 않은 todo id입니다." + todoId));
final Todo updatedTodo = todo.updateContent(content);
final TodoEntity updatedTodoEntity = new TodoEntity(updatedTodo);
todoRepository.save(updatedTodoEntity);
final TodoEntity todoEntity = todoRepository.fetchById(todoId);

todoEntity.updateContent(content);
}

public void toggleTodoChecked(final Long todoId) {
final Todo todo = todoRepository.findById(todoId)
.map(TodoEntity::toDomain)
.orElseThrow(() -> new TodoNotFoundException("존재하지 않은 todo id입니다." + todoId));
final Todo updatedTodo = todo.toggleTodoChecked();
final TodoEntity updatedTodoEntity = new TodoEntity(updatedTodo);
todoRepository.save(updatedTodoEntity);
final TodoEntity todoEntity = todoRepository.fetchById(todoId);

todoEntity.toggleTodoChecked();
}

public void updateTodoSort(final Long targetTodoId, final int destinationSort) {
Expand Down

0 comments on commit 26fa241

Please sign in to comment.