Skip to content

Commit

Permalink
Merge pull request #153 from fastcampus-711/feature/bug
Browse files Browse the repository at this point in the history
Feature/bug
  • Loading branch information
having-dlrow authored Jun 11, 2024
2 parents 9b078b3 + 595d7c1 commit 64fa0d7
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 49 deletions.
5 changes: 2 additions & 3 deletions src/main/java/com/aptner/v3/MenuInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.aptner.v3.menu.dto.MenuDto;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

Expand All @@ -27,7 +26,6 @@
import static com.aptner.v3.CommunityApplication.passwordEncoder;

@Component
@Profile("dev") // dev 환경에서만 실행되도록 설정
public class MenuInitializer implements CommandLineRunner {

private final MenuService menuService;
Expand Down Expand Up @@ -58,7 +56,8 @@ public void run(String... args) {

String ddlAuto = environment.getProperty("spring.jpa.hibernate.ddl-auto");
if (!"create-drop".equals(ddlAuto)) {
return; // ddl-auto가 create-drop이 아닌 경우 실행 중단
// ddl-auto가 create-drop이 아닌 경우 실행 중단
return;
}

House house = House.of(77777, "패캠세븐아파트", HouseType.APARTMENT,115.7, "701", "103");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.aptner.v3.global.error.response.ApiResponse;
import com.aptner.v3.global.util.ResponseUtil;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -77,7 +78,7 @@ public ApiResponse<?> getPost(
@PostMapping("/")
@Operation(summary = "게시글 등록")
public ApiResponse<?> createPost(
@RequestBody Q request,
@Valid @RequestBody Q request,
@AuthenticationPrincipal CustomUserDetails user
) {
this.logGenericTypes();
Expand All @@ -101,7 +102,7 @@ public ApiResponse<?> createPost(
@Operation(summary = "게시글 수정")
public ApiResponse<?> updatePost(
@PathVariable(name = "post-id") Long postId,
@RequestBody Q request,
@Valid @RequestBody Q request,
@AuthenticationPrincipal CustomUserDetails user) {
this.logGenericTypes();
request.setId(postId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.aptner.v3.board.category.BoardGroup;
import com.aptner.v3.board.common_post.domain.CommonPost;
import com.aptner.v3.board.complain.ComplainStatus;
import com.aptner.v3.board.market.MarketStatus;
import com.aptner.v3.board.qna.QnaStatus;
import com.aptner.v3.board.qna.Status;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.jpa.domain.Specification;
Expand Down Expand Up @@ -31,11 +34,23 @@ public static <E extends CommonPost> Specification<E> hasCategoryId(Long categor
};
}

public static <E extends CommonPost> Specification<E> hasStatus(Status status) {
public static <E extends CommonPost> Specification<E> hasStatus(Status status, BoardGroup boardGroup) {
return (root, query, criteriaBuilder) -> {
if (status != null) {
log.debug("specification - status : {}", status);
return criteriaBuilder.equal(root.get("status"), status);
log.debug("specification - status : {} {}", status, boardGroup.getTable());
if (boardGroup.getTable().equals(BoardGroup.MARKETS.getTable())) {
log.debug("마켓");
return criteriaBuilder.equal(root.get("status"), (MarketStatus) status);
} else if (boardGroup.getTable().equals(BoardGroup.COMPLAINT.getTable())) {
log.debug("complaint");
return criteriaBuilder.equal(root.get("status"), (ComplainStatus) status);
} else if (boardGroup.getTable().equals(BoardGroup.QNAS.getTable())) {
log.debug("qna");
return criteriaBuilder.equal(root.get("status"), (QnaStatus) status);
} else {
log.debug("etc");
return criteriaBuilder.conjunction();
}
} else {
return criteriaBuilder.conjunction();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import com.aptner.v3.member.Member;
import com.aptner.v3.member.dto.MemberDto;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.*;
import lombok.*;
import lombok.experimental.SuperBuilder;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -166,12 +165,14 @@ public CommonPostResponse toResponseWithComment() {
@NoArgsConstructor
public static class CommonPostRequest {
protected Long id;
@NotBlank
@NotNull
@Min(1L)
protected Long categoryId;
@NotBlank
@Size(max = 200, message = "제목은 200자 이내로 작성해주세요.")
protected String title;
@NotBlank
@Size(max = 500, message = "제목은 500자 이내로 작성해주세요.")
protected String content;
protected boolean visible;
protected List<String> imageUrls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static <E extends CommonPost> Specification<E> geteSpecification(BoardGr
}

if (status != null) {
spec = spec.and(PostSpecification.hasStatus(status));
spec = spec.and(PostSpecification.hasStatus(status, boardGroup));
}

if (userId != null) {
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/com/aptner/v3/board/complain/ComplainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.aptner.v3.board.common_post.dto.SearchDto;
import com.aptner.v3.board.common_post.service.PaginationService;
import com.aptner.v3.board.complain.dto.ComplainDto;
import com.aptner.v3.board.complain.dto.ComplainStatusDto;
import com.aptner.v3.board.qna.Status;
import com.aptner.v3.global.error.response.ApiResponse;
import com.aptner.v3.global.util.ResponseUtil;
Expand All @@ -18,10 +19,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
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
@Tag(name="민원 게시판")
Expand Down Expand Up @@ -57,6 +55,26 @@ public ApiResponse<?> getMyPostListByCategoryId(@RequestParam(name = "category-i
)));
}

@GetMapping("/status")
@Operation(summary = "상태 목록")
public ApiResponse<?> getStatusList() {
return ResponseUtil.ok(ComplainStatusDto.ComplainStatusResponse.toList());
}

@PostMapping("/status")
@Operation(summary = "상태 등록")
public ApiResponse<?> setStatus(
@RequestBody ComplainStatusDto.ComplainStatusRequest request
, @AuthenticationPrincipal CustomUserDetails user) {

ComplainDto dto = ComplainDto.of(
getBoardGroup(),
user.toDto(),
ComplainDto.ComplainRequest.of(request.getPostId(), null)
);

return ResponseUtil.ok(complainService.setStatus(dto).toResponse());
}
@Override
public BoardGroup getBoardGroup() {
return BoardGroup.COMPLAINT;
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/com/aptner/v3/board/complain/ComplainService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@
@Qualifier("complainService")
public class ComplainService extends CommonPostService<Complain, ComplainDto, ComplainDto.ComplainRequest, ComplainDto.ComplainResponse> {

private final CommonPostRepository<Complain> commonPostRepository;
private final CommonPostRepository<Complain> complainRepository;

public ComplainService(MemberRepository memberRepository,
CategoryRepository categoryRepository,
CommonPostRepository<Complain> commonPostRepository,
CommonPostRepository<Complain> complainRepository,
ReactionRepository<PostReaction> postReactionRepository
) {
super(memberRepository, categoryRepository, commonPostRepository, postReactionRepository);
this.commonPostRepository = commonPostRepository;
super(memberRepository, categoryRepository, complainRepository, postReactionRepository);
this.complainRepository = complainRepository;
}

public ComplainDto setStatus(ComplainDto dto) {
Complain complain = verifyPost(dto);
// update
complain.setStatus(dto.getStatus());
complainRepository.flush();
return complain.toDto();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public ComplainDto.ComplainResponse toResponse() {
.reactionType(isSecret ? ReactionType.DEFAULT : dto.getReactionType())
.countOfComments(dto.getCountOfComments())
// complaint
.status(dto.getStatus())
.status(dto.getStatus() == null ? ComplainStatus.RECEIVED : dto.getStatus())
// category
.boardGroup(dto.getBoardGroup())
.categoryName(dto.getCategoryDto().getName())
Expand Down Expand Up @@ -121,7 +121,7 @@ public ComplainDto.ComplainResponse toResponseWithComment() {
.reactionType(isSecret ? ReactionType.DEFAULT : dto.getReactionType())
.countOfComments(dto.getCountOfComments())
// complaint
.status(dto.getStatus())
.status(dto.getStatus() == null ? ComplainStatus.RECEIVED : dto.getStatus())
// category
.boardGroup(dto.getBoardGroup())
.categoryName(dto.getCategoryDto().getName())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.aptner.v3.board.complain.dto;

import com.aptner.v3.board.complain.ComplainStatus;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Getter
@ToString(callSuper = true)
@SuperBuilder
@NoArgsConstructor
public class ComplainStatusDto {

Long postId;
ComplainStatus status;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class ComplainStatusRequest {
Long postId;
ComplainStatus status;
}

@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class ComplainStatusResponse {
private String code;
private String description;
public static ComplainStatusResponse from(ComplainStatus status) {
return new ComplainStatusResponse(status.name(), status.getDescription());
}

public static List<ComplainStatusResponse> toList() {
return Arrays.stream(ComplainStatus.values())
.map(ComplainStatusResponse::from)
.collect(Collectors.toList());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private Page<FreePostDto> getFirstPageWithTopPosts(BoardGroup boardGroup, Long c
// .where(PostSpecification.<FreePost>hasBoardGroup(boardGroup))
// .and(PostSpecification.hasCategoryId(categoryId))
// .and(PostSpecification.hasKeyword(keyword))
// .and(PostSpecification.hasStatus(status))
// .and(PostSpecification.hasStatus(status, boardGroup))
// .and(PostSpecification.hasAuthor(userId));

Specification<FreePost> spec = Specification.where(PostSpecification.hasBoardGroup(boardGroup));
Expand All @@ -84,7 +84,7 @@ private Page<FreePostDto> getFirstPageWithTopPosts(BoardGroup boardGroup, Long c

if (status != null) {
log.debug("인기글 조건(status) : {}", status);
spec = spec.and(PostSpecification.hasStatus(status));
spec = spec.and(PostSpecification.hasStatus(status, boardGroup));
}

if (userId != null) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/aptner/v3/board/market/dto/MarketDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.aptner.v3.board.market.MarketStatus;
import com.aptner.v3.member.Member;
import com.aptner.v3.member.dto.MemberDto;
import jakarta.validation.constraints.Min;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
Expand Down Expand Up @@ -93,7 +94,7 @@ public MarketResponse toResponse() {
.categoryName(dto.getCategoryDto().getName())
// market
.price(dto.getPrice())
.status(dto.getStatus())
.status(dto.getStatus() == null ? MarketStatus.SALE : dto.getStatus())
// base
.createdAt(dto.getCreatedAt())
.createdBy(dto.getCreatedBy())
Expand Down Expand Up @@ -138,7 +139,7 @@ public MarketResponse toResponseWithComment() {
.categoryName(dto.getCategoryDto().getName())
// market
.price(dto.getPrice())
.status(dto.getStatus())
.status(dto.getStatus() == null ? MarketStatus.SALE : dto.getStatus())
// base
.createdAt(dto.getCreatedAt())
.createdBy(dto.getCreatedBy())
Expand All @@ -159,6 +160,7 @@ public MarketResponse toResponseWithComment() {
public static class MarketRequest extends CommonPostDto.CommonPostRequest {
private String type;
private MarketStatus status = MarketStatus.SALE;
@Min(value = 0, message = "가격은 0 이상이어야 합니다.")
private Integer price = 0;

public static MarketDto.MarketRequest of(Long id, Long categoryId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Page<NoticePostDto> getPostList(BoardGroup boardGroup, Long categoryId, S
.where(PostSpecification.<NoticePost>hasBoardGroup(boardGroup))
.and(PostSpecification.hasCategoryId(categoryId))
.and(PostSpecification.hasKeyword(keyword))
.and(PostSpecification.hasStatus(status))
.and(PostSpecification.hasStatus(status, boardGroup))
.and(PostSpecification.hasAuthor(userId))
.and(PostSpecification.isDuty(isDuty))
;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/aptner/v3/menu/dto/MenuDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.aptner.v3.board.category.BoardGroup;
import com.aptner.v3.menu.Menu;
import com.fasterxml.jackson.annotation.JsonInclude;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -20,7 +21,10 @@ public static class MenuDtoRequest {
Long parentId;
@NotBlank
String code;
@NotBlank
@Max(value = 50, message = "50자 이내로 입력해주세요.")
String name;

BoardGroup boardGroup;


Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ frontend:
server:
port: 8181

spring:

sql:
init:
mode: always
jpa:
hibernate:
ddl-auto: create-drop
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spring:
defer-datasource-initialization: true
hibernate:
dialect: org.hibernate.dialect.MySQL8Dialect
ddl-auto: update
ddl-auto: none

properties:
hibernate:
Expand Down
Loading

0 comments on commit 64fa0d7

Please sign in to comment.