Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import NextLevel.demo.common.SuccessResponse;
import NextLevel.demo.project.community.dto.request.SaveCommunityDto;
import NextLevel.demo.project.community.dto.response.ResponseCommunityListDto;
import NextLevel.demo.project.community.service.ProjectCommunityAskService;
import NextLevel.demo.util.jwt.JWTUtil;
import jakarta.validation.Valid;
Expand All @@ -10,10 +11,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.*;

@Controller
@Slf4j
Expand All @@ -22,6 +20,12 @@ public class ProjectCommunityController {

private final ProjectCommunityAskService communityService;

// list
@GetMapping("/public/project/{projectId}/community")
public ResponseEntity getProjectCommunity(@PathVariable Long projectId) {
return ResponseEntity.ok().body(new SuccessResponse("success", new ResponseCommunityListDto(communityService.selectAll(projectId))));
}

// 생성만
@PostMapping("/api1/project/{projectId}/community")
public ResponseEntity<?> saveProjectCommunity(@PathVariable("projectId") Long projectId, @RequestBody @Valid SaveCommunityDto dto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ResponseCommunityListDto {
private int communityCount;
private List<ResponseProjectCommunityDto> communities;

public ResponseCommunityListDto (Collection<ProjectCommunityAskEntity> communities) {
public ResponseCommunityListDto (List<ProjectCommunityAskEntity> communities) {
this.communities = communities.stream().map(e->ResponseProjectCommunityDto.of(e)).toList();
this.communityCount = communities.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public interface ProjectCommunityAskRepository extends JpaRepository<ProjectCommunityAskEntity, Long> {

@Query("select ask from ProjectCommunityAskEntity ask left join fetch ask.answer where ask.project.id = :projectId")
List<ProjectCommunityAskEntity> findAllByProjectId(@Param("projectId") Long projectId);
@Query("select ask from ProjectCommunityAskEntity ask left join fetch ask.answer where ask.project.id = :projectId order by ask.createdAt desc")
List<ProjectCommunityAskEntity> findAllByProjectIdOrderByCreatedAt(@Param("projectId") Long projectId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ public void update(SaveCommunityDto dto) {
}

@Transactional
public ResponseCommunityListDto selectAll(Long projectId) {
public List<ProjectCommunityAskEntity> selectAll(Long projectId) {
ProjectEntity project = projectValidateService.getProjectEntity(projectId);
List<ProjectCommunityAskEntity> asks = projectCommunityAskRepository.findAllByProjectId(project.getId());
return new ResponseCommunityListDto(asks);
return projectCommunityAskRepository.findAllByProjectIdOrderByCreatedAt(project.getId());
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import NextLevel.demo.common.SuccessResponse;
import NextLevel.demo.project.notice.dto.request.SaveProjectNoticeRequestDto;
import NextLevel.demo.project.notice.dto.response.ResponseNoticeListDto;
import NextLevel.demo.project.notice.dto.response.ResponseProjectNoticeDto;
import NextLevel.demo.project.notice.service.ProjectNoticeService;
import NextLevel.demo.util.jwt.JWTUtil;
import jakarta.validation.Valid;
Expand All @@ -10,11 +12,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.*;

@Controller
@Slf4j
Expand All @@ -23,6 +21,12 @@ public class ProjectNoticeController {

private final ProjectNoticeService projectNoticeService;

// select notice by project
@GetMapping("/public/project/{projectId}/notice")
public ResponseEntity<?> getProjectNotice(@PathVariable Long projectId) {
return ResponseEntity.ok().body(new SuccessResponse("success", new ResponseNoticeListDto(projectNoticeService.getAllNotice(projectId))));
}

@PostMapping("/api1/project/{projectId}/notice")
public ResponseEntity<?> addProjectNotice(@PathVariable("projectId") long projectId, @ModelAttribute @Valid SaveProjectNoticeRequestDto dto) {
dto.setProjectId(projectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ResponseNoticeListDto {
private int noticeCount;
private List<ResponseProjectNoticeDto> notices;

public ResponseNoticeListDto(Set<ProjectNoticeEntity> entities) {
public ResponseNoticeListDto(List<ProjectNoticeEntity> entities) {
this.notices = entities.stream().map(e->ResponseProjectNoticeDto.of(e)).toList();
this.noticeCount = notices.size();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package NextLevel.demo.project.notice.repository;

import NextLevel.demo.project.notice.entity.ProjectNoticeEntity;

import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -10,4 +12,8 @@ public interface ProjectNoticeRepository extends JpaRepository<ProjectNoticeEnti

@Query("select n from ProjectNoticeEntity n left join fetch n.project where n.id = :noticeId")
Optional<ProjectNoticeEntity> findByIdWithProject(@Param("noticeId") Long noticeId);

@Query("select pn from ProjectNoticeEntity pn where pn.project.id = :projectId order by pn.createdAt desc")
List<ProjectNoticeEntity> findAllByProjectOrderByCreatedAt(@Param("projectId") Long projectId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import jakarta.persistence.EntityManager;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -27,6 +29,11 @@ public class ProjectNoticeService {
private final ImgServiceImpl imgService;
private final ProjectValidateService projectValidateService;

public List<ProjectNoticeEntity> getAllNotice(Long projectId){
ProjectEntity project = projectValidateService.getProjectEntity(projectId);
return projectNoticeRepository.findAllByProjectOrderByCreatedAt(project.getId());
}

@Transactional
@ImgTransaction
public void saveProjectNotice(SaveProjectNoticeRequestDto dto, ArrayList<Path> imgPaths) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import NextLevel.demo.common.SuccessResponse;
import NextLevel.demo.project.project.dto.request.CreateProjectDto;
import NextLevel.demo.project.project.dto.request.RequestMainPageProjectListDto;
import NextLevel.demo.project.project.dto.response.ResponseProjectAllDto;
import NextLevel.demo.project.project.dto.response.ResponseProjectDetailDto;
import NextLevel.demo.project.project.dto.response.ResponseProjectListDto;
import NextLevel.demo.project.project.service.ProjectService;
Expand Down Expand Up @@ -99,11 +98,4 @@ public ResponseEntity<?> getProjectDetailById(@PathVariable("projectId") @NotNul
return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success" ,dto));
}

@GetMapping("/public/project/{projectId}/all")
public ResponseEntity<?> getProjectNotice(@PathVariable("projectId") Long projectId) {
ResponseProjectAllDto dto = projectService.getProjectCommunityAndNoticeAndStoryDto(projectId);

return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success", dto));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public class ProjectEntity extends BasedEntity {
private List<ProjectTagEntity> tags;

@OneToMany(mappedBy = "project", fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST})
private Set<ProjectStoryEntity> stories;
private List<ProjectStoryEntity> stories;

@OneToMany(mappedBy = "project", fetch = FetchType.LAZY)
private Set<OptionEntity> options;
private List<OptionEntity> options;

@OneToMany(mappedBy = "project", fetch = FetchType.LAZY)
private Set<FreeFundingEntity> freeFundings;
Expand All @@ -78,15 +78,15 @@ public class ProjectEntity extends BasedEntity {
private Set<LikeEntity> likes;

@OneToMany(mappedBy = "project", fetch = FetchType.LAZY)
private Set<ProjectCommunityAskEntity> communities;
private List<ProjectCommunityAskEntity> communities;

@OneToMany(mappedBy = "project", fetch = FetchType.LAZY)
private Set<ProjectNoticeEntity> notices;
private List<ProjectNoticeEntity> notices;

@OneToMany(mappedBy = "project", fetch = FetchType.LAZY)
private Set<ProjectViewEntity> views;
private List<ProjectViewEntity> views;

public void setStories(Set<ProjectStoryEntity> imgs) {
public void setStories(List<ProjectStoryEntity> imgs) {
this.stories = imgs;
}
public void setTags(List<ProjectTagEntity> tags) {
Expand All @@ -96,7 +96,7 @@ public void setTags(List<ProjectTagEntity> tags) {
@Builder
public ProjectEntity(Long id, UserEntity user, String title, String content,
Long goal, ImgEntity titleImg, String expired, List<ProjectTagEntity> tags,
Set<ProjectStoryEntity> stories) throws ParseException {
List<ProjectStoryEntity> stories) throws ParseException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
this.id = id;
this.user = user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,4 @@ public interface ProjectRepository extends JpaRepository<ProjectEntity, Long> {
+ "where p.id = :id")
Optional<ProjectEntity> findProjectDetailById(@Param("id") Long id);

@Query("select p from ProjectEntity p "
+ "left join fetch p.notices as n "
+ "left join fetch p.communities as c "
+ "left join fetch p.stories as story "
+ "where p.id = :id")
Optional<ProjectEntity> findProjectWithNoticesAndCommunityAndStory(@Param("id") Long id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
import NextLevel.demo.img.entity.ImgEntity;
import NextLevel.demo.img.service.ImgServiceImpl;
import NextLevel.demo.img.service.ImgTransaction;
import NextLevel.demo.project.community.dto.response.ResponseCommunityListDto;
import NextLevel.demo.project.notice.dto.response.ResponseNoticeListDto;
import NextLevel.demo.project.project.dto.request.CreateProjectDto;
import NextLevel.demo.project.project.dto.request.RequestMainPageProjectListDto;
import NextLevel.demo.project.project.dto.response.ResponseProjectAllDto;
import NextLevel.demo.project.project.dto.response.ResponseProjectDetailDto;
import NextLevel.demo.project.project.dto.response.ResponseProjectListDetailDto;
import NextLevel.demo.project.project.dto.response.ResponseProjectListDto;
import NextLevel.demo.project.project.entity.ProjectEntity;
import NextLevel.demo.project.project.repository.ProjectDslRepository;
import NextLevel.demo.project.project.repository.ProjectRepository;
import NextLevel.demo.project.story.dto.ResponseProjectStoryListDto;
import NextLevel.demo.project.story.entity.ProjectStoryEntity;
import NextLevel.demo.project.story.service.ProjectStoryService;
import NextLevel.demo.project.tag.service.TagService;
import NextLevel.demo.project.view.ProjectViewService;
Expand Down Expand Up @@ -48,6 +44,7 @@ public class ProjectService {

private final FundingValidateService fundingValidateService;
private final ProjectDslRepository projectDslRepository;
private final ProjectValidateService projectValidateService;

// 추가
@ImgTransaction
Expand Down Expand Up @@ -134,20 +131,4 @@ public ResponseProjectDetailDto getProjectDetailById(Long id, Long userId) {
return ResponseProjectDetailDto.of(project, fundingPrice, fundingCount, userId);
}

// notice and community and story
// 추가 수정 필요!!! 정렬 어디다 팔아 먹음? 다시 만들것!
@Transactional
public ResponseProjectAllDto getProjectCommunityAndNoticeAndStoryDto(Long projectId) {
ProjectEntity project = projectRepository.findProjectWithNoticesAndCommunityAndStory(projectId).orElseThrow(
()-> new CustomException(ErrorCode.NOT_FOUND,"project")
);

return ResponseProjectAllDto
.builder()
.community(new ResponseCommunityListDto(project.getCommunities()))
.notice(new ResponseNoticeListDto(project.getNotices()))
.story(new ResponseProjectStoryListDto(project.getStories()))
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package NextLevel.demo.project.story.controller;

import NextLevel.demo.common.SuccessResponse;
import NextLevel.demo.project.story.dto.ResponseProjectStoryListDto;
import NextLevel.demo.project.story.service.ProjectStoryService;
import NextLevel.demo.util.jwt.JWTUtil;
import java.util.List;
Expand All @@ -9,6 +10,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -27,4 +29,9 @@ public ResponseEntity<?> updateProjectStory(@PathVariable("projectId") long proj
return ResponseEntity.status(HttpStatus.OK).body(new SuccessResponse("success",null));
}

@GetMapping("/public/project/{projectId}/story")
public ResponseEntity<?> getProjectStory(@PathVariable("projectId") long projectId){
return ResponseEntity.ok().body(new SuccessResponse("success", new ResponseProjectStoryListDto(projectStoryService.getProjectStory(projectId))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import NextLevel.demo.img.ImgDto;
import NextLevel.demo.project.story.entity.ProjectStoryEntity;
import java.util.List;
import java.util.Set;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -12,7 +11,7 @@
public class ResponseProjectStoryListDto {
private List<ImgDto> imgs;

public ResponseProjectStoryListDto (Set<ProjectStoryEntity> entities) {
public ResponseProjectStoryListDto (List<ProjectStoryEntity> entities) {
this.imgs = entities.stream().map(e-> new ImgDto(e.getImg())).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import NextLevel.demo.project.story.entity.ProjectStoryEntity;
import java.util.List;
import java.util.Set;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -13,4 +13,7 @@ public interface ProjectStoryRepository extends JpaRepository<ProjectStoryEntity
@Query("delete from ProjectStoryEntity s where s.project.id = :id")
void deleteAllByProjectId(@Param("id") Long projectId);

@Query("select ps from ProjectStoryEntity ps where ps.project.id = :projectId order by ps.img.id asc")
List<ProjectStoryEntity> findAllByProjectOrderByCreatedAt(@Param("projectId") Long projectId);

}
Loading
Loading