diff --git a/src/main/java/ussum/homepage/application/post/controller/PostManageController.java b/src/main/java/ussum/homepage/application/post/controller/PostManageController.java index 2407439c..ff7a1ad9 100644 --- a/src/main/java/ussum/homepage/application/post/controller/PostManageController.java +++ b/src/main/java/ussum/homepage/application/post/controller/PostManageController.java @@ -16,6 +16,7 @@ import ussum.homepage.application.post.service.dto.response.TopLikedPostListResponse; import ussum.homepage.global.ApiResponse; import ussum.homepage.global.config.auth.UserId; +import ussum.homepage.global.config.custom.BoardRequestBody; @RestController @RequiredArgsConstructor @@ -83,11 +84,14 @@ public ResponseEntity> getBoardPost(@PathVariable(name = "boardCo 이 컨트롤러에 있는 "/board/{boardCode}/files" api를 먼저 사용하여 리턴값으로 전달받는 값을 넣어주면 됩니다. 사진이나 파일이 존재하지 않을 시 빈 List로 전달해주시면 됩니다. isNotice는 긴급공지 사항을 나타내는 필드로 맞을시 true, 틀릴시 false를 반환하면 됩니다. + + 인권신고게시판 경우 기존 json에 추가로 relatedPeople 리스트로 전달해주시면 됩니다. 리스트에는 name, major, studentId에 값을 String으로 + 넣어서 전달해주시고 personType은 신고자, 피침해자, 침해자중 선택하여 전달해주시면 됩니다. """) @PostMapping("/{boardCode}/posts") public ResponseEntity> createBoardPost(@Parameter(hidden = true) @UserId Long userId, @PathVariable(name = "boardCode") String boardCode, - @RequestBody PostCreateRequest postCreateRequest){ + @BoardRequestBody PostCreateRequest postCreateRequest){ return ApiResponse.success(postManageService.createBoardPost(userId, boardCode, postCreateRequest)); } diff --git a/src/main/java/ussum/homepage/application/post/service/PostManageService.java b/src/main/java/ussum/homepage/application/post/service/PostManageService.java index c2baf42b..a4789038 100644 --- a/src/main/java/ussum/homepage/application/post/service/PostManageService.java +++ b/src/main/java/ussum/homepage/application/post/service/PostManageService.java @@ -177,7 +177,7 @@ public PostCreateResponse createBoardPost(Long userId, String boardCode, PostCre Board board = boardReader.getBoardWithBoardCode(boardCode); PostCreateRequest converPostCreateRequest = postFactory.convert(boardCode,postCreateRequest); Post post = postAppender.createPost(converPostCreateRequest.toDomain(board, userId)); - postAdditionalAppender.createAdditional(converPostCreateRequest); + postAdditionalAppender.createAdditional(converPostCreateRequest,post.getId()); postFileAppender.updatePostIdForIds(converPostCreateRequest.getPostFileList(), post.getId(), FileCategory.자료집아님); return PostCreateResponse.of(post.getId(), boardCode); } diff --git a/src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java b/src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java index 4f59de1f..5c40b62b 100644 --- a/src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java +++ b/src/main/java/ussum/homepage/application/post/service/dto/request/GeneralPostCreateRequest.java @@ -9,13 +9,10 @@ @Getter public class GeneralPostCreateRequest extends PostCreateRequest { - private final String categoryCode; @Builder - public GeneralPostCreateRequest(String title, String content, String thumbNailImage, boolean isNotice, String categoryCode, List postFileList) { - super(title, content, thumbNailImage, isNotice,postFileList); - this.categoryCode = categoryCode; - this.postFileList = postFileList; + public GeneralPostCreateRequest(String title, String content, String categoryCode, String thumbNailImage, boolean isNotice, List postFileList) { + super(title, content,categoryCode, thumbNailImage, isNotice,postFileList); } public Post toDomain(Board board, Long userId){ diff --git a/src/main/java/ussum/homepage/application/post/service/dto/request/PostCreateRequest.java b/src/main/java/ussum/homepage/application/post/service/dto/request/PostCreateRequest.java index 1deccfbc..2d8c88ac 100644 --- a/src/main/java/ussum/homepage/application/post/service/dto/request/PostCreateRequest.java +++ b/src/main/java/ussum/homepage/application/post/service/dto/request/PostCreateRequest.java @@ -1,47 +1,31 @@ package ussum.homepage.application.post.service.dto.request; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonTypeInfo; import java.util.List; import lombok.Getter; import ussum.homepage.domain.post.Board; import ussum.homepage.domain.post.Post; @Getter -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "boardId",defaultImpl = GeneralPostCreateRequest.class) -@JsonSubTypes({ - @JsonSubTypes.Type(value = RightsDetailRequest.class, name = "8"), -}) +//@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "boardCode",defaultImpl = GeneralPostCreateRequest.class) +//@JsonSubTypes({ +// @JsonSubTypes.Type(value = RightsPostCreateRequest.class, name = "인권신고게시판") +//}) public abstract class PostCreateRequest { protected String title; protected String content; + protected String categoryCode; protected String thumbNailImage; protected boolean isNotice; protected List postFileList; - public PostCreateRequest(String title, String content, String thumbNailImage, boolean isNotice, List postFileList) { + public PostCreateRequest(String title, String content, String categoryCode, String thumbNailImage, boolean isNotice, List postFileList) { this.title = title; this.content = content; + this.categoryCode = categoryCode; this.thumbNailImage = thumbNailImage; this.isNotice = isNotice; this.postFileList = postFileList; } - public Post toDomain(Board board, Long userId){ - String status = "새로운"; - if(isNotice){ - status = "긴급공지"; - } - - return Post.of(null, - title, - content, - 1, - thumbNailImage, - status, - null,null,null, - null, - userId, - board.getId()); - } + public abstract Post toDomain(Board board, Long userId); } diff --git a/src/main/java/ussum/homepage/application/post/service/dto/request/RightsDetailRequest.java b/src/main/java/ussum/homepage/application/post/service/dto/request/RightsDetailRequest.java index c7af9d0d..c28b8f9c 100644 --- a/src/main/java/ussum/homepage/application/post/service/dto/request/RightsDetailRequest.java +++ b/src/main/java/ussum/homepage/application/post/service/dto/request/RightsDetailRequest.java @@ -1,14 +1,18 @@ package ussum.homepage.application.post.service.dto.request; import ussum.homepage.domain.post.RightsDetail; +import ussum.homepage.infra.jpa.post.entity.RightsDetailEntity.PersonType; public record RightsDetailRequest( String name, String studentId, String major, - String personType + String personType, + Long postId ) { - public RightsDetail toDomain() { - return RightsDetail.of(null, name, studentId, major, personType); + public RightsDetail toDomain(Long postId) { + PersonType enumPersonType = PersonType.getEnumPersonTypeFromStringType(personType()); + + return RightsDetail.of(null, name, studentId, major, enumPersonType,postId); } } diff --git a/src/main/java/ussum/homepage/application/post/service/dto/request/RightsPostCreateRequest.java b/src/main/java/ussum/homepage/application/post/service/dto/request/RightsPostCreateRequest.java index af105ede..f7beda13 100644 --- a/src/main/java/ussum/homepage/application/post/service/dto/request/RightsPostCreateRequest.java +++ b/src/main/java/ussum/homepage/application/post/service/dto/request/RightsPostCreateRequest.java @@ -3,15 +3,37 @@ import java.util.List; import lombok.Builder; import lombok.Getter; +import ussum.homepage.domain.post.Board; +import ussum.homepage.domain.post.Post; @Getter public class RightsPostCreateRequest extends PostCreateRequest { private final List relatedPeople; @Builder - public RightsPostCreateRequest(String title, String content, String thumbNailImage, boolean isNotice, + public RightsPostCreateRequest(String title, String content, String categoryCode,String thumbNailImage, boolean isNotice, List postFileList, List relatedPeople) { - super(title, content, thumbNailImage, isNotice, postFileList); + super(title, content, categoryCode, thumbNailImage, isNotice, postFileList); this.relatedPeople = relatedPeople; } + + @Override + public Post toDomain(Board board, Long userId) { + + return Post.of(null, + title, + content, + null, + thumbNailImage, + "새로운", + null, null, null, + categoryCode, + userId, + board.getId()); + } + + private boolean validation(String boardCod){ + return true; + } } + diff --git a/src/main/java/ussum/homepage/domain/post/RightsDetail.java b/src/main/java/ussum/homepage/domain/post/RightsDetail.java index 2bcf2390..c48b1fb1 100644 --- a/src/main/java/ussum/homepage/domain/post/RightsDetail.java +++ b/src/main/java/ussum/homepage/domain/post/RightsDetail.java @@ -12,10 +12,11 @@ public class RightsDetail { private String name; private String studentId; private String major; - private String personType; + private PersonType personType; + private Long postId; public static RightsDetail of(Long id, - String name,String studentId,String major,String personType) { - return new RightsDetail(id, name, studentId, major, personType); + String name,String studentId,String major,PersonType personType,Long postId) { + return new RightsDetail(id, name, studentId, major, personType, postId); } } diff --git a/src/main/java/ussum/homepage/domain/post/RightsDetailRepository.java b/src/main/java/ussum/homepage/domain/post/RightsDetailRepository.java index 4c53ddfb..8a215166 100644 --- a/src/main/java/ussum/homepage/domain/post/RightsDetailRepository.java +++ b/src/main/java/ussum/homepage/domain/post/RightsDetailRepository.java @@ -4,4 +4,5 @@ public interface RightsDetailRepository { void saveAll(List rightsDetails); + void deleteAll(Long postId); } diff --git a/src/main/java/ussum/homepage/domain/post/service/PostAdditionalAppender.java b/src/main/java/ussum/homepage/domain/post/service/PostAdditionalAppender.java index 9e2133b7..4b1bedc9 100644 --- a/src/main/java/ussum/homepage/domain/post/service/PostAdditionalAppender.java +++ b/src/main/java/ussum/homepage/domain/post/service/PostAdditionalAppender.java @@ -18,13 +18,13 @@ public class PostAdditionalAppender { private final RightsDetailRepository rightsDetailRepository; @Transactional - public void createAdditional(PostCreateRequest converPostCreateRequest) { + public void createAdditional(PostCreateRequest converPostCreateRequest, Long postId) { if (converPostCreateRequest instanceof RightsPostCreateRequest){ List rightsDetailList = new ArrayList<>(); - for ( RightsDetailRequest detailRequest : ((RightsPostCreateRequest) converPostCreateRequest).getRelatedPeople()){ - rightsDetailList.add(detailRequest.toDomain()); + for (RightsDetailRequest detailRequest : ((RightsPostCreateRequest) converPostCreateRequest).getRelatedPeople()){ + rightsDetailList.add(detailRequest.toDomain(postId)); } rightsDetailRepository.saveAll(rightsDetailList); } diff --git a/src/main/java/ussum/homepage/domain/post/service/PostModifier.java b/src/main/java/ussum/homepage/domain/post/service/PostModifier.java index b1437b2f..47bb9bc8 100644 --- a/src/main/java/ussum/homepage/domain/post/service/PostModifier.java +++ b/src/main/java/ussum/homepage/domain/post/service/PostModifier.java @@ -11,6 +11,7 @@ @RequiredArgsConstructor public class PostModifier { private final PostRepository postRepository; + private final RightsDetailRepository rightsDetailRepository; private final PostReader postReader; private final BoardReader boardReader; @@ -23,6 +24,7 @@ public Post updateDataPost(Post post, String category){ } public void deletePost(String boardCode, Long postId) { + rightsDetailRepository.deleteAll(postId); postRepository.delete(postReader.getPostWithBoardCodeForEditAndDelete(boardCode, postId)); } diff --git a/src/main/java/ussum/homepage/domain/post/service/factory/PostFactoryImpl.java b/src/main/java/ussum/homepage/domain/post/service/factory/PostFactoryImpl.java index b3eafee8..21373256 100644 --- a/src/main/java/ussum/homepage/domain/post/service/factory/PostFactoryImpl.java +++ b/src/main/java/ussum/homepage/domain/post/service/factory/PostFactoryImpl.java @@ -10,23 +10,28 @@ public class PostFactoryImpl implements PostFactory { @Override public PostCreateRequest convert(String boardCode, PostCreateRequest request) { - return switch (boardCode){ - case "인권신고게시판" -> - RightsPostCreateRequest.builder() - .title(request.getTitle()) - .content(request.getContent()) - .isNotice(request.isNotice()) - .thumbNailImage(request.getThumbNailImage()) - .postFileList(request.getPostFileList()) + + return switch (boardCode) { + case "인권신고게시판" -> { + RightsPostCreateRequest rightsPostCreateRequest = (RightsPostCreateRequest) request; + yield RightsPostCreateRequest.builder() + .title(rightsPostCreateRequest.getTitle()) + .content(rightsPostCreateRequest.getContent()) + .categoryCode(rightsPostCreateRequest.getCategoryCode()) + .thumbNailImage(rightsPostCreateRequest.getThumbNailImage()) + .isNotice(rightsPostCreateRequest.isNotice()) + .postFileList(rightsPostCreateRequest.getPostFileList()) + .relatedPeople(rightsPostCreateRequest.getRelatedPeople()) .build(); - default -> - GeneralPostCreateRequest.builder() - .title(request.getTitle()) - .content(request.getContent()) - .isNotice(request.isNotice()) - .thumbNailImage(request.getThumbNailImage()) - .postFileList(request.getPostFileList()) - .build(); + } + default -> GeneralPostCreateRequest.builder() + .title(request.getTitle()) + .content(request.getContent()) + .categoryCode(request.getCategoryCode()) + .thumbNailImage(request.getThumbNailImage()) + .isNotice(request.isNotice()) + .postFileList(request.getPostFileList()) + .build(); }; } } diff --git a/src/main/java/ussum/homepage/global/config/BoardRequestBodyArgumentResolver.java b/src/main/java/ussum/homepage/global/config/BoardRequestBodyArgumentResolver.java new file mode 100644 index 00000000..b59e7be3 --- /dev/null +++ b/src/main/java/ussum/homepage/global/config/BoardRequestBodyArgumentResolver.java @@ -0,0 +1,54 @@ +package ussum.homepage.global.config; + +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.servlet.http.HttpServletRequest; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import org.springframework.core.MethodParameter; +import org.springframework.stereotype.Component; +import org.springframework.util.StreamUtils; +import org.springframework.web.bind.support.WebDataBinderFactory; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.method.support.ModelAndViewContainer; +import org.springframework.web.servlet.HandlerMapping; +import ussum.homepage.application.post.service.dto.request.GeneralPostCreateRequest; +import ussum.homepage.application.post.service.dto.request.RightsPostCreateRequest; +import ussum.homepage.global.config.custom.BoardRequestBody; + +@Component +public class BoardRequestBodyArgumentResolver implements HandlerMethodArgumentResolver { + private final ObjectMapper objectMapper; + + public BoardRequestBodyArgumentResolver(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @Override + public boolean supportsParameter(MethodParameter parameter) { + return parameter.hasParameterAnnotation(BoardRequestBody.class); + } + + @Override + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { + + Map pathVariables = (Map) webRequest.getAttribute( + HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, + RequestAttributes.SCOPE_REQUEST + ); + + String boardCode = pathVariables.get("boardCode"); + + HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); + String body = StreamUtils.copyToString(request.getInputStream(), StandardCharsets.UTF_8); + + Class targetClass = "인권신고게시판".equals(boardCode) ? + RightsPostCreateRequest.class : GeneralPostCreateRequest.class; + + Object result = objectMapper.readValue(body, targetClass); + + return result; + } +} diff --git a/src/main/java/ussum/homepage/global/config/WebConfig.java b/src/main/java/ussum/homepage/global/config/WebConfig.java index d5d1f6d4..50712aa7 100644 --- a/src/main/java/ussum/homepage/global/config/WebConfig.java +++ b/src/main/java/ussum/homepage/global/config/WebConfig.java @@ -1,5 +1,6 @@ package ussum.homepage.global.config; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.support.HandlerMethodArgumentResolver; @@ -12,9 +13,11 @@ @Configuration public class WebConfig implements WebMvcConfigurer { private final UserIdArgumentResolver userIdArgumentResolver; + private final ObjectMapper objectMapper; @Override public void addArgumentResolvers(List resolvers){ resolvers.add(userIdArgumentResolver); + resolvers.add(new BoardRequestBodyArgumentResolver(objectMapper)); } } diff --git a/src/main/java/ussum/homepage/global/config/custom/BoardRequestBody.java b/src/main/java/ussum/homepage/global/config/custom/BoardRequestBody.java new file mode 100644 index 00000000..c806beb6 --- /dev/null +++ b/src/main/java/ussum/homepage/global/config/custom/BoardRequestBody.java @@ -0,0 +1,11 @@ +package ussum.homepage.global.config.custom; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.RUNTIME) +public @interface BoardRequestBody { +} diff --git a/src/main/java/ussum/homepage/global/error/status/ErrorStatus.java b/src/main/java/ussum/homepage/global/error/status/ErrorStatus.java index aa8aa04b..bf33a8b8 100644 --- a/src/main/java/ussum/homepage/global/error/status/ErrorStatus.java +++ b/src/main/java/ussum/homepage/global/error/status/ErrorStatus.java @@ -76,6 +76,8 @@ public enum ErrorStatus implements BaseErrorCode { INVALID_GROUP_CODE(HttpStatus.BAD_REQUEST,"ENUM_015","유효하지 않은 GROUPCODE입니다."), INVALID_FILE_CATEGORY(HttpStatus.BAD_REQUEST,"ENUM_016","유효하지 않은 FILE_CATEGORY입니다."), INVALID_FILETYPE(HttpStatus.BAD_REQUEST,"ENUM_017","유효하지 않은 FILETYPE입니다."), + PERSON_TYPE_NULL(HttpStatus.BAD_REQUEST,"ENUM_18","PERSON_TYPE이 NULL입니다."), + INVALID_PERSON_TYPE(HttpStatus.BAD_REQUEST,"ENUM_19","유효하지 않은 PERSON_TYPE입니다."), /** * 401 Unauthorized, Token 관련 에러 */ diff --git a/src/main/java/ussum/homepage/infra/config/SwaggerConfig.java b/src/main/java/ussum/homepage/infra/config/SwaggerConfig.java index 9f4ed466..275c3ffe 100644 --- a/src/main/java/ussum/homepage/infra/config/SwaggerConfig.java +++ b/src/main/java/ussum/homepage/infra/config/SwaggerConfig.java @@ -30,7 +30,7 @@ public OpenAPI openAPI() { .bearerFormat(JWT) ); return new OpenAPI() - .addServersItem(new Server().url("https://sssupport.shop")) + .addServersItem(new Server().url("https://dev.sssupport.shop")) .components(new Components()) .info(new Info()) .addSecurityItem(securityRequirement) diff --git a/src/main/java/ussum/homepage/infra/jpa/post/RightsDetailMapper.java b/src/main/java/ussum/homepage/infra/jpa/post/RightsDetailMapper.java index c46ead56..44363fdd 100644 --- a/src/main/java/ussum/homepage/infra/jpa/post/RightsDetailMapper.java +++ b/src/main/java/ussum/homepage/infra/jpa/post/RightsDetailMapper.java @@ -1,19 +1,32 @@ package ussum.homepage.infra.jpa.post; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import ussum.homepage.domain.post.PostRepository; import ussum.homepage.domain.post.RightsDetail; +import ussum.homepage.infra.jpa.post.entity.PostEntity; import ussum.homepage.infra.jpa.post.entity.RightsDetailEntity; import ussum.homepage.infra.jpa.post.entity.RightsDetailEntity.PersonType; +import ussum.homepage.infra.jpa.post.repository.PostJpaRepository; @Component +@RequiredArgsConstructor public class RightsDetailMapper { + + private final PostJpaRepository postJpaRepository; + public static RightsDetail toDomain(RightsDetailEntity rightsDetailEntity){ - return RightsDetail.of(rightsDetailEntity.getId(), rightsDetailEntity.getName(), rightsDetailEntity.getStudentId(),rightsDetailEntity.getMajor(),rightsDetailEntity.getPersonType().toString()); + return RightsDetail.of(rightsDetailEntity.getId(), rightsDetailEntity.getName(), rightsDetailEntity.getStudentId(),rightsDetailEntity.getMajor(),rightsDetailEntity.getPersonType(), + rightsDetailEntity.getPostEntity().getId()); } - public static RightsDetailEntity toEntity(RightsDetail rightsDetail){ - PersonType personType = RightsDetailEntity.PersonType.getEnumPersonTypeFromStringType(rightsDetail.getPersonType()); - return RightsDetailEntity.of(rightsDetail.getId(), rightsDetail.getName(), rightsDetail.getStudentId(),rightsDetail.getMajor(),null,null); + public RightsDetailEntity toEntity(RightsDetail rightsDetail) { // non-static + PostEntity postEntity = postJpaRepository.findById(rightsDetail.getPostId()) + .orElseThrow(() -> new IllegalArgumentException("Post not found")); + + PersonType personType = rightsDetail.getPersonType(); + return RightsDetailEntity.of(rightsDetail.getId(), rightsDetail.getName(), + rightsDetail.getStudentId(), rightsDetail.getMajor(), personType, postEntity); } } diff --git a/src/main/java/ussum/homepage/infra/jpa/post/RightsDetailRepositoryImpl.java b/src/main/java/ussum/homepage/infra/jpa/post/RightsDetailRepositoryImpl.java index ca6f784a..70acaddf 100644 --- a/src/main/java/ussum/homepage/infra/jpa/post/RightsDetailRepositoryImpl.java +++ b/src/main/java/ussum/homepage/infra/jpa/post/RightsDetailRepositoryImpl.java @@ -12,11 +12,17 @@ public class RightsDetailRepositoryImpl implements RightsDetailRepository { private final RightsDetailJpaRepository rightsDetailJpaRepository; + private final RightsDetailMapper rightsDetailMapper; @Override public void saveAll(List rightsDetails) { rightsDetailJpaRepository.saveAll(rightsDetails.stream() - .map(RightsDetailMapper::toEntity) + .map(rightsDetailMapper::toEntity) .toList()); } + + @Override + public void deleteAll(Long postId) { + rightsDetailJpaRepository.deleteByPostEntityId(postId); + } } diff --git a/src/main/java/ussum/homepage/infra/jpa/post/entity/Category.java b/src/main/java/ussum/homepage/infra/jpa/post/entity/Category.java index 406d19d4..d142e232 100644 --- a/src/main/java/ussum/homepage/infra/jpa/post/entity/Category.java +++ b/src/main/java/ussum/homepage/infra/jpa/post/entity/Category.java @@ -55,7 +55,8 @@ public enum Category { DINNER_RULES("회식세칙"), BUDGET_SETTLEMENT("예결산안"), - //공지사항 카테고리 + //인권신고게시판 + STAND_BY("접수대기"), //중앙 : 총학생회, 중앙운영위원회, 중앙선거관리위원회, 동아리연합회 //단과대 : IT대학, 인문대학, 융합특성화자유전공학부, 사회과학대학, 공과대학, 경영대학, 경제통상대학, 자연과학대학, 법과대학 STUDENT_COUNCIL("총학생회"), diff --git a/src/main/java/ussum/homepage/infra/jpa/post/entity/RightsDetailEntity.java b/src/main/java/ussum/homepage/infra/jpa/post/entity/RightsDetailEntity.java index c456e83c..2a387189 100644 --- a/src/main/java/ussum/homepage/infra/jpa/post/entity/RightsDetailEntity.java +++ b/src/main/java/ussum/homepage/infra/jpa/post/entity/RightsDetailEntity.java @@ -1,5 +1,8 @@ package ussum.homepage.infra.jpa.post.entity; +import static ussum.homepage.global.error.status.ErrorStatus.INVALID_PERSON_TYPE; +import static ussum.homepage.global.error.status.ErrorStatus.PERSON_TYPE_NULL; + import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -12,11 +15,15 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; +import java.util.Arrays; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.CascadeType; +import ussum.homepage.global.error.exception.InvalidValueException; @Entity @Table(name = "rights_detail") @@ -57,12 +64,13 @@ public enum PersonType { private final String type; public static PersonType getEnumPersonTypeFromStringType(String type) { - for (PersonType person : values()) { - if (person.getType().equals(type)) { - return person; - } + if (type == null) { + throw new InvalidValueException(PERSON_TYPE_NULL); } - throw new IllegalArgumentException("Unknown rights person type: " + type); + return Arrays.stream(values()) + .filter(personType -> personType.getType().equals(type)) + .findFirst() + .orElseThrow(() -> new InvalidValueException(INVALID_PERSON_TYPE)); } } public static RightsDetailEntity of(Long id, String name, String studentId, String major, PersonType personType,PostEntity postEntity) { diff --git a/src/main/java/ussum/homepage/infra/jpa/post/repository/RightsDetailJpaRepository.java b/src/main/java/ussum/homepage/infra/jpa/post/repository/RightsDetailJpaRepository.java index 95e14e27..7c6c69eb 100644 --- a/src/main/java/ussum/homepage/infra/jpa/post/repository/RightsDetailJpaRepository.java +++ b/src/main/java/ussum/homepage/infra/jpa/post/repository/RightsDetailJpaRepository.java @@ -4,4 +4,5 @@ import ussum.homepage.infra.jpa.post.entity.RightsDetailEntity; public interface RightsDetailJpaRepository extends JpaRepository { + void deleteByPostEntityId(Long postId); }