오늘은 git이 말썽이였다. 폴더 올리기도 안되고 올려도 에러가 터져서 고생했는데, 그 해결법을 써보기로 한다.
git hub에 통째로 파일 올리는 법
인텔리제이의 터미널에 git init 하고 레포지터리 처음 만들면 나오는
git remote add origin https://github.com/suh75321/Todolist2.git
를 치면 되는데, 뒤에 부분은 어떤 레포지터리냐에 따라 다르다.
그리고 git add .(add하고 띄고 .이다.) 다음엔 git commit -m "아무 메시지"를 하고 git push origin main를 하면 올라간다.
근데 이미 연결되어있다고 하면
git remote를 쳐서 나오는 이름을, 예를들어 origin이라고 뜨면 git remote remove origin으로 없애고 다시 git remote add origin https://github.com/suh75321/Todolist.git
를 하고 순서대로 하면 된다.
그런데 올라간 파일이 화살표 표시가 뜨면서 열람이 불가능하다면
반드시 화살표가 생긴 폴더 경로에서 해야 한다. teamsparta가 화살표가 생기면, cd 명령어로 거기까지 가서 rm -rf .git
그 다음엔 git rm --cached . -rf를 해야 한다. 그리고 다시 최상위 파일로 가서 add. commit -m"" git push origin등을 해야한다.
상위파일은 cd..으로 가면 된다.
data class Task
에서 Task가 빨간줄 이런걸로 고생 많이 했는데,
constructor() : this(id = null)
을 밑에 추가하면 된다.
UnsatisfiedDependencyException 이 에러도 많이 나와서 고생했는데, 보통은 @Autowired가 중복된것이라 하나만 남기고 수정하던가, @Entity처럼 @이걸 빈?이였나? 그걸 넣어야 하는걸 빼먹은거라 빠진데를 찾아서 넣어줘야 한다. 난 후자였다.
package com.teamsparta.courseregistration2.domain.service
import com.teamsparta.courseregistration2.domain.Task
import com.teamsparta.courseregistration2.domain.TaskRepository
import com.teamsparta.courseregistration2.domain.dto.CommentDto
import org.springframework.data.domain.Sort
import org.springframework.stereotype.Service
import java.util.*
@Service
class TaskService(private val taskRepository: TaskRepository) {
fun getAllTasks(): List<Task> {
val tasks = taskRepository.findAll(Sort.by(Sort.Direction.DESC, "createdAt"))
return tasks
}
fun getTaskById(id: Long): Optional<Task> {
return taskRepository.findById(id)
}
fun createTask(task: Task): Task {
return taskRepository.save(task)
}
fun updateTask(id: Long, newTask: Task): Optional<Task> {
return taskRepository.findById(id).map { existingTask ->
existingTask.title = newTask.title
existingTask.content = newTask.content
existingTask.writer = newTask.writer
taskRepository.save(existingTask)
}
}
fun deleteTask(id: Long) {
return taskRepository.deleteById(id)
}
fun deleteAllTasks() {
TODO("Not yet implemented")
}
fun addCommentToTask(task: Task, comment: CommentDto): Task {
// 여기에 댓글을 추가하는 로직을 구현하세요.
return task
}
}
여기의 existingTask.title = newTask.title
existingTask.content = newTask.content
existingTask.writer = newTask.writer
이 부분을 매서드화 하라고 한다.
fun updateTask(id: Long, newTask: Task): Optional<Task> {
return taskRepository.findById(id).map { existingTask ->
existingTask.title = newTask.title
existingTask.content = newTask.content
existingTask.writer = newTask.writer
taskRepository.save(existingTask)
}
}이랬던 녀석이
fun updateTask(id: Long, newTask: Task): Optional<Task> {
return taskRepository.findById(id).map { existingTask ->
updateTaskDetails(existingTask, newTask)
taskRepository.save(existingTask)
}
}
// ...
private fun updateTaskDetails(existingTask: Task, newTask: Task) {
existingTask.title = newTask.title
existingTask.content = newTask.content
existingTask.writer = newTask.writer
}
}
이렇게 바뀐다.