본문 바로가기
중간평가/disassemble_1

중간평가 (Main)

by pms93 2022. 8. 10.
package disassemble.main;

import java.util.Scanner;
import disassemble.Service.*;
import disassemble.DAO.*;
import disassemble.DTO.*;


public class Main {
	private static MemberDAO memberDao = new MemberDAO();
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			System.out.println("명령어를 입력하세요");
			System.out.print("> ");
			String command = sc.nextLine();
			if(command.equalsIgnoreCase("exit")){
				System.out.println("종료합니다.");
				break;
			}
			if(command.startsWith("new")){
				processNewCommand(command.split(" "));
				continue;
			} else if(command.startsWith("change")){
				processChangeCommand(command.split(" "));
				continue;
			} else if(command.startsWith("all")) {
				processAllCommand();
				continue;
			} else if(command.startsWith("delete")) {
				processDeleteCommand(command.split(" "));
				continue;
			}
			
			printHelp();
		}
	}
	
	private static void processNewCommand(String[] arg) {
		if(arg.length != 5){
			printHelp();
			return;
		}
		// MemberRegisterService 객체 생성
		// RegisterRequest 객체 생성 
		// 데이터는 RegisterRequest 객체에 입력
		// regSvc.regist() 호출
		// 이메일[1], 이름[2], 암호[3], 암호확인[4]
		MemberRegisterService regSvc = new MemberRegisterService(memberDao);
		RegisterRequest regReq = new RegisterRequest();
		regReq.setEmail(arg[1]);
		regReq.setName(arg[2]);
		regReq.setPassword(arg[3]);
		regReq.setConfirmPassword(arg[4]);
		regSvc.regist(regReq);
	}
	
	private static void processAllCommand() {
		// MemberAllService 객체 생성
		// allSvc.selectAll() 호출
		MemberAllService allSvc = new MemberAllService(memberDao);
		allSvc.selectAll();
	}

	private static void processChangeCommand(String[] arg) {
		if(arg.length != 4) {
			printHelp();
			return;
		}
		// ChangePasswordService 객체 생성
		// change.changePassword() 호출
		// email[1], 현재비밀번호[2], 변경비밀번호[3]
		ChangePasswordService change = new ChangePasswordService(memberDao);
		change.changePassword(arg[1], arg[2], arg[3]);
	}

	private static void processDeleteCommand(String[] arg) {
		if(arg.length != 4) {
			printHelp();
			return ;
		}
		// MemberDeleteService 객체 생성
		// delete.checkPassword() 호출
		// 이메일[1], 암호[2], 암호확인[3]
		MemberDeleteService delete = new MemberDeleteService(memberDao);
		delete.checkPassword(arg[1], arg[2], arg[3]);
	}

	private static void printHelp(){
		System.out.println();
		System.out.println("명령어 사용법을 확인하세요.");
		System.out.println("usage : ");
		System.out.println("모든 정보 출력 : all");
		System.out.println("정보 등록 : new [이메일] [이름] [암호] [암호확인]");
		System.out.println("비밀번호 수정 : change [이메일] [현재비밀번호] [변경할비밀번호]");
		System.out.println("정보 삭제 : delete [이메일] [암호] [암호확인]");
		System.out.println("종료 : exit");
		System.out.println();
	}
}

'중간평가 > disassemble_1' 카테고리의 다른 글

중간평가 (Service)  (0) 2022.08.10
중간평가 (DTO, DAO)  (0) 2022.08.10