Merge branch 'main' into yoon
This commit is contained in:
commit
1643a5fc7c
@ -14,11 +14,12 @@
|
|||||||
*************************************************************/
|
*************************************************************/
|
||||||
package io.company.localhost.common.dto;
|
package io.company.localhost.common.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
public class ApiResponse<T> {
|
public class ApiResponse<T> {
|
||||||
private int code;
|
private int code;
|
||||||
private HttpStatus status;
|
private HttpStatus status;
|
||||||
@ -47,6 +48,11 @@ public class ApiResponse<T> {
|
|||||||
public static <T> ApiResponse<T> error(HttpStatus status, String message) {
|
public static <T> ApiResponse<T> error(HttpStatus status, String message) {
|
||||||
return new ApiResponse<>(status, message, null);
|
return new ApiResponse<>(status, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> ApiResponse<T> error(int code,HttpStatus status, String message) {
|
||||||
|
return new ApiResponse<>(code,status, message, null);
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> ApiResponse<T> okMessage(String message) {
|
public static <T> ApiResponse<T> okMessage(String message) {
|
||||||
return new ApiResponse<>(HttpStatus.OK, message, null);
|
return new ApiResponse<>(HttpStatus.OK, message, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,10 +26,10 @@ public enum UserErrorCode implements ErrorCode {
|
|||||||
|
|
||||||
NOT_AUTH_USER(HttpStatus.UNAUTHORIZED ,"로그인이 필요합니다."),
|
NOT_AUTH_USER(HttpStatus.UNAUTHORIZED ,"로그인이 필요합니다."),
|
||||||
INACTIVE_USER(HttpStatus.FORBIDDEN,"권한이 필요합니다."),
|
INACTIVE_USER(HttpStatus.FORBIDDEN,"권한이 필요합니다."),
|
||||||
USER_NOT_FOUND(HttpStatus.UNAUTHORIZED,"아이디 혹은 비밀번호가 틀렸습니다."),
|
USER_NOT_FOUND(10001,HttpStatus.UNAUTHORIZED,"아이디 혹은 비밀번호가 틀렸습니다."),
|
||||||
NOT_AUTHORIZED(HttpStatus.UNAUTHORIZED,"비인가 계정입니다."),
|
NOT_AUTHORIZED(10002,HttpStatus.UNAUTHORIZED,"비인가 계정입니다."),
|
||||||
EXIT_USER(HttpStatus.UNAUTHORIZED,"탈퇴한 계정입니다."),
|
EXIT_USER(10003,HttpStatus.UNAUTHORIZED,"탈퇴한 계정입니다."),
|
||||||
BAD_CREDENTIAL(HttpStatus.UNAUTHORIZED, "아이디 혹은 비밀번호 문제")
|
BAD_CREDENTIAL(10004,HttpStatus.UNAUTHORIZED, "아이디 혹은 비밀번호 문제")
|
||||||
;
|
;
|
||||||
|
|
||||||
private final long code;
|
private final long code;
|
||||||
@ -43,8 +43,12 @@ public enum UserErrorCode implements ErrorCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ApiResponse<?> getApiResponse() {
|
public ApiResponse<?> getApiResponse() {
|
||||||
|
if(this.code > 10000){
|
||||||
|
return ApiResponse.error((int) this.getCode(),this.getHttpStatus() , this.getMessage());
|
||||||
|
}else{
|
||||||
return ApiResponse.error(this.getHttpStatus() , this.getMessage());
|
return ApiResponse.error(this.getHttpStatus() , this.getMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ApiResponse<?> getApiResponse(String message) {
|
public ApiResponse<?> getApiResponse(String message) {
|
||||||
return ApiResponse.error(this.getHttpStatus() , message);
|
return ApiResponse.error(this.getHttpStatus() , message);
|
||||||
|
|||||||
@ -15,6 +15,8 @@
|
|||||||
package io.company.localhost.common.security.handler;
|
package io.company.localhost.common.security.handler;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import io.company.localhost.common.dto.ApiResponse;
|
||||||
|
import io.company.localhost.common.exception.code.UserErrorCode;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -24,8 +26,6 @@ import org.springframework.security.web.authentication.AuthenticationFailureHand
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Component("failHandler")
|
@Component("failHandler")
|
||||||
public class MemberAuthFailureHandler implements AuthenticationFailureHandler {
|
public class MemberAuthFailureHandler implements AuthenticationFailureHandler {
|
||||||
@ -36,30 +36,18 @@ public class MemberAuthFailureHandler implements AuthenticationFailureHandler {
|
|||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
|
||||||
Map<String, Object> responseMap = new HashMap<>();
|
|
||||||
responseMap.put("success", false); // 로그인 실패 표시
|
|
||||||
|
|
||||||
String message = exception.getMessage();
|
String message = exception.getMessage();
|
||||||
String errorCode;
|
|
||||||
String errorMessage;
|
ApiResponse<?> res = UserErrorCode.BAD_CREDENTIAL.getApiResponse();
|
||||||
|
|
||||||
if (exception instanceof BadCredentialsException || message.startsWith("NOT_FOUND")) {
|
if (exception instanceof BadCredentialsException || message.startsWith("NOT_FOUND")) {
|
||||||
errorCode = "USER_NOT_FOUND";
|
res = UserErrorCode.USER_NOT_FOUND.getApiResponse();
|
||||||
errorMessage = "아이디 또는 비밀번호가 일치하지 않습니다.";
|
|
||||||
} else if (message.startsWith("NOT_AUTHORIZED")) {
|
} else if (message.startsWith("NOT_AUTHORIZED")) {
|
||||||
errorCode = "NOT_AUTHORIZED";
|
res = UserErrorCode.NOT_AUTH_USER.getApiResponse();
|
||||||
errorMessage = "접근 권한이 없습니다.";
|
|
||||||
} else if (message.startsWith("EXIT")) {
|
} else if (message.startsWith("EXIT")) {
|
||||||
errorCode = "EXIT_USER";
|
res = UserErrorCode.EXIT_USER.getApiResponse();
|
||||||
errorMessage = "탈퇴한 사용자입니다.";
|
|
||||||
} else {
|
|
||||||
errorCode = "BAD_CREDENTIAL";
|
|
||||||
errorMessage = "인증에 실패했습니다.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
responseMap.put("code", errorCode);
|
response.getWriter().write(mapper.writeValueAsString(res));
|
||||||
responseMap.put("message", errorMessage);
|
|
||||||
|
|
||||||
response.getWriter().write(mapper.writeValueAsString(responseMap));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -100,20 +100,23 @@ public class VacationController {
|
|||||||
List<MapDto> addRequests = map.getList("add", MapDto.class);
|
List<MapDto> addRequests = map.getList("add", MapDto.class);
|
||||||
List<Long> deleteIds = map.getList("delete", Long.class);
|
List<Long> deleteIds = map.getList("delete", Long.class);
|
||||||
|
|
||||||
if (addRequests != null) {
|
// 1️⃣ 삭제 먼저 처리
|
||||||
|
if (deleteIds != null && !deleteIds.isEmpty()) {
|
||||||
|
localVacaService.deleteVacation(deleteIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2️⃣ 추가 또는 업데이트 처리
|
||||||
|
if (addRequests != null && !addRequests.isEmpty()) {
|
||||||
for (MapDto addRequest : addRequests) {
|
for (MapDto addRequest : addRequests) {
|
||||||
addRequest.put("employeeId", user);
|
addRequest.put("employeeId", user);
|
||||||
localVacaService.insertVacation(addRequest);
|
localVacaService.upsertVacation(addRequest);
|
||||||
}
|
|
||||||
}
|
|
||||||
if (deleteIds != null) {
|
|
||||||
for (Long deleteId : deleteIds) {
|
|
||||||
localVacaService.deleteVacation(deleteId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ApiResponse.ok("휴가 변경이 성공적으로 처리되었습니다.");
|
return ApiResponse.ok("휴가 변경이 성공적으로 처리되었습니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 전체 사원의 휴가 조회
|
* 전체 사원의 휴가 조회
|
||||||
* @param year, month
|
* @param year, month
|
||||||
|
|||||||
@ -26,7 +26,7 @@ import io.company.localhost.common.dto.MapDto;
|
|||||||
public interface localvacaMapper {
|
public interface localvacaMapper {
|
||||||
void insertVacation(MapDto map);
|
void insertVacation(MapDto map);
|
||||||
|
|
||||||
void deleteVacation(Long vacationId);
|
void deleteVacation(@Param("vacationIds") List<Long> vacationIds);
|
||||||
|
|
||||||
List<MapDto> selectVacations(@Param("year") int year, @Param("month") int month);
|
List<MapDto> selectVacations(@Param("year") int year, @Param("month") int month);
|
||||||
|
|
||||||
@ -37,6 +37,10 @@ public interface localvacaMapper {
|
|||||||
List<MapDto> selectEmployeeRemainingVacation();
|
List<MapDto> selectEmployeeRemainingVacation();
|
||||||
|
|
||||||
List<MapDto> selectSentVacationCount(MapDto map);
|
List<MapDto> selectSentVacationCount(MapDto map);
|
||||||
|
|
||||||
|
Long findVacationIdByDate(@Param("userId") Long employeeId, @Param("date") String date);
|
||||||
|
|
||||||
|
void updateVacation(MapDto vacation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import org.springframework.http.HttpMethod;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import io.company.localhost.common.dto.MapDto;
|
import io.company.localhost.common.dto.MapDto;
|
||||||
import io.company.localhost.mapper.localvacaMapper;
|
import io.company.localhost.mapper.localvacaMapper;
|
||||||
@ -53,9 +54,38 @@ public class localvacaService {
|
|||||||
localvacaMapper.insertVacation(vacation);
|
localvacaMapper.insertVacation(vacation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteVacation(Long vacationId) {
|
/**
|
||||||
localvacaMapper.deleteVacation(vacationId);
|
* 여러 개의 휴가를 삭제
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void deleteVacation(List<Long> vacationIds) {
|
||||||
|
if (vacationIds != null && !vacationIds.isEmpty()) {
|
||||||
|
localvacaMapper.deleteVacation(vacationIds);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 휴가 추가 또는 업데이트 (중복 검사 후 처리)
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void upsertVacation(MapDto vacation) {
|
||||||
|
String date = vacation.getString("date");
|
||||||
|
Long employeeId = vacation.getLong("employeeId");
|
||||||
|
|
||||||
|
// 기존 데이터 확인
|
||||||
|
Long existingId = localvacaMapper.findVacationIdByDate(employeeId, date);
|
||||||
|
|
||||||
|
if (existingId != null) {
|
||||||
|
// 기존 휴가가 존재하면 업데이트
|
||||||
|
vacation.put("id", existingId);
|
||||||
|
localvacaMapper.updateVacation(vacation);
|
||||||
|
} else {
|
||||||
|
System.out.println(vacation);
|
||||||
|
// 기존 휴가가 없으면 새롭게 추가
|
||||||
|
localvacaMapper.insertVacation(vacation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<MapDto> selectVacationList(int year, int month) {
|
public List<MapDto> selectVacationList(int year, int month) {
|
||||||
return localvacaMapper.selectVacations(year, month);
|
return localvacaMapper.selectVacations(year, month);
|
||||||
|
|||||||
@ -8,10 +8,27 @@
|
|||||||
VALUES (#{employeeId}, #{date}, #{type}, NOW(), #{receiverId})
|
VALUES (#{employeeId}, #{date}, #{type}, NOW(), #{receiverId})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<!-- 휴가 데이터 삭제 -->
|
<!-- 특정 날짜의 휴가 ID 조회 (존재 여부 확인) -->
|
||||||
<delete id="deleteVacation" parameterType="long">
|
<select id="findVacationIdByDate" resultType="Long">
|
||||||
|
SELECT LOCVACSEQ
|
||||||
|
FROM localvaca
|
||||||
|
WHERE MEMBERSEQ = #{userId} AND LOCVACUDT = #{date}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 휴가 수정 (기존 데이터가 존재하는 경우) -->
|
||||||
|
<update id="updateVacation">
|
||||||
|
UPDATE localvaca
|
||||||
|
SET LOCVACTYP = #{type}
|
||||||
|
WHERE LOCVACSEQ = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!-- ✅ 여러 개의 휴가 삭제 -->
|
||||||
|
<delete id="deleteVacation">
|
||||||
DELETE FROM localvaca
|
DELETE FROM localvaca
|
||||||
WHERE LOCVACSEQ = #{vacationId}
|
WHERE LOCVACSEQ IN
|
||||||
|
<foreach item="id" collection="vacationIds" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<!-- 휴가 정보 조회 -->
|
<!-- 휴가 정보 조회 -->
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user