몽땅뚝딱 개발자

[JAVA/Spring Boot] TodoList 만들기(8) - Mapper, Service 본문

Development/Spring Framework

[JAVA/Spring Boot] TodoList 만들기(8) - Mapper, Service

레오나르도 다빈츠 2021. 6. 20. 01:13

 

📄 TodoService.java

package com.moddk.swagger.service;

import java.util.List;

import com.moddk.swagger.vo.TodoVO;

public interface TodoService {

	// TodoList 가져오기
	public List<TodoVO> getTodoList(int searchType, String user_id);
	
	// TodoList 추가하기
	public int addTodoList(String contents, String user_id);
	
	// TodoList 값 변경하기
	public int updateComYnOfTodoList(int idx);
	
	// Todo 삭제하기
	public int deleteTodo(int idx, String user_id);	
	
	// 로그인 체크
	public int loginCheck(String user_id, String user_pw);
}

 

 

 

 

 

📄 TodoServiceImpl.java

package com.moddk.swagger.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.moddk.swagger.mapper.TodoMapper;
import com.moddk.swagger.vo.TodoVO;

@Service
public class TodoServiceImpl implements TodoService {
	
	@Autowired
	private TodoMapper mapper;

	@Override
	public List<TodoVO> getTodoList(int searchType, String user_id) {
		if(searchType == 0) {
			// 전체 Todo 가져오기
			return mapper.getAllTodoList(user_id);
            
		} else if(searchType == 1) {
			// 활성화된 Todo 가져오기
			return mapper.getActiveTodoList(user_id);
            
		} else {
			// 완료된 Todo 가져오기
			return mapper.getCompletedTodoList(user_id);
		}
	}

	@Override
	public int addTodoList(String contents, String user_id) {
		return mapper.addTodoList(contents, user_id);
	}

	@Override
	public int updateComYnOfTodoList(int idx) {
		return mapper.updateComYnOfTodoList(idx);
	}

	@Override
	public int deleteTodo(int idx, String user_id) {
 		return mapper.deleteTodo(idx, user_id);
	}

	@Override
	public int loginCheck(String user_id, String compare_user_pw) {
		
		String user_pw = mapper.getUserPw(user_id);
		int isPassed = user_pw.equals(compare_user_pw) ? 1 : 0;
		
		return isPassed;
	}
}

 

 

 

 

📄 TodoMapper.java

package com.moddk.swagger.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

import com.moddk.swagger.vo.TodoVO;

@Mapper
public interface TodoMapper {
	public List<TodoVO> getAllTodoList(String user_id);
	public List<TodoVO> getActiveTodoList(String user_id);
	public List<TodoVO> getCompletedTodoList(String user_id);
	public int addTodoList(String contents, String user_id);
	public int updateComYnOfTodoList(int idx);
	public int deleteTodo(int idx, String user_id);
	public String getUserPw(String user_id);
}

 

 


개인적으로 공부한 내용을 정리하는 블로그로
잘못된 개념을 게시하지않도록 주의하고 있으나 오류가 있을 수 있습니다.

 

Comments