This commit is contained in:
nevermoregb 2025-02-13 11:44:32 +09:00
commit 0d6594b439
16 changed files with 275 additions and 95 deletions

View File

@ -10,6 +10,7 @@
* DATE AUTHOR NOTE * DATE AUTHOR NOTE
* ----------------------------------------------------------- * -----------------------------------------------------------
* 24.12.06 조인제 최초 생성 * 24.12.06 조인제 최초 생성
* 25.02.10 서지희 InvalidPasswordException추가
* *
*************************************************************/ *************************************************************/
package io.company.localhost.common.exception; package io.company.localhost.common.exception;
@ -28,26 +29,52 @@ import lombok.extern.slf4j.Slf4j;
@RestControllerAdvice(annotations = RestController.class) @RestControllerAdvice(annotations = RestController.class)
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(RestApiException.class) /**
public ResponseEntity<Object> handleCustomException(RestApiException e) { * 사용자 정의 API 예외 처리 (RestApiException)
ErrorCode errorCode = e.getErrorCode(); */
return ErrorResult.handleExceptionInternal(errorCode); @ExceptionHandler(RestApiException.class)
} public ResponseEntity<Object> handleCustomException(RestApiException e) {
ErrorCode errorCode = e.getErrorCode();
return ErrorResult.handleExceptionInternal(errorCode);
}
@ExceptionHandler(IllegalArgumentException.class) /**
public ResponseEntity<Object> handleIllegalArgument(IllegalArgumentException e) { * 잘못된 요청 (IllegalArgumentException) 처리
log.warn("handleIllegalArgument", e); */
ErrorCode errorCode = CommonErrorCode.INVALID_PARAMETER; @ExceptionHandler(IllegalArgumentException.class)
return ErrorResult.handleExceptionInternal(errorCode, e.getMessage()); public ResponseEntity<Object> handleIllegalArgument(IllegalArgumentException e) {
} log.warn("handleIllegalArgument", e);
ErrorCode errorCode = CommonErrorCode.INVALID_PARAMETER;
return ErrorResult.handleExceptionInternal(errorCode, e.getMessage());
}
/**
* 게시물을 찾을 없는 경우 (NotFoundHandler)
*/
@ExceptionHandler(NotFoundHandler.class)
public ResponseEntity<Object> handleBoardNotFoundException(NotFoundHandler e) {
log.warn("handleBoardNotFoundException: {}", e.getMessage());
ErrorCode errorCode = CommonErrorCode.RESOURCE_NOT_FOUND;
return ErrorResult.handleExceptionInternal(errorCode, e.getMessage());
}
@ExceptionHandler({Exception.class}) /**
public ResponseEntity<Object> handleAllException(Exception ex) { * 비밀번호가 틀린 경우 예외 처리 (InvalidPasswordException)
log.warn("handleAllException", ex); */
ErrorCode errorCode = CommonErrorCode.INTERNAL_SERVER_ERROR; @ExceptionHandler(InvalidPasswordException.class)
return ErrorResult.handleExceptionInternal(errorCode); public ResponseEntity<Object> handleInvalidPasswordException(InvalidPasswordException e) {
} log.warn("handleInvalidPasswordException: {}", e.getMessage());
ErrorCode errorCode = CommonErrorCode.UNAUTHORIZED;
return ErrorResult.handleExceptionInternal(errorCode, e.getMessage());
}
/**
* 서버 내부 오류 처리 (Exception)
*/
@ExceptionHandler({Exception.class})
public ResponseEntity<Object> handleAllException(Exception ex) {
log.warn("handleAllException", ex);
ErrorCode errorCode = CommonErrorCode.INTERNAL_SERVER_ERROR;
return ErrorResult.handleExceptionInternal(errorCode);
}
} }

View File

@ -0,0 +1,7 @@
package io.company.localhost.common.exception;
public class InvalidPasswordException extends RuntimeException {
public InvalidPasswordException(String message) {
super(message);
}
}

View File

@ -25,15 +25,8 @@ import io.company.localhost.common.exception.code.CommonErrorCode;
import io.company.localhost.common.exception.code.ErrorCode; import io.company.localhost.common.exception.code.ErrorCode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Slf4j public class NotFoundHandler extends RuntimeException {
@RestControllerAdvice public NotFoundHandler(String message) {
public class NotFoundHandler { super(message);
}
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NoHandlerFoundException.class)
public ResponseEntity<Object> noHandlerFoundArgument(NoHandlerFoundException e) {
log.warn("NoHandlerFoundException", e);
ErrorCode errorCode = CommonErrorCode.RESOURCE_NOT_FOUND;
return ErrorResult.handleExceptionInternal(errorCode, errorCode.getMessage());
}
} }

View File

@ -10,6 +10,7 @@
* DATE AUTHOR NOTE * DATE AUTHOR NOTE
* ----------------------------------------------------------- * -----------------------------------------------------------
* 24.12.06 조인제 최초 생성 * 24.12.06 조인제 최초 생성
* 24.02.10 서지희 비밀번호 불일치 권한없음 추가
* *
*************************************************************/ *************************************************************/
package io.company.localhost.common.exception.code; package io.company.localhost.common.exception.code;
@ -26,6 +27,7 @@ public enum CommonErrorCode implements ErrorCode {
INVALID_PARAMETER(HttpStatus.BAD_REQUEST,"잘못된 매개변수가 포함되었습니다."), INVALID_PARAMETER(HttpStatus.BAD_REQUEST,"잘못된 매개변수가 포함되었습니다."),
RESOURCE_NOT_FOUND(HttpStatus.NOT_FOUND,"리소스가 존재하지 않습니다"), RESOURCE_NOT_FOUND(HttpStatus.NOT_FOUND,"리소스가 존재하지 않습니다"),
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR,"내부 서버 오류"), INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR,"내부 서버 오류"),
UNAUTHORIZED(HttpStatus.UNAUTHORIZED,"권한없음"),
; ;
private final long code; private final long code;

View File

@ -80,7 +80,7 @@ public class SecurityConfig {
http http
.securityMatcher("/api/**") // '/api/**' 경로에 대해서만 보안 적용 .securityMatcher("/api/**") // '/api/**' 경로에 대해서만 보안 적용
.authorizeHttpRequests(auth -> auth .authorizeHttpRequests(auth -> auth
//.requestMatchers("/api/board/**").hasRole("MEMBER") .requestMatchers("/api/project/**").hasRole("MEMBER")
.requestMatchers("/api/**").permitAll() // 특정 엔드포인트 허용 .requestMatchers("/api/**").permitAll() // 특정 엔드포인트 허용
.anyRequest().authenticated() // 나머지 요청은 인증 필요 .anyRequest().authenticated() // 나머지 요청은 인증 필요
//auth.anyRequest().access(authorizationManager) // 모든 요청에 대해 권한 관리 //auth.anyRequest().access(authorizationManager) // 모든 요청에 대해 권한 관리

View File

@ -18,6 +18,7 @@ package io.company.localhost.controller.api;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.List; import java.util.List;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
@ -27,6 +28,8 @@ import io.company.localhost.common.annotation.ParameterCheck;
import io.company.localhost.common.annotation.ReqMap; import io.company.localhost.common.annotation.ReqMap;
import io.company.localhost.common.dto.ApiResponse; import io.company.localhost.common.dto.ApiResponse;
import io.company.localhost.common.dto.MapDto; import io.company.localhost.common.dto.MapDto;
import io.company.localhost.common.exception.InvalidPasswordException;
import io.company.localhost.common.exception.NotFoundHandler;
import io.company.localhost.service.commoncodService; import io.company.localhost.service.commoncodService;
import io.company.localhost.service.localbordService; import io.company.localhost.service.localbordService;
import io.company.localhost.utils.AuthUtil; import io.company.localhost.utils.AuthUtil;
@ -41,6 +44,7 @@ public class BoardController {
private final localbordService boardService; private final localbordService boardService;
private final commoncodService commoncodService; private final commoncodService commoncodService;
private final PasswordEncoder passwordEncoder;
/** /**
* 공지사항 목록 조회 * 공지사항 목록 조회
@ -76,8 +80,15 @@ public class BoardController {
@ParameterCheck @ParameterCheck
@PostMapping @PostMapping
public ApiResponse<BigInteger> createBoard(@ReqMap MapDto map) { public ApiResponse<BigInteger> createBoard(@ReqMap MapDto map) {
Long userId = AuthUtil.getUser().getId(); //Long userId = AuthUtil.getUser().getId();
map.put("MEMBERSEQ", userId); map.put("MEMBERSEQ", 22);
if (map.containsKey("LOCBRDPWD") && !map.getString("LOCBRDPWD").trim().isEmpty()) { // 체크
String rawPassword = map.getString("LOCBRDPWD");
String hashedPassword = passwordEncoder.encode(rawPassword);
map.put("LOCBRDPWD", hashedPassword);
}
return ApiResponse.ok(boardService.createBoard(map)); return ApiResponse.ok(boardService.createBoard(map));
} }
@ -90,7 +101,11 @@ public class BoardController {
@ParameterCheck @ParameterCheck
@GetMapping("/{boardId}") @GetMapping("/{boardId}")
public ApiResponse<MapDto> getBoardDetail(@PathVariable("boardId") Long boardId) { public ApiResponse<MapDto> getBoardDetail(@PathVariable("boardId") Long boardId) {
return ApiResponse.ok(boardService.getBoardDetail(boardId)); MapDto board = boardService.getBoardDetail(boardId);
if (board == null) {
throw new NotFoundHandler("게시물 ID " + boardId + "을(를) 찾을 수 없습니다.");
}
return ApiResponse.ok(board);
} }
/** /**
@ -128,8 +143,8 @@ public class BoardController {
@ParameterCheck @ParameterCheck
@PostMapping("/{CMNBRDSEQ}/attachments") @PostMapping("/{CMNBRDSEQ}/attachments")
public ApiResponse<String> uploadAttachment(@ReqMap MapDto map) { public ApiResponse<String> uploadAttachment(@ReqMap MapDto map) {
Long userId = AuthUtil.getUser().getId(); //Long userId = AuthUtil.getUser().getId();
map.put("CMNFLEREG", userId); map.put("CMNFLEREG", 22);
boardService.addAttachment(map); boardService.addAttachment(map);
return ApiResponse.ok("첨부파일이 저장되었습니다."); return ApiResponse.ok("첨부파일이 저장되었습니다.");
} }
@ -143,8 +158,8 @@ public class BoardController {
@ParameterCheck @ParameterCheck
@PostMapping("/{LOCBRDSEQ}/{LOCCMTSEQ}/reaction") @PostMapping("/{LOCBRDSEQ}/{LOCCMTSEQ}/reaction")
public ApiResponse<String> reactToBoard(@ReqMap MapDto map) { public ApiResponse<String> reactToBoard(@ReqMap MapDto map) {
Long userId = AuthUtil.getUser().getId(); //Long userId = AuthUtil.getUser().getId();
map.put("MEMBERSEQ", userId); map.put("MEMBERSEQ", 22);
boardService.reactToBoard(map); boardService.reactToBoard(map);
return ApiResponse.ok("반응이 성공적으로 처리되었습니다."); return ApiResponse.ok("반응이 성공적으로 처리되었습니다.");
} }
@ -171,8 +186,14 @@ public class BoardController {
@ParameterCheck @ParameterCheck
@PostMapping("/{LOCBRDSEQ}/comment") @PostMapping("/{LOCBRDSEQ}/comment")
public ApiResponse<String> addCommentOrReply(@ReqMap MapDto map) { public ApiResponse<String> addCommentOrReply(@ReqMap MapDto map) {
Long userId = AuthUtil.getUser().getId(); //Long userId = AuthUtil.getUser().getId();
map.put("MEMBERSEQ", userId); map.put("MEMBERSEQ", 22);
if (map.containsKey("LOCCMTPWD") && !map.getString("LOCCMTPWD").trim().isEmpty()) { // 체크
String rawPassword = map.getString("LOCCMTPWD");
String hashedPassword = passwordEncoder.encode(rawPassword);
map.put("LOCCMTPWD", hashedPassword);
}
boardService.addCommentOrReply(map); boardService.addCommentOrReply(map);
return ApiResponse.ok("댓글 또는 대댓글이 작성되었습니다."); return ApiResponse.ok("댓글 또는 대댓글이 작성되었습니다.");
} }
@ -205,20 +226,7 @@ public class BoardController {
} }
/** /**
* 댓글 비밀번호 확인 * 게시물 비밀번호 확인 (해싱된 비밀번호 비교 적용)
* @ReqMap map 수정 데이터 (LOCCMTSEQ, LOCCMTPWD)
* @return 비밀번호 확인 결과
*/
@Member
@ParameterCheck
@PostMapping("/comment/{commentId}/password")
public ApiResponse<Boolean> checkCommentPassword(@ReqMap MapDto map) {
int commentId = (int) map.get("LOCCMTPWD");
return ApiResponse.ok(boardService.getCommentPassword(commentId).equals(map.getString("LOCCMTPWD")));
}
/**
* 게시물 비밀번호 확인
* @ReqMap map 수정 데이터 (LOCBRDSEQ, LOCBRDPWD) * @ReqMap map 수정 데이터 (LOCBRDSEQ, LOCBRDPWD)
* @return 비밀번호 확인 결과 * @return 비밀번호 확인 결과
*/ */
@ -226,8 +234,62 @@ public class BoardController {
@ParameterCheck @ParameterCheck
@PostMapping("/{boardId}/password") @PostMapping("/{boardId}/password")
public ApiResponse<Boolean> checkBoardPassword(@ReqMap MapDto map) { public ApiResponse<Boolean> checkBoardPassword(@ReqMap MapDto map) {
int boardId = (int) map.get("LOCBRDSEQ"); // boardId 데이터 타입 변환
return ApiResponse.ok(boardService.getBoardPassword(boardId).equals(map.getString("LOCBRDPWD"))); Object boardIdObj = map.get("LOCBRDSEQ");
int boardId = 0;
if (boardIdObj instanceof Integer) {
boardId = (Integer) boardIdObj;
} else if (boardIdObj instanceof String) {
boardId = Integer.parseInt((String) boardIdObj);
}
String rawPassword = map.getString("LOCBRDPWD");
String storedHashedPassword = boardService.getBoardPassword(boardId);
if (storedHashedPassword == null) {
throw new NotFoundHandler("해당 게시물이 존재하지 않습니다.");
}
boolean isMatch = passwordEncoder.matches(rawPassword, storedHashedPassword);
if (!isMatch) {
throw new InvalidPasswordException("비밀번호가 일치하지 않습니다.");
}
return ApiResponse.ok(true);
}
/**
* 댓글 비밀번호 확인 (해싱된 비밀번호 비교 적용)
* @ReqMap map 수정 데이터 (LOCCMTSEQ, LOCCMTPWD)
* @return 비밀번호 확인 결과
*/
@Member
@ParameterCheck
@PostMapping("/comment/{commentId}/password")
public ApiResponse<Boolean> checkCommentPassword(@ReqMap MapDto map) {
// commentId 데이터 타입 변환
Object commentIdObj = map.get("LOCCMTSEQ");
int commentId = 0;
if (commentIdObj instanceof Integer) {
commentId = (Integer) commentIdObj;
} else if (commentIdObj instanceof String) {
commentId = Integer.parseInt((String) commentIdObj);
}
String rawPassword = map.getString("LOCCMTPWD");
String storedHashedPassword = boardService.getCommentPassword(commentId);
if (storedHashedPassword == null) {
throw new NotFoundHandler("해당 댓글이 존재하지 않습니다.");
}
boolean isMatch = passwordEncoder.matches(rawPassword, storedHashedPassword);
if (!isMatch) {
throw new InvalidPasswordException("비밀번호가 일치하지 않습니다.");
}
return ApiResponse.ok(true);
} }
/** /**

View File

@ -0,0 +1,51 @@
/************************************************************
*
* @packageName : io.company.localhost.controller.api
* @fileName : ProjectListController.java
* @author : 박지윤
* @date : 25.02.10
* @description : 프로젝트 목록
*
* ===========================================================
* DATE AUTHOR NOTE
* -----------------------------------------------------------
* 25.02.10 박지윤 최초 생성
*
*************************************************************/
package io.company.localhost.controller.api;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.company.localhost.common.annotation.ParameterCheck;
import io.company.localhost.common.dto.ApiResponse;
import io.company.localhost.common.dto.MapDto;
import io.company.localhost.service.commoncodService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@RestController
@RequestMapping("/api/project")
@RequiredArgsConstructor
@Slf4j
public class ProjectListController {
private final commoncodService commoncodservice;
/**
* 프로젝트 년도 조회
*
* @return ApiResponse<List<MapDto>>
*
*/
@ParameterCheck
@GetMapping("/yearCategory")
public ApiResponse<List<MapDto>> getYearCategories() {
List<MapDto> yearCategory = commoncodservice.getYearCategories();
return ApiResponse.ok(yearCategory);
}
}

View File

@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
import io.company.localhost.common.annotation.ReqMap; import io.company.localhost.common.annotation.ReqMap;
import io.company.localhost.common.dto.ApiResponse; import io.company.localhost.common.dto.ApiResponse;
import io.company.localhost.common.dto.MapDto; import io.company.localhost.common.dto.MapDto;
import io.company.localhost.service.commoncodService;
import io.company.localhost.service.localvacaService; // 서비스 클래스 경로 수정 import io.company.localhost.service.localvacaService; // 서비스 클래스 경로 수정
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -40,13 +41,12 @@ public class VacationController {
localVacaService.insertVacation(request); localVacaService.insertVacation(request);
} }
// 성공적으로 저장된 경우 응답 반환
return ApiResponse.ok("모든 휴가가 성공적으로 저장되었습니다."); return ApiResponse.ok("모든 휴가가 성공적으로 저장되었습니다.");
} }
/** /**
* 특정 연월에 대한 휴가 데이터 조회 * 특정 연월에 대한 휴가 데이터 조회
*/ */
@GetMapping("/list/{year}/{month}") @GetMapping("/list/{year}/{month}")
public List<MapDto> getVacations(@PathVariable("year") int year, @PathVariable("month") int month) { public List<MapDto> getVacations(@PathVariable("year") int year, @PathVariable("month") int month) {
@ -54,7 +54,7 @@ public class VacationController {
} }
/** /**
* 특정 연월에 대한 공휴일 데이터 조회 * 특정 연월에 대한 공휴일 데이터 조회
*/ */
@GetMapping("/{year}/{month}") @GetMapping("/{year}/{month}")
public List<MapDto> getHolidays(@PathVariable("year") int year, @PathVariable("month") int month) { public List<MapDto> getHolidays(@PathVariable("year") int year, @PathVariable("month") int month) {

View File

@ -109,7 +109,9 @@ public class worddictController {
public ApiResponse<Long> insertWord(@AuthenticationPrincipal MemberVo memberVo,@ReqMap MapDto map) { public ApiResponse<Long> insertWord(@AuthenticationPrincipal MemberVo memberVo,@ReqMap MapDto map) {
//userId //userId
Long userId = AuthUtil.getUser().getId(); //Long userId = AuthUtil.getUser().getId();
//임시
int userId = 38;
map.put("userId", userId); map.put("userId", userId);
Long result = worddictyservice.insertWord(map); Long result = worddictyservice.insertWord(map);
@ -126,7 +128,9 @@ public class worddictController {
public ApiResponse<Long> updateWord(@AuthenticationPrincipal MemberVo memberVo,@ReqMap MapDto map) { public ApiResponse<Long> updateWord(@AuthenticationPrincipal MemberVo memberVo,@ReqMap MapDto map) {
//userId //userId
Long userId = AuthUtil.getUser().getId(); //Long userId = AuthUtil.getUser().getId();
//임시
int userId = 38;
map.put("userId", userId); map.put("userId", userId);
Long result = worddictyservice.updateWord(map); Long result = worddictyservice.updateWord(map);

View File

@ -24,7 +24,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;

View File

@ -153,6 +153,18 @@ public class UserController {
return ApiResponse.ok(isPwReset); return ApiResponse.ok(isPwReset);
} }
/**
* 기존 비밀번호 체크
*
* @param map
* @return ApiResponse<Boolean>
*/
@PostMapping("/checkPassword")
public ApiResponse<Boolean> selectPassword(@ReqMap MapDto map) {
boolean isNewPassword = netmemberservice.selectPassword(map);
return ApiResponse.ok(isNewPassword);
}
/** /**
* 비밀번호 재설정 * 비밀번호 재설정
* *

View File

@ -35,5 +35,7 @@ public interface commoncodMapper {
int updateColorYon(String color); int updateColorYon(String color);
List<MapDto> getYearCategories();
List<MapDto> getCategories(); List<MapDto> getCategories();
} }

View File

@ -44,9 +44,14 @@ public class commoncodService {
return commoncodmapper.getMbtiList(); return commoncodmapper.getMbtiList();
} }
public List<MapDto> getYearCategories() {
return commoncodmapper.getYearCategories();
}
public List<MapDto> getPwhintList() { public List<MapDto> getPwhintList() {
return commoncodmapper.getPwhintList(); return commoncodmapper.getPwhintList();
} }
public List<MapDto> getCategoryList() { public List<MapDto> getCategoryList() {
return commoncodmapper.getCategories(); return commoncodmapper.getCategories();
} }

View File

@ -82,9 +82,8 @@ public class localbordService {
public MapDto getBoardDetail(Long boardId) { public MapDto getBoardDetail(Long boardId) {
incrementViewCount(boardId); incrementViewCount(boardId);
MapDto boardDetail = boardMapper.selectBoardDetail(boardId); MapDto boardDetail = boardMapper.selectBoardDetail(boardId);
if (boardDetail != null) { enrichBoardDetail(boardDetail);
enrichBoardDetail(boardDetail);
}
return boardDetail; return boardDetail;
} }
@ -171,45 +170,24 @@ public class localbordService {
return boardMapper.getCommentReactions(boardId); return boardMapper.getCommentReactions(boardId);
} }
private void enrichBoardDetail(MapDto boardDetail) {
long boardId = ((Number) boardDetail.get("id")).longValue();
boardDetail.put("hasAttachment", hasAttachments(boardId));
boardDetail.put("commentCount", getCommentCount(boardId));
MapDto reactions = getBoardReactions(boardId);
boardDetail.put("likeCount", reactions.getOrDefault("likeCount", 0));
boardDetail.put("dislikeCount", reactions.getOrDefault("dislikeCount", 0));
// Blob 데이터를 문자열로 변환
Object content = boardDetail.get("content");
if (content != null) {
String contentString = convertBlobToString(content); // Blob을 문자열로 변환
boardDetail.put("content", contentString); // JSON 변환 가능
}
}
private String convertBlobToString(Object blob) { private String convertBlobToString(Object blob) {
try { try {
if (blob instanceof String) { if (blob instanceof String) {
return (String) blob; // 이미 문자열 경우 반환 return (String) blob; // 이미 문자열이면 그대로 반환
} else if (blob instanceof java.sql.Blob) { } else if (blob instanceof java.sql.Blob) {
java.sql.Blob sqlBlob = (java.sql.Blob) blob; java.sql.Blob sqlBlob = (java.sql.Blob) blob;
long blobLength = sqlBlob.length(); long blobLength = sqlBlob.length();
byte[] blobBytes = sqlBlob.getBytes(1, (int) blobLength); byte[] blobBytes = sqlBlob.getBytes(1, (int) blobLength);
return new String(blobBytes, StandardCharsets.UTF_8); return new String(blobBytes, StandardCharsets.UTF_8); // SQL BLOB 바이트 배열 문자열 변환
} else if (blob instanceof ByteArrayInputStream) {
ByteArrayInputStream inputStream = (ByteArrayInputStream) blob;
byte[] bytes = inputStream.readAllBytes();
return new String(bytes, StandardCharsets.UTF_8);
} else { } else {
System.err.println("Unsupported blob type: " + blob.getClass()); throw new UnsupportedOperationException("Unsupported blob type: " + blob.getClass()); // 지원되지 않는 타입이면 예외 발생
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); throw new RuntimeException("Failed to convert Blob to String: " + e.getMessage(), e); // 변환 실패 예외 처리
throw new RuntimeException("Failed to convert Blob to String: " + e.getMessage(), e);
} }
return null;
} }
private String extractFirstImageUrl(String jsonContent) { private String extractFirstImageUrl(String jsonContent) {
try { try {
// JSON 유효성 검사 // JSON 유효성 검사
@ -277,6 +255,22 @@ public class localbordService {
return plainTextBuilder.toString(); return plainTextBuilder.toString();
} }
private void enrichBoardDetail(MapDto boardDetail) {
long boardId = ((Number) boardDetail.get("id")).longValue();
boardDetail.put("hasAttachment", hasAttachments(boardId));
boardDetail.put("commentCount", getCommentCount(boardId));
MapDto reactions = getBoardReactions(boardId);
boardDetail.put("likeCount", reactions.getOrDefault("likeCount", 0));
boardDetail.put("dislikeCount", reactions.getOrDefault("dislikeCount", 0));
// Blob 데이터를 문자열로 변환
Object content = boardDetail.get("content");
if (content != null) {
String contentString = convertBlobToString(content); // Blob을 문자열로 변환
boardDetail.put("content", contentString); // JSON 변환 가능
}
}
private void enrichPostsWithAdditionalData(List<MapDto> posts) { private void enrichPostsWithAdditionalData(List<MapDto> posts) {
for (MapDto post : posts) { for (MapDto post : posts) {
Object idObject = post.get("id"); Object idObject = post.get("id");

View File

@ -79,5 +79,18 @@
WHERE CMNCODVAL BETWEEN 300101 AND 300103 WHERE CMNCODVAL BETWEEN 300101 AND 300103
</select> </select>
<select id="getYearCategories" resultType="Map">
SELECT
CMNCODVAL
,CMNCODNAM
FROM
commoncod
WHERE
CMNCODLV1 = 900
AND
CMNCODODR != 0
</select>
</mapper> </mapper>

View File

@ -67,10 +67,19 @@
<!-- 게시물 상세정보 조회 --> <!-- 게시물 상세정보 조회 -->
<select id="selectBoardDetail" resultType="io.company.localhost.common.dto.MapDto"> <select id="selectBoardDetail" resultType="io.company.localhost.common.dto.MapDto">
SELECT LOCBRDSEQ AS id, LOCBRDTTL AS title, LOCBRDCON AS content, LOCBRDUDT AS date, LOCBRDTYP AS type, LOCBRDCNT AS cnt SELECT
FROM localbord b.LOCBRDSEQ AS id,
WHERE LOCBRDSEQ = #{boardId} b.LOCBRDTTL AS title,
</select> b.LOCBRDCON AS content,
b.LOCBRDUDT AS date,
b.LOCBRDTYP AS type,
b.LOCBRDCNT AS cnt,
m.MEMBERNAM AS author
FROM localbord b
LEFT JOIN netmember m ON b.MEMBERSEQ = m.MEMBERSEQ
WHERE b.LOCBRDSEQ = #{boardId}
</select>
<!-- 첨부파일 목록 조회 --> <!-- 첨부파일 목록 조회 -->
<select id="selectAttachments" resultType="io.company.localhost.common.dto.MapDto"> <select id="selectAttachments" resultType="io.company.localhost.common.dto.MapDto">