Skip to content

Commit

Permalink
Merge pull request #277 from techeer-sv/FE/#268
Browse files Browse the repository at this point in the history
Fe/#268 MyPage 마이그레이션 및 기능 구현
  • Loading branch information
Mayreeel committed Oct 24, 2023
2 parents e96e49f + e98f0b9 commit 6433769
Show file tree
Hide file tree
Showing 118 changed files with 3,842 additions and 452 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ jobs:
run: |
cd backend/src/main/resources
touch ./application-local.yml
touch ./application-docker.yml
echo "${{ secrets.TEST_PROPERTIES }}" > ./application-local.yml
echo "${{ secrets.DOCKER_TEST_PROPERTIES }}" > ./application-docker.yml
cd ../../test/resources
touch ./application-test.yml
echo "${{ secrets.INTEGRATION_TEST_PROPERTIES }}" > ./application-test.yml
shell: bash

- name: Test with Gradle
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ logs/
logs/

backend/src/main/resources/application-local.yml
backend/src/test/resources/application-test.yml

backend/src/main/resources/static/docs/
8 changes: 7 additions & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ dependencies {
// spring-boot
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'

implementation 'org.json:json:20210307'

Expand All @@ -59,7 +61,11 @@ dependencies {

// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'com.h2database:h2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
testImplementation 'org.testcontainers:testcontainers:1.19.0'
testImplementation 'org.testcontainers:junit-jupiter:1.19.0'
testImplementation "org.testcontainers:mysql:1.19.0"


//rest-docs
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.graphy.backend.domain.bookmark.domain;

import com.graphy.backend.domain.member.domain.Member;
import com.graphy.backend.domain.recruitment.domain.Recruitment;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Bookmark {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "recruitment_id")
private Recruitment recruitment;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
@Entity
@AllArgsConstructor
@Builder

/*
* TODO
* Hard Delete 하기 위해서 제거해야 될 거 같아요
*/
@SQLDelete(sql = "UPDATE comment SET is_deleted = true WHERE comment_id = ?")
public class Comment extends BaseEntity {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.graphy.backend.domain.follow.domain;

import com.graphy.backend.domain.member.domain.Member;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,63 @@
import com.graphy.backend.domain.member.domain.Member;
import com.graphy.backend.domain.member.dto.response.GetMemberListResponse;
import com.graphy.backend.domain.member.repository.MemberRepository;
import com.graphy.backend.domain.member.service.MemberService;
import com.graphy.backend.domain.notification.domain.NotificationType;
import com.graphy.backend.domain.notification.dto.NotificationDto;
import com.graphy.backend.domain.notification.service.NotificationService;
import com.graphy.backend.global.error.ErrorCode;
import com.graphy.backend.global.error.exception.AlreadyExistException;
import com.graphy.backend.global.error.exception.EmptyResultException;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.transaction.Transactional;
import java.util.List;


@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
@Service
@Transactional
@Transactional(readOnly = true)
public class FollowService {
private final FollowRepository followRepository;
private final MemberRepository memberRepository;

private final NotificationService notificationService;
private final MemberService memberService;


@Transactional
public void addFollow(Long toId, Member loginUser) {
memberService.findMemberById(loginUser.getId());

Long fromId = loginUser.getId();
checkFollowingAlready(loginUser.getId(), toId);
checkFollowAvailable(loginUser.getId(), toId);

Follow follow = Follow.builder().fromId(fromId).toId(toId).build();
NotificationType notificationType = NotificationType.FOLLOW;
notificationType.setMessage(loginUser.getNickname(), "");
NotificationDto notificationDto = NotificationDto.builder()
.type(notificationType)
.content(notificationType.getMessage())
.build();

followRepository.save(follow);
memberRepository.increaseFollowerCount(toId);
memberRepository.increaseFollowingCount(fromId);

notificationService.addNotification(notificationDto, toId);
}

@Transactional
public void removeFollow(Long toId, Member loginUser) {
Long fromId = loginUser.getId();
Follow follow = followRepository.findByFromIdAndToId(fromId, toId).orElseThrow(
() -> new EmptyResultException(ErrorCode.FOLLOW_NOT_EXIST)
);
followRepository.delete(follow);

// TODO: memberService의 메소드로 분리
memberRepository.decreaseFollowerCount(toId);
memberRepository.decreaseFollowingCount(fromId);
}
Expand All @@ -50,9 +74,12 @@ public List<GetMemberListResponse> findFollowingList(Member loginUser) {
return followRepository.findFollowings(loginUser.getId());
}

public void checkFollowingAlready(Long fromId, Long toId) {
public void checkFollowAvailable(Long fromId, Long toId) {
if (followRepository.existsByFromIdAndToId(fromId, toId)) {
throw new AlreadyExistException(ErrorCode.FOLLOW_ALREADY_EXIST);
}
if (fromId.equals(toId)) {
throw new AlreadyExistException(ErrorCode.FOLLOW_SELF);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.graphy.backend.domain.job.controller;

import com.graphy.backend.domain.job.dto.response.GetJobResponse;
import com.graphy.backend.domain.job.service.JobService;
import com.graphy.backend.global.common.PageRequest;
import com.graphy.backend.global.error.ErrorCode;
import com.graphy.backend.global.error.exception.EmptyResultException;
import com.graphy.backend.global.result.ResultCode;
import com.graphy.backend.global.result.ResultResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Tag(name = "EmploymentController", description = "신규 채용 공고 API")
Expand All @@ -15,18 +23,13 @@
public class JobController {
private final JobService jobService;

@Operation(summary = "Save JobInfo", description = "신규 공고 저장")
@Scheduled(cron = "0 0 0 */3 * *")
@PostMapping
public void save(){
jobService.save();
}

@Operation(summary = "findJobList", description = "채용공고 조회")
@GetMapping
public ResponseEntity<ResultResponse> jobList(PageRequest pageRequest) {
Pageable pageable = pageRequest.jobOf();
List<GetJobResponse> result = jobService.findJobList(pageable);
if (result.isEmpty()) throw new EmptyResultException(ErrorCode.JOB_DELETED_OR_NOT_EXIST);

@Operation(summary = "Delete Job", description = "만료일이 지난 공고 삭제")
@Scheduled(cron = "0 0 0 * * *")
@DeleteMapping
public void deleteExpiredJobs(){
jobService.deleteExpiredJobs();
return ResponseEntity.ok(ResultResponse.of(ResultCode.JOB_PAGING_GET_SUCCESS, result));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public class Job {
@Id
@Column(name = "job_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.graphy.backend.domain.job.dto.response;

import com.graphy.backend.domain.job.domain.Job;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GetJobResponse {

private Long id;

private String companyName;

private String title;

private String url;

private LocalDateTime expirationDate;

public static GetJobResponse from(Job job) {
return GetJobResponse.builder()
.id(job.getId())
.companyName(job.getCompanyName())
.title(job.getTitle())
.url(job.getUrl())
.expirationDate(job.getExpirationDate())
.build();
}

public static Page<GetJobResponse> listOf(Page<Job> jobs) {
return jobs.map(GetJobResponse::from);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.graphy.backend.domain.job.repository;

import com.graphy.backend.domain.job.domain.Job;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.time.LocalDateTime;

public interface JobRepository extends JpaRepository<Job, Long> {
@Modifying
@Query("DELETE FROM Job j WHERE j.expirationDate < :today")
void deleteAllExpiredSince(LocalDateTime today);

@Override
Page<Job> findAll(Pageable pageable);
}
Loading

0 comments on commit 6433769

Please sign in to comment.