diff --git a/src/main/java/com/delfood/controller/MemberController.java b/src/main/java/com/delfood/controller/MemberController.java index 23a3c3e..65c2745 100644 --- a/src/main/java/com/delfood/controller/MemberController.java +++ b/src/main/java/com/delfood/controller/MemberController.java @@ -1,8 +1,8 @@ package com.delfood.controller; import com.delfood.dto.MemberDTO; -import com.delfood.mapper.DMLOperationError; import com.delfood.service.MemberService; +import com.delfood.utils.SessionUtil; import javax.servlet.http.HttpSession; import javax.validation.constraints.NotNull; import lombok.AllArgsConstructor; @@ -16,6 +16,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -41,6 +42,7 @@ * 스레드 환경 로깅이 필요하다면 Log4j2를 사용하는 것이 성능면에서 유리하다. 사용자 정의 로그레벨과 람다 표현식을 지원한다. Log4j2 자체적으로 직접 사용할 수는 * 있지만 일반적으로는 SLF4J와 함께 사용한다. *

+ * * @Log @Slf4j @Log4j2 등 어노테이션 적용시 자동으로 log 필드를 만들고 해당 클래스의 이름으로 로거 객체를 생성하여 할당한다. * * @author 정준 @@ -62,7 +64,7 @@ public class MemberController { @GetMapping("myInfo") public ResponseEntity memberInfo(HttpSession session) { ResponseEntity responseEntity = null; - String id = (String) session.getAttribute("LOGIN_MEMBER_ID"); + String id = SessionUtil.getLoginMemberId(session); if (id == null) { responseEntity = new ResponseEntity(HttpStatus.UNAUTHORIZED); } else { @@ -130,7 +132,7 @@ public ResponseEntity signUp(@RequestBody @NotNull MemberDTO mem return responseEntity; } - /* + /** * 회원 로그인을 진행한다. Login 요청시 id, password가 NULL일 경우 NullPointerException을 throw한다. */ @PostMapping("login") @@ -150,7 +152,7 @@ public ResponseEntity login(@RequestBody @NonNull MemberLoginRequ } else if (MemberDTO.Status.DEFAULT.equals(memberInfo.getStatus())) { // 성공시 세션에 ID를 저장 loginResponse = LoginResponse.success(memberInfo); - session.setAttribute("LOGIN_MEMBER_ID", memberInfo.getId()); + SessionUtil.setLoginMemberId(session, id); responseEntity = new ResponseEntity(loginResponse, HttpStatus.OK); } else if (MemberDTO.Status.DELETED.equals(memberInfo.getStatus())) { // 삭제된 경우 @@ -166,17 +168,39 @@ public ResponseEntity login(@RequestBody @NonNull MemberLoginRequ } /** - * 회원 비밀번호 변경 + * 회원 로그아웃 메서드. + * + * @author jun + * @param session 현제 접속한 세션 + * @return 로그인 하지 않았을 시 401코드를 반환하고 result:NO_LOGIN 반환 로그아웃 성공시 200 코드를 반환하고 result:SUCCESS 반환 + */ + @GetMapping("logout") + public ResponseEntity logout(HttpSession session) { + String memberId = (String) session.getAttribute("LOGIN_MEMBER_ID"); + if (memberId == null) { + return new ResponseEntity(LogoutResponse.NO_LOGIN, + HttpStatus.UNAUTHORIZED); + } else { + SessionUtil.logoutMember(session); + } + + + return new ResponseEntity(LogoutResponse.SUCCESS, + HttpStatus.OK); + } + + /** + * 회원 비밀번호 변경. * * @param session 현재 로그인한 사용자의 세션 * @return */ - @PutMapping("password") + @PatchMapping("password") public ResponseEntity updateMemberInfo(HttpSession session, @RequestBody @NotNull UpdateMemberPasswordRequest passwordRequest) { String password = passwordRequest.getPassword(); String newPassword = passwordRequest.getNewPassword(); - String id = (String) session.getAttribute("LOGIN_MEMBER_ID"); + String id = SessionUtil.getLoginMemberId(session); ResponseEntity responseEntity = null; UpdateMemberPasswordResponse updateResponse; @@ -199,16 +223,10 @@ public ResponseEntity updateMemberInfo(HttpSession new ResponseEntity(updateResponse, HttpStatus.BAD_REQUEST); } else { // 성공시 - DMLOperationError dmlResponse = memberService.updateMemberPassword(id, newPassword); - if (dmlResponse == DMLOperationError.SUCCESS) { - updateResponse = UpdateMemberPasswordResponse.SUCCESS; - responseEntity = - new ResponseEntity(updateResponse, HttpStatus.OK); - } else { - // 정상적인 상황에서는 발생하지 않는 에러 - log.error("Member Password Update - ERROR!"); - throw new RuntimeException("Password update ERROR"); - } + memberService.updateMemberPassword(id, newPassword); + updateResponse = UpdateMemberPasswordResponse.SUCCESS; + responseEntity = + new ResponseEntity(updateResponse, HttpStatus.OK); } return responseEntity; @@ -225,40 +243,36 @@ public ResponseEntity updateMemberInfo(HttpSession public ResponseEntity deleteMemberInfo(HttpSession session) { ResponseEntity responseEntity = null; DeleteMemberResponse deleteResponse; - String id = (String) session.getAttribute("LOGIN_MEMBER_ID"); + String id = SessionUtil.getLoginMemberId(session); if (id == null) { deleteResponse = DeleteMemberResponse.NO_LOGIN; responseEntity = new ResponseEntity(deleteResponse, HttpStatus.UNAUTHORIZED); } else { - DMLOperationError dmlResponse = memberService.deleteMember(id); - if (dmlResponse == DMLOperationError.SUCCESS) { - deleteResponse = DeleteMemberResponse.SUCCESS; - // 회원 탈퇴시 로그아웃 시켜야 하기 때문에 세션 정보를 날린다 - session.invalidate(); - responseEntity = new ResponseEntity(deleteResponse, HttpStatus.OK); - } else { - // 정상적인 상황에서는 발생하지 않는 에러 - log.error("Member Delete ERROR! \n" + responseEntity); - throw new RuntimeException("Member Delete ERROR! " + responseEntity); - } + memberService.deleteMember(id); + deleteResponse = DeleteMemberResponse.SUCCESS; + + // 회원 탈퇴시 로그아웃 시켜야 하기 때문에 세션 정보를 날린다 + SessionUtil.logoutAll(session); + responseEntity = new ResponseEntity(deleteResponse, HttpStatus.OK); + } return responseEntity; } /** - * 회원 주소 변경 + * 회원 주소 변경. * * @param memberInfo 회원 주소 정보 * @param session 현재 로그인한 고객의 세션 */ - @PutMapping("address") + @PatchMapping("address") public ResponseEntity updateMemberAddress( @RequestBody @NotNull UpdateMemberAddressRequest memberInfo, HttpSession session) { ResponseEntity responseEntity = null; String address = memberInfo.getAddress(); String addressDetail = memberInfo.getAddressDetail(); - String id = (String) session.getAttribute("LOGIN_MEMBER_ID"); + String id = SessionUtil.getLoginMemberId(session); if (address == null || addressDetail == null) { // 요청한 주소가 null일 때 @@ -274,21 +288,10 @@ public ResponseEntity updateMemberAddress( responseEntity = new ResponseEntity( UpdateMemberAddressResponse.NO_LOGIN, HttpStatus.UNAUTHORIZED); } else { - DMLOperationError dmlResponse = memberService.updateMemberAddress(id, address, addressDetail); - if (dmlResponse == DMLOperationError.SUCCESS) { - // 성공시 - responseEntity = new ResponseEntity( - UpdateMemberAddressResponse.SUCCESS, HttpStatus.OK); - } else if (dmlResponse == DMLOperationError.NONE_CHANGED) { - // 주소 변경이 되지 않았을 때 - log.error("Member Address Update ERROR " + dmlResponse); - throw new RuntimeException("Member Address Update ERROR"); - } else { - // 너무 많은 주소가 변경되었을 때. 정상적인 상황에서는 발생하지 않는다. - log.error("Member Address Update ERROR " + dmlResponse); - throw new RuntimeException("Member Address Update ERROR"); - } - + // 모든 조건을 충족할 때 + memberService.updateMemberAddress(id, address, addressDetail); + responseEntity = new ResponseEntity( + UpdateMemberAddressResponse.SUCCESS, HttpStatus.OK); } return responseEntity; @@ -303,24 +306,42 @@ public ResponseEntity updateMemberAddress( @AllArgsConstructor @RequiredArgsConstructor private static class LoginResponse { - enum LogInStatus { + enum LoginStatus { SUCCESS, FAIL, DELETED, ERROR } @NonNull - private LogInStatus result; + private LoginStatus result; private MemberDTO memberInfo; // success의 경우 memberInfo의 값을 set해줘야 하기 때문에 new 하도록 해준다. - private static final LoginResponse FAIL = new LoginResponse(LogInStatus.FAIL); - private static final LoginResponse DELETED = new LoginResponse(LogInStatus.DELETED); + private static final LoginResponse FAIL = new LoginResponse(LoginStatus.FAIL); + private static final LoginResponse DELETED = new LoginResponse(LoginStatus.DELETED); private static LoginResponse success(MemberDTO memberInfo) { - return new LoginResponse(LogInStatus.SUCCESS, memberInfo); + return new LoginResponse(LoginStatus.SUCCESS, memberInfo); } + } + + @Getter + @RequiredArgsConstructor + private static class LogoutResponse { + enum LogoutStatus { + SUCCESS, NO_LOGIN, ERROR + } + + @NonNull + private LogoutStatus result; + + + private static final LogoutResponse NO_LOGIN = new LogoutResponse(LogoutStatus.NO_LOGIN); + private static final LogoutResponse SUCCESS = new LogoutResponse(LogoutStatus.SUCCESS); + + + } @Getter @@ -436,7 +457,7 @@ private static class MemberLoginRequest { @Setter @Getter - private class UpdateMemberAddressRequest { + private static class UpdateMemberAddressRequest { @NonNull private String address; @NonNull diff --git a/src/main/java/com/delfood/controller/OwnerController.java b/src/main/java/com/delfood/controller/OwnerController.java index 3c24f78..32baaff 100644 --- a/src/main/java/com/delfood/controller/OwnerController.java +++ b/src/main/java/com/delfood/controller/OwnerController.java @@ -2,8 +2,8 @@ import com.delfood.dto.OwnerDTO; import com.delfood.dto.OwnerDTO.Status; -import com.delfood.mapper.DMLOperationError; import com.delfood.service.OwnerService; +import com.delfood.utils.SessionUtil; import javax.servlet.http.HttpSession; import lombok.AllArgsConstructor; import lombok.Getter; @@ -93,7 +93,7 @@ public ResponseEntity login(@RequestBody OwnerLoginRequest l Status ownerStatus = ownerInfo.getStatus(); if (ownerStatus == Status.DEFAULT) { ownerLoginResponse = OwnerLoginResponse.success(ownerInfo); - session.setAttribute("LOGIN_OWNER_ID", ownerInfo.getId()); + SessionUtil.setLoginOwnerId(session, loginRequest.getId()); responseEntity = new ResponseEntity(ownerLoginResponse, HttpStatus.OK); } else { ownerLoginResponse = OwnerLoginResponse.DELETED; @@ -112,14 +112,14 @@ public ResponseEntity login(@RequestBody OwnerLoginRequest l * @return */ @GetMapping("logout") - public ResponseEntity logout(HttpSession session) { - String id = (String) session.getAttribute("LOGIN_OWNER_ID"); + public ResponseEntity logout(HttpSession session) { + String id = SessionUtil.getLoginOwnerId(session); if (id != null) { - session.invalidate(); - return new ResponseEntity(logoutResponse.SUCCESS, + SessionUtil.logoutOwner(session); + return new ResponseEntity(LogoutResponse.SUCCESS, HttpStatus.OK); } else { - return new ResponseEntity(logoutResponse.NO_LOGIN, + return new ResponseEntity(LogoutResponse.NO_LOGIN, HttpStatus.UNAUTHORIZED); } } @@ -134,7 +134,7 @@ public ResponseEntity logout(HttpSession session) { @GetMapping("myInfo") public ResponseEntity ownerInfo(HttpSession session) { ResponseEntity responseEntity = null; - String id = (String) session.getAttribute("LOGIN_OWNER_ID"); + String id = SessionUtil.getLoginOwnerId(session); if (id == null) { responseEntity = new ResponseEntity(HttpStatus.UNAUTHORIZED); } else { @@ -158,7 +158,7 @@ public ResponseEntity updateOwnerInfo( String mail = updateRequest.getMail(); String tel = updateRequest.getTel(); String password = updateRequest.getPassword(); - String id = (String) session.getAttribute("LOGIN_OWNER_ID"); + String id = SessionUtil.getLoginOwnerId(session); if (id == null) { // 로그인 상태가 아닌 경우 return new ResponseEntity( @@ -175,14 +175,9 @@ public ResponseEntity updateOwnerInfo( UpdateOwnerResponse.EMPTY_CONTENT, HttpStatus.BAD_REQUEST); } - DMLOperationError dmlOperationError = ownerService.updateOwnerMailAndTel(id, mail, tel); - if (dmlOperationError == DMLOperationError.SUCCESS) { - return new ResponseEntity( - UpdateOwnerResponse.SUCCESS, HttpStatus.OK); - } else { - log.error("Member mail and tel update ERROR : {}", updateRequest); - throw new RuntimeException("Member mail and tel update ERROR"); - } + ownerService.updateOwnerMailAndTel(id, mail, tel); + return new ResponseEntity( + UpdateOwnerResponse.SUCCESS, HttpStatus.OK); } /** @@ -195,7 +190,7 @@ public ResponseEntity updateOwnerInfo( @PatchMapping("password") public ResponseEntity updatePassword( @RequestBody UpdateOwnerPasswordRequest passwordResquest, HttpSession session) { - String id = (String) session.getAttribute("LOGIN_OWNER_ID"); + String id = SessionUtil.getLoginOwnerId(session); String password = passwordResquest.getPassword(); String newPassword = passwordResquest.getNewPassword(); @@ -215,16 +210,9 @@ public ResponseEntity updatePassword( responseEntity = new ResponseEntity( UpdateOwnerResponse.PASSWORD_DUPLICATED, HttpStatus.CONFLICT); } else { - DMLOperationError dmlOperationError = ownerService.updateOwnerPassword(id, newPassword); - - if (DMLOperationError.SUCCESS.equals(dmlOperationError)) { - responseEntity = new ResponseEntity( - UpdateOwnerResponse.SUCCESS, HttpStatus.OK); - } else { - log.error("Password Update Error {}", passwordResquest); - throw new RuntimeException("Password Update Error"); - } - + ownerService.updateOwnerPassword(id, newPassword); + responseEntity = new ResponseEntity( + UpdateOwnerResponse.SUCCESS, HttpStatus.OK); } return responseEntity; } @@ -344,16 +332,16 @@ enum UpdateStatus { @Getter @RequiredArgsConstructor - private static class logoutResponse { - enum logoutStatus { + private static class LogoutResponse { + enum LogoutStatus { SUCCESS, NO_LOGIN } @NonNull - private logoutStatus result; + private LogoutStatus result; - private static final logoutResponse SUCCESS = new logoutResponse(logoutStatus.SUCCESS); - private static final logoutResponse NO_LOGIN = new logoutResponse(logoutStatus.NO_LOGIN); + private static final LogoutResponse SUCCESS = new LogoutResponse(LogoutStatus.SUCCESS); + private static final LogoutResponse NO_LOGIN = new LogoutResponse(LogoutStatus.NO_LOGIN); } diff --git a/src/main/java/com/delfood/controller/ShopController.java b/src/main/java/com/delfood/controller/ShopController.java index 802f849..1b29939 100644 --- a/src/main/java/com/delfood/controller/ShopController.java +++ b/src/main/java/com/delfood/controller/ShopController.java @@ -1,19 +1,25 @@ package com.delfood.controller; -import com.delfood.dto.ShopDTO; -import com.delfood.service.ShopService; +import java.util.List; import javax.servlet.http.HttpSession; -import lombok.Getter; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.lang.Nullable; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import com.delfood.dto.ShopDTO; +import com.delfood.service.ShopService; +import com.delfood.utils.SessionUtil; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.extern.log4j.Log4j2; @RestController @RequestMapping("/owners/shops/") @@ -31,47 +37,99 @@ public class ShopController { * @return */ @PostMapping - public ResponseEntity openShop(HttpSession session, + public ResponseEntity addShop(HttpSession session, @RequestBody ShopDTO shopInfo) { - String ownerId = (String) session.getAttribute("LOGIN_OWNER_ID"); + String ownerId = SessionUtil.getLoginOwnerId(session); // 로그인 하지 않았을 시 401코드를 반환한다. if (ownerId == null) { - return new ResponseEntity(OpenShopResponse.NO_LOGIN, + return new ResponseEntity(AddShopResponse.NO_LOGIN, HttpStatus.UNAUTHORIZED); } - + shopInfo.setOwnerId(ownerId); // 입력한 데이터 중 필수 데이터가 null일 경우 400 에러코드를 반환한다. if (ShopDTO.hasNullDataBeforeCreate(shopInfo)) { - return new ResponseEntity(OpenShopResponse.NULL_ARGUMENTS, + return new ResponseEntity(AddShopResponse.NULL_ARGUMENTS, HttpStatus.BAD_REQUEST); } - shopService.newShop(shopInfo); + shopService.addShop(shopInfo); - return new ResponseEntity(OpenShopResponse.SUCCESS, + return new ResponseEntity(AddShopResponse.SUCCESS, HttpStatus.CREATED); } + /** + * 사장님이 가진 매장들을 불러온다. + * + * @param myShopsRequest 페이징 정보 + * @param session 사용자의 세션 + * @return 페이지에 따른 사장님 매장, 총 매장 개수 + */ + @GetMapping + public ResponseEntity myShops(MyShopsRequest myShopsRequest, + HttpSession session) { + String id = SessionUtil.getLoginOwnerId(session); + if (id == null) { + return new ResponseEntity(MyShopsResponse.NO_LOGIN, HttpStatus.UNAUTHORIZED); + } + + List myShops = shopService.getMyShops(id, myShopsRequest.getLastId()); + long myShopCount = shopService.getMyShopCount(id); + return new ResponseEntity(MyShopsResponse.success(myShops, myShopCount), + HttpStatus.OK); + } + // Response 객체 @Getter @RequiredArgsConstructor - private static class OpenShopResponse { + private static class AddShopResponse { enum Result { SUCCESS, NO_LOGIN, NULL_ARGUMENTS } @NonNull Result result; - - private static OpenShopResponse SUCCESS = new OpenShopResponse(Result.SUCCESS); - private static OpenShopResponse NO_LOGIN = new OpenShopResponse(Result.NO_LOGIN); - private static OpenShopResponse NULL_ARGUMENTS = new OpenShopResponse(Result.NULL_ARGUMENTS); + + private static final AddShopResponse SUCCESS = new AddShopResponse(Result.SUCCESS); + private static final AddShopResponse NO_LOGIN = new AddShopResponse(Result.NO_LOGIN); + private static final AddShopResponse NULL_ARGUMENTS = + new AddShopResponse(Result.NULL_ARGUMENTS); + } + + @Getter + @RequiredArgsConstructor + @AllArgsConstructor + private static class MyShopsResponse { + enum Result { + SUCCESS, NO_LOGIN + } + + @NonNull + Result result; + + List myShops; + + Long shopCount; + + private static final MyShopsResponse NO_LOGIN = new MyShopsResponse(Result.NO_LOGIN); + + public static MyShopsResponse success(List myShops, Long shopCount) { + return new MyShopsResponse(Result.SUCCESS, myShops, shopCount); + } + } + + // Request 객체 + @Getter + @Setter + private static class MyShopsRequest { + @Nullable + private Long lastId; } } diff --git a/src/main/java/com/delfood/dto/MenuCategoryDTO.java b/src/main/java/com/delfood/dto/MenuCategoryDTO.java index b9cbb18..51578f6 100644 --- a/src/main/java/com/delfood/dto/MenuCategoryDTO.java +++ b/src/main/java/com/delfood/dto/MenuCategoryDTO.java @@ -9,11 +9,6 @@ @ToString public class MenuCategoryDTO { // 주력 메뉴 - // 한식, 분식, 카페, 일식, - // 치킨, 피자, 아시안, 양식, - // 중국집, 족발보쌈, 야식, 찜탕, - // 도시락, 패스트푸드, 프렌차이즈 - // KOREAN, SCHOOL_FOOD, CAFE, JAPANESE, // CHICKEN, PIZZA, ASIAN, WESTERN, // CHINESE, BOSSAM, MIDNIGHT_MEAL, SOUP, diff --git a/src/main/java/com/delfood/dto/OwnerDTO.java b/src/main/java/com/delfood/dto/OwnerDTO.java index d4f2473..b6d4837 100644 --- a/src/main/java/com/delfood/dto/OwnerDTO.java +++ b/src/main/java/com/delfood/dto/OwnerDTO.java @@ -32,7 +32,7 @@ public enum Status { private LocalDateTime updatedAt; private Status status; /** - * 회원가입 전 null 정보 체크 메서드 + * 회원가입 전 null 정보 체크 메서드. * @author jun * @param ownerInfo nullCheck할 사장님 정보 * @return null이 존재할 시 true diff --git a/src/main/java/com/delfood/dto/ShopDTO.java b/src/main/java/com/delfood/dto/ShopDTO.java index e70e074..1ebc105 100644 --- a/src/main/java/com/delfood/dto/ShopDTO.java +++ b/src/main/java/com/delfood/dto/ShopDTO.java @@ -116,7 +116,10 @@ public static boolean hasNullDataBeforeCreate(ShopDTO shopInfo) { || shopInfo.getBizNumber() == null || shopInfo.getInfo() == null || shopInfo.getMinOrderPrice() == null - || shopInfo.getOrderType() == null) { + || shopInfo.getOrderType() == null + || shopInfo.getTel() == null + || shopInfo.getAddress() == null + || shopInfo.getAddressDetail() == null) { return true; } return false; diff --git a/src/main/java/com/delfood/mapper/DMLOperationError.java b/src/main/java/com/delfood/mapper/DMLOperationError.java deleted file mode 100644 index f31495b..0000000 --- a/src/main/java/com/delfood/mapper/DMLOperationError.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.delfood.mapper; - -// SUCCESS 빼고 에러발생시 아래 내용을 포함하여 throw Exception -public enum DMLOperationError { - SUCCESS, NONE_CHANGED, TOO_MANY_CHANGED, EMPTY_RESULT -} diff --git a/src/main/java/com/delfood/mapper/ShopMapper.java b/src/main/java/com/delfood/mapper/ShopMapper.java index 953ee8d..fc4e84f 100644 --- a/src/main/java/com/delfood/mapper/ShopMapper.java +++ b/src/main/java/com/delfood/mapper/ShopMapper.java @@ -6,6 +6,12 @@ @Repository public interface ShopMapper { + /** + * 매장 입점 신청을 한다. + * @author jun + * @param shopInfo 입점 신청 매장 정보 + * @return + */ public int insertShop(ShopDTO shopInfo); /** @@ -41,11 +47,20 @@ public interface ShopMapper { public ShopDTO findById(Long id); /** - * 사장 id로 가지고 있는 매장을 모두 조회한다.
- * 한 사장당 많은 매장을 가지기는 어려우므로 페이징 처리를 따로 하지는 않았다. + * 사장 id로 가지고 있는 매장을 조회한다.
* @author jun * @param ownerId 매장을 가진 사장의 id + * @param lastId 페이지 * @return */ - public List findByOwnerId(String ownerId); + public List findByOwnerId(String ownerId, Long lastId); + + /** + * 사장 id로 가지고 있는 매장의 개수를 조회한다. + * @author jun + * @param ownerId 사장님 id + * @return 매장 개수 + */ + public long countByOwnerId(String ownerId); + } diff --git a/src/main/java/com/delfood/service/MemberService.java b/src/main/java/com/delfood/service/MemberService.java index 1d3afaa..6c019b8 100644 --- a/src/main/java/com/delfood/service/MemberService.java +++ b/src/main/java/com/delfood/service/MemberService.java @@ -1,13 +1,15 @@ package com.delfood.service; import com.delfood.dto.MemberDTO; -import com.delfood.mapper.DMLOperationError; import com.delfood.mapper.MemberMapper; import com.delfood.utils.SHA256Util; +import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service +@Log4j2 public class MemberService { @Autowired private MemberMapper memberMapper; @@ -17,8 +19,7 @@ public MemberDTO getMemberInfo(String memberId) { } /** - * - 고객 회원가입 메서드 - * 비밀번호를 암호화하여 세팅한다. MyBatis에서 insert return값은 성공시 1이 리턴된다. return값은 검사하여 null값이면 + * - 고객 회원가입 메서드 비밀번호를 암호화하여 세팅한다. MyBatis에서 insert return값은 성공시 1이 리턴된다. return값은 검사하여 null값이면 * true, null이 아닐시 insert에 실패한 것이니 false를 반환한다 * * @param memberInfo 저장할 회원의 정보 @@ -28,13 +29,15 @@ public void insertMember(MemberDTO memberInfo) { int insertCount = memberMapper.insertMember(memberInfo); if (insertCount != 1) { + log.error("insertMember ERROR! {}", memberInfo); throw new RuntimeException( "insertMember ERROR! 회원가입 메서드를 확인해주세요\n" + "Params : " + memberInfo); } } /** - * 고객 로그인 메서드 + * 고객 로그인 메서드. + * * @param id 고객 아이디 * @param password 고객 비밀번호 * @return @@ -62,33 +65,29 @@ public boolean isDuplicatedId(String id) { * @param password 변경할 비밀번호 * @return */ - public DMLOperationError updateMemberPassword(String id, String password) { + @Transactional(rollbackFor = RuntimeException.class) + public void updateMemberPassword(String id, String password) { String cryptoPassword = SHA256Util.encryptSHA256(password); int result = memberMapper.updateMemberPassword(id, cryptoPassword); if (result == 1) { - return DMLOperationError.SUCCESS; // 원하는 1개의 데이터만 수정 - } else if (result == 0) { - return DMLOperationError.NONE_CHANGED; // 데이터가 수정되지 않음. WHERE 조건 확인 필요 - } else { - return DMLOperationError.TOO_MANY_CHANGED; // 데이터가 너무 많이 바뀜. WHERE 조건 확인 필요. + log.error("update Member ERROR! id : {}, pw : {}", id, password); + throw new RuntimeException("update Member Password ERROR!"); } } /** - * 회원 status를 'DELETED'로 변경한다 + * 회원 status를 'DELETED'로 변경한다. * * @param id 탈퇴할 회원의 아이디 * @return */ - public DMLOperationError deleteMember(String id) { + @Transactional(rollbackFor = RuntimeException.class) + public void deleteMember(String id) { int result = memberMapper.deleteMember(id); - if (result == 1) { - return DMLOperationError.SUCCESS; // 원하는 1개의 데이터만 수정 - } else if (result == 0) { - return DMLOperationError.NONE_CHANGED; // 데이터가 수정되지 않음. WHERE 조건 확인 필요 - } else { - return DMLOperationError.TOO_MANY_CHANGED; // 데이터가 너무 많이 바뀜. WHERE 조건 확인 필요. + if (result != 1) { + log.error("delete Member ERROR! id : {}" + id); + throw new RuntimeException("delete Member ERROR!"); } } @@ -100,15 +99,13 @@ public DMLOperationError deleteMember(String id) { * @param addressDetail 변경할 상세 주소 * @return */ - public DMLOperationError updateMemberAddress(String id, String address, String addressDetail) { + @Transactional(rollbackFor = RuntimeException.class) + public void updateMemberAddress(String id, String address, String addressDetail) { int result = memberMapper.updateMemberAddress(id, address, addressDetail); - if (result == 1) { - return DMLOperationError.SUCCESS; // 원하는 1개의 데이터만 수정 - } else if (result == 0) { - return DMLOperationError.NONE_CHANGED; // 데이터가 수정되지 않음. WHERE 조건 확인 필요 - } else { - return DMLOperationError.TOO_MANY_CHANGED; // 데이터가 너무 많이 바뀜. WHERE 조건 확인 필요. 정상적인 상황에서는 발생하지 - // 않음. + if (result != 1) { + log.error("update Member address ERROR! id : {}, address : {}, addressDetail : {}", id, + address, addressDetail); + throw new RuntimeException("update Member address ERROR!"); } } diff --git a/src/main/java/com/delfood/service/OwnerService.java b/src/main/java/com/delfood/service/OwnerService.java index fe3bc2d..0ea8a2c 100644 --- a/src/main/java/com/delfood/service/OwnerService.java +++ b/src/main/java/com/delfood/service/OwnerService.java @@ -1,7 +1,6 @@ package com.delfood.service; import com.delfood.dto.OwnerDTO; -import com.delfood.mapper.DMLOperationError; import com.delfood.mapper.OwnerMapper; import com.delfood.utils.SHA256Util; import lombok.extern.log4j.Log4j2; @@ -17,7 +16,7 @@ public class OwnerService { OwnerMapper ownerMapper; /** - * 사장님 회원 가입 메서드 + * 사장님 회원 가입 메서드. * * @author jun * @param ownerInfo 가입할 사장님의 정보 @@ -33,7 +32,7 @@ public void signUp(OwnerDTO ownerInfo) { } /** - * 사장님 id 중복 체크 메서드 + * 사장님 id 중복 체크 메서드. * * @author jun * @param id 중복 체크할 id @@ -76,14 +75,11 @@ public OwnerDTO getOwner(String id) { * @return */ @Transactional(rollbackFor = RuntimeException.class) - public DMLOperationError updateOwnerMailAndTel(String id, String mail, String tel) { + public void updateOwnerMailAndTel(String id, String mail, String tel) { int result = ownerMapper.updateMailAndTel(id, mail, tel); - if (result == 1) { - return DMLOperationError.SUCCESS; // 정상 수행 - } else if (result == 0) { - return DMLOperationError.NONE_CHANGED; // 데이터가 변경되지 않음 - } else { - throw new RuntimeException("password update error : " + DMLOperationError.TOO_MANY_CHANGED); + if (result != 1) { + log.error("updateOwnerMailAndTel ERROR! id : {}, mail : {}, tel : {}", id, mail, tel); + throw new RuntimeException("password update error"); } } @@ -95,15 +91,12 @@ public DMLOperationError updateOwnerMailAndTel(String id, String mail, String te * @return */ @Transactional(rollbackFor = RuntimeException.class) // runtimeException이 발생하면 rollback을 수행한다. - public DMLOperationError updateOwnerPassword(String id, String password) { + public void updateOwnerPassword(String id, String password) { String cryptoPassword = SHA256Util.encryptSHA256(password); int result = ownerMapper.updatePassword(id, cryptoPassword); - if (result == 1) { - return DMLOperationError.SUCCESS; - } else if (result == 0) { - return DMLOperationError.NONE_CHANGED; - } else { - throw new RuntimeException("password update error : " + DMLOperationError.TOO_MANY_CHANGED); + if (result != 1) { + log.error("updateOwnerPassword ERROR! id : {}, password : {}", id, password); + throw new RuntimeException("password update error"); } } diff --git a/src/main/java/com/delfood/service/ShopService.java b/src/main/java/com/delfood/service/ShopService.java index c568e03..88aeeb0 100644 --- a/src/main/java/com/delfood/service/ShopService.java +++ b/src/main/java/com/delfood/service/ShopService.java @@ -1,11 +1,12 @@ package com.delfood.service; import com.delfood.dto.ShopDTO; -import com.delfood.mapper.DMLOperationError; import com.delfood.mapper.ShopMapper; import lombok.extern.log4j.Log4j2; +import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @Log4j2 @@ -19,11 +20,31 @@ public class ShopService { * @param shopInfo 삽입할 매장의 데이터 * @return */ - public void newShop(ShopDTO shopInfo) { + @Transactional(rollbackFor = RuntimeException.class) + public void addShop(ShopDTO shopInfo) { int insertShop = shopMapper.insertShop(shopInfo); if (insertShop != 1) { log.error("insert ERROR - {}", shopInfo); throw new RuntimeException("Shop insert ERROR"); } } + + /** + * 사장님 가게들의 정보를 불러오는 메서드. + * @param ownerId 사장님 id + * @param lastId 마지막으로 조회한 매장 id + * @return + */ + public List getMyShops(String ownerId, Long lastId) { + return shopMapper.findByOwnerId(ownerId, lastId); + } + + /** + * 사장님이 가진 총 가게 개수를 불러오는 메서드. + * @param ownerId 사장님 아이디 + * @return + */ + public long getMyShopCount(String ownerId) { + return shopMapper.countByOwnerId(ownerId); + } } diff --git a/src/main/java/com/delfood/utils/SessionUtil.java b/src/main/java/com/delfood/utils/SessionUtil.java new file mode 100644 index 0000000..79db788 --- /dev/null +++ b/src/main/java/com/delfood/utils/SessionUtil.java @@ -0,0 +1,87 @@ +package com.delfood.utils; + +import javax.servlet.http.HttpSession; + +public class SessionUtil { + + private static final String LOGIN_MEMBER_ID = "LOGIN_MEMBER_ID"; + private static final String LOGIN_OWNER_ID = "LOGIN_OWNER_ID"; + + // 인스턴스화 방지 + private SessionUtil() {} + + /** + * 로그인한 고객의 아이디를 세션에서 꺼낸다. + * @author jun + * @param session 사용자의 세션 + * @return 로그인한 고객의 id 또는 null + */ + public static String getLoginMemberId(HttpSession session) { + return (String) session.getAttribute(LOGIN_MEMBER_ID); + } + + /** + * 로그인 한 고객의 id를 세션에 저장한다. + * @author jun + * @param session 사용자의 session + * @param id 로그인한 고객의 id + */ + public static void setLoginMemberId(HttpSession session, String id) { + session.setAttribute(LOGIN_MEMBER_ID, id); + } + + + + + /** + * 로그인한 사장님 id를 세션에서 꺼낸다. + * 로그인 하지 않았다면 null이 반환된다 + * @author jun + * @param session 사용자의 세션 + * @return 로그인한 사장님 id 또는 null + */ + public static String getLoginOwnerId(HttpSession session) { + return (String) session.getAttribute(LOGIN_OWNER_ID); + } + + /** + * 로그인한 사장님의 id를 세션에 저장한다. + * @author jun + * @param session 사용자의 세션 + * @param id 로그인한 사장님 id + */ + public static void setLoginOwnerId(HttpSession session, String id) { + session.setAttribute(LOGIN_OWNER_ID, id); + } + + + /** + * 해당 세션의 정보를 모두 삭제한다. + * @author jun + * @param session 사용자의 세션 + */ + public static void logoutAll(HttpSession session) { + session.invalidate(); + } + + /** + * 고객 로그인 정보를 삭제한다. + * @author jun + * @param session 사용자의 세션 + */ + public static void logoutMember(HttpSession session) { + session.removeAttribute(LOGIN_MEMBER_ID); + } + + /** + * 사장님 로그인 정보를 삭제한다. + * @author jun + * @param session 사용자의 세션 + */ + public static void logoutOwner(HttpSession session) { + session.removeAttribute(LOGIN_OWNER_ID); + } + + + +} diff --git a/src/main/resources/mybatis/mapper/member.xml b/src/main/resources/mybatis/mapper/member.xml index 2d0082a..1d2238b 100644 --- a/src/main/resources/mybatis/mapper/member.xml +++ b/src/main/resources/mybatis/mapper/member.xml @@ -1,8 +1,8 @@ - - + + - INSERT INTO MEMBER(id, password, name, tel, mail) - VALUES(#{id}, #{password}, #{name}, #{tel}, #{mail}) + INSERT INTO MEMBER(id, password, name, tel, mail) + VALUES(#{id}, #{password}, #{name}, #{tel}, #{mail}) - UPDATE MEMBER - SET password = #{password} - WHERE id=#{id} + UPDATE MEMBER + SET password = #{password} + WHERE id=#{id} - UPDATE MEMBER - SET status = 'DELETE' - WHERE id=#{id} + UPDATE MEMBER + SET status = 'DELETE' + WHERE id=#{id} - UPDATE MEMBER - SET address = #{address}, - address_detail = #{addressDetail} - WHERE id = #{id} + UPDATE MEMBER + SET address = #{address}, + address_detail = #{addressDetail} + WHERE id = #{id} diff --git a/src/main/resources/mybatis/mapper/shop.xml b/src/main/resources/mybatis/mapper/shop.xml index 1f8c64d..f4ca452 100644 --- a/src/main/resources/mybatis/mapper/shop.xml +++ b/src/main/resources/mybatis/mapper/shop.xml @@ -20,7 +20,7 @@ created_at createdAt, updated_at updatedAt, status, - oreder_type orderType, + order_type orderType, origin_info originInfo, work_condition workCondition FROM SHOP @@ -58,13 +58,15 @@ WHERE id = #{id} - - WHERE ownerId = #{ownerId} + WHERE owner_id = #{ownerId} + AND id > #{lastId} + LIMIT 10 - WHERE id = #{id} @@ -92,4 +94,11 @@ WHERE id = #{id} + + +