diff --git a/backend/src/main/java/com/graphy/backend/domain/member/domain/Member.java b/backend/src/main/java/com/graphy/backend/domain/member/domain/Member.java index b2676044..666705d3 100644 --- a/backend/src/main/java/com/graphy/backend/domain/member/domain/Member.java +++ b/backend/src/main/java/com/graphy/backend/domain/member/domain/Member.java @@ -9,6 +9,10 @@ import javax.persistence.*; +/** + * TODO + * imageUrl 추가 + */ @Entity @Getter @Builder diff --git a/backend/src/main/java/com/graphy/backend/domain/project/domain/ProjectImage.java b/backend/src/main/java/com/graphy/backend/domain/project/domain/ProjectImage.java index fa5a1683..7a8e0875 100644 --- a/backend/src/main/java/com/graphy/backend/domain/project/domain/ProjectImage.java +++ b/backend/src/main/java/com/graphy/backend/domain/project/domain/ProjectImage.java @@ -1,10 +1,16 @@ package com.graphy.backend.domain.project.domain; import com.graphy.backend.global.common.BaseEntity; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; import javax.persistence.*; +/** + * 삭제 + */ @Entity @Getter @Builder diff --git a/backend/src/main/java/com/graphy/backend/domain/project/dto/response/GetProjectDetailResponse.java b/backend/src/main/java/com/graphy/backend/domain/project/dto/response/GetProjectDetailResponse.java index ed952949..d94d8435 100644 --- a/backend/src/main/java/com/graphy/backend/domain/project/dto/response/GetProjectDetailResponse.java +++ b/backend/src/main/java/com/graphy/backend/domain/project/dto/response/GetProjectDetailResponse.java @@ -36,6 +36,10 @@ public class GetProjectDetailResponse implements Serializable { private String thumbNail; private List commentsList; + /** + * TODO + * viewCount 추가 + */ @JsonSerialize(using = LocalDateTimeSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) diff --git a/backend/src/main/java/com/graphy/backend/domain/project/service/ProjectService.java b/backend/src/main/java/com/graphy/backend/domain/project/service/ProjectService.java index 1ec03503..51b42855 100644 --- a/backend/src/main/java/com/graphy/backend/domain/project/service/ProjectService.java +++ b/backend/src/main/java/com/graphy/backend/domain/project/service/ProjectService.java @@ -13,7 +13,6 @@ import com.graphy.backend.domain.project.dto.request.UpdateProjectRequest; import com.graphy.backend.domain.project.dto.response.*; import com.graphy.backend.domain.project.repository.ProjectRepository; -import com.graphy.backend.domain.project.repository.TagRepository; import com.graphy.backend.global.chatgpt.dto.GptCompletionDto.GptCompletionRequest; import com.graphy.backend.global.chatgpt.dto.GptCompletionDto.GptCompletionResponse; import com.graphy.backend.global.chatgpt.service.GPTChatRestService; @@ -56,7 +55,6 @@ public class ProjectService { private final CommentService commentService; private final TagService tagService; private final GPTChatRestService gptChatRestService; - private final TagRepository tagRepository; private final RedisTemplate redisTemplate; private final RedisTemplate redisRankingTemplate; private final String RANKING_KEY = "ranking"; @@ -65,22 +63,6 @@ public class ProjectService { private final int END_RANKING = 9; private int NEXT_RANKING = END_RANKING; - -// @PostConstruct -// public void initTag() throws IOException { -// if (tagRepository.existsById(1L)) -// return; -// ClassPathResource resource = new ClassPathResource("tag.txt"); -// BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream())); -// String s; -// -// while ((s = br.readLine()) != null) { -// Tag tag = Tag.builder().tech(s).build(); -// tagRepository.save(tag); -// } -// br.close(); -// } - @Transactional public CreateProjectResponse addProject(CreateProjectRequest dto, Member loginUser) { Project entity = dto.toEntity(loginUser); diff --git a/backend/src/main/java/com/graphy/backend/domain/project/util/ProjectInitializer.java b/backend/src/main/java/com/graphy/backend/domain/project/util/ProjectInitializer.java new file mode 100644 index 00000000..273ee824 --- /dev/null +++ b/backend/src/main/java/com/graphy/backend/domain/project/util/ProjectInitializer.java @@ -0,0 +1,118 @@ +package com.graphy.backend.domain.project.util; + +import com.graphy.backend.domain.comment.repository.CommentRepository; +import com.graphy.backend.domain.member.domain.Member; +import com.graphy.backend.domain.member.repository.MemberRepository; +import com.graphy.backend.domain.project.domain.Project; +import com.graphy.backend.domain.project.domain.ProjectTags; +import com.graphy.backend.domain.project.domain.Tag; +import com.graphy.backend.domain.project.domain.Tags; +import com.graphy.backend.domain.project.repository.ProjectRepository; +import com.graphy.backend.domain.project.repository.TagRepository; +import com.graphy.backend.domain.project.service.ProjectService; +import com.graphy.backend.domain.project.service.TagService; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.core.io.ClassPathResource; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Component; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@Component +@RequiredArgsConstructor +public class ProjectInitializer implements ApplicationRunner { + private final MemberRepository memberRepository; + private final PasswordEncoder encoder; + + private final ProjectRepository projectRepository; + private final ProjectService projectService; + + private final CommentRepository commentRepository; + + private final TagRepository tagRepository; + private final TagService tagService; + + private final RedisTemplate redisTemplate; + + @Override + public void run(ApplicationArguments args) throws Exception { + if (tagRepository.existsById(1L)) return; + + ClassPathResource resource = new ClassPathResource("tag.txt"); + BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream())); + + String s; + List tagList = new ArrayList<>(); + while ((s = br.readLine()) != null) { + Tag tag = Tag.builder().tech(s).build(); + tagList.add(tag.getTech()); + tagRepository.save(tag); + } + br.close(); + + String[] team = new String[]{"Yujin-Baek", "baekhangyeol", "kimhalin", "youKeon", "Mayreeel"}; + memberRepository.save(Member.builder() + .email("admin@graphy.com") + .nickname("ADMIN") + .password(encoder.encode("12345")) + .build()); + + for (int i = 0; i < 5; i++) { + memberRepository.save(Member.builder() + .email(team[i] + "@graphy.com") + .nickname(team[i]) + .password(encoder.encode("12345")) + .build()); + } + + int randomNumber = (int) (Math.random() * 4) + 3; + List members = memberRepository.findAll(); + for (int i = 1; i <= 100; i++) { + Tags tags = null; + for (int j = 0; j < randomNumber; j++) { + Collections.shuffle(tagList); + tags = tagService.findTagListByName(tagList.subList(0, 3 + (int) (Math.random() * 4))); + } + + Project project = Project.builder() + .member(members.get((int) (Math.random() * 5) + 1)) + .projectName("Project" + i) + .description("Description" + i) + .viewCount(30 + (int) (Math.random() * (900 - 30 + 1))) + .content("Content" + i) + .thumbNail("ThumbNail" + i) + .projectTags(new ProjectTags()) + .build(); + project.addTag(tags); + projectRepository.save(project); +// for (int j = 0; j < 10; j++) { +// for (int k = 0; k < (Math.random() * 5) + 1; k++) { +// +// } +// commentRepository.save(Comment.builder() +// .parent(null) +// .project(project) +// .member(members.get((int) (Math.random() * 5) + 1)) +// .childList() +// .content("comment" + j) +// .build()); +// } + } + + // Redis Sorted Set에 데이터 저장 + List projects = projectRepository.findAll(); + for (Project p : projects) { + redisTemplate.opsForZSet().incrementScore("ranking", p.getId(), p.getViewCount()); + } + + // Redis에 상위 10개 프로젝트 저장 + projectService.initializeProjectRanking(); + } +} diff --git a/backend/src/main/java/com/graphy/backend/domain/recruitment/controller/RecruitmentController.java b/backend/src/main/java/com/graphy/backend/domain/recruitment/controller/RecruitmentController.java index 88c08635..920729b0 100644 --- a/backend/src/main/java/com/graphy/backend/domain/recruitment/controller/RecruitmentController.java +++ b/backend/src/main/java/com/graphy/backend/domain/recruitment/controller/RecruitmentController.java @@ -47,6 +47,10 @@ public ResponseEntity recruitmentDetails(@PathVariable Long recr return ResponseEntity.ok(ResultResponse.of(ResultCode.RECRUITMENT_GET_SUCCESS, result)); } + /** + * 모집 여부 필터링 + * 모집 중 필터링 + */ @Operation(summary = "findRecruitmentList", description = "구인 게시글 조회") @GetMapping public ResponseEntity recruitmentList(@RequestParam(required = false) List positions, diff --git a/backend/src/main/java/com/graphy/backend/domain/recruitment/domain/Recruitment.java b/backend/src/main/java/com/graphy/backend/domain/recruitment/domain/Recruitment.java index ef144f54..a758a6d8 100644 --- a/backend/src/main/java/com/graphy/backend/domain/recruitment/domain/Recruitment.java +++ b/backend/src/main/java/com/graphy/backend/domain/recruitment/domain/Recruitment.java @@ -14,6 +14,9 @@ import java.time.LocalDateTime; import java.util.List; +/** + * 조회수 속성 추가 + */ @Entity @Getter @Builder