-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/shoeone96/wanted into fe…
…ature/#32-likes-API
- Loading branch information
Showing
21 changed files
with
312 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/com/clone/wanted/Company/CompanyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package com.clone.wanted.Company; | ||
|
||
import com.clone.wanted.User.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface CompanyRepository extends JpaRepository<Company,Long> { | ||
Optional<Company> findByUser(User user); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.clone.wanted.User; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface UserRepository extends JpaRepository<User, Long> { | ||
|
||
Optional<User> findByEmail(String email); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/com/clone/wanted/application/ApplicationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.clone.wanted.application; | ||
|
||
import com.clone.wanted.application.requestDto.EstimateRequestDto; | ||
import com.clone.wanted.application.responseDto.CompanyApplicationResponseDto; | ||
import com.clone.wanted.application.responseDto.UserApplicationResponseDto; | ||
import com.clone.wanted.config.BaseResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class ApplicationController { | ||
|
||
private final ApplicationService applicationService; | ||
/** | ||
* @param email | ||
* @return BaseResponse | ||
* TODO: spring security 단 이후 email 을 Authentication 으로 변경 | ||
*/ | ||
@PostMapping("api/v1/applications/{employmentId}") | ||
public BaseResponse<Void> enroll(@RequestBody String email, @PathVariable Long employmentId) { | ||
applicationService.enroll(email, employmentId); | ||
return BaseResponse.success(); | ||
} | ||
|
||
@PatchMapping("api/v1/applications/{employmentId}/estimate") | ||
public BaseResponse<Void> estimate(@RequestBody String email, @RequestBody EstimateRequestDto requestDto, @PathVariable Long employmentId){ | ||
applicationService.estimate(email, requestDto, employmentId); | ||
return BaseResponse.success(); | ||
} | ||
|
||
@PatchMapping("api/v1/applications/{employmentId}/cancel") | ||
public BaseResponse<Void> cancel(@RequestBody String email, @PathVariable Long employmentId){ | ||
applicationService.cancel(email, employmentId); | ||
return BaseResponse.success(); | ||
} | ||
|
||
@GetMapping("api/v1/applications") | ||
public BaseResponse<List<UserApplicationResponseDto>> getUserApplicationList(@RequestBody String email){ | ||
return BaseResponse.success(applicationService.getUserApplications(email)); | ||
} | ||
|
||
@GetMapping("api/v1/applications/{employmentId}") | ||
public BaseResponse<List<CompanyApplicationResponseDto>> getCompanyApplicationList(@RequestBody String email, @PathVariable Long employmentId){ | ||
return BaseResponse.success(applicationService.getCompanyApplications(email, employmentId)); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/clone/wanted/application/ApplicationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.clone.wanted.application; | ||
|
||
import com.clone.wanted.User.User; | ||
import com.clone.wanted.employment.Employment; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
interface ApplicationRepository extends JpaRepository<Application, Long> { | ||
|
||
Optional<Application> findByUserAndEmployment(User suer, Employment employment); | ||
List<Application> findAllByUser(User user); | ||
List<Application> findAllByEmployment(Employment employment); | ||
} |
88 changes: 88 additions & 0 deletions
88
src/main/java/com/clone/wanted/application/ApplicationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.clone.wanted.application; | ||
|
||
import com.clone.wanted.Company.Company; | ||
import com.clone.wanted.Company.CompanyRepository; | ||
import com.clone.wanted.User.User; | ||
import com.clone.wanted.User.UserRepository; | ||
import com.clone.wanted.User.UserType; | ||
import com.clone.wanted.application.requestDto.EstimateRequestDto; | ||
import com.clone.wanted.application.responseDto.CompanyApplicationResponseDto; | ||
import com.clone.wanted.application.responseDto.UserApplicationResponseDto; | ||
import com.clone.wanted.config.BaseException; | ||
import com.clone.wanted.config.BaseResponseStatus; | ||
import com.clone.wanted.employment.Employment; | ||
import com.clone.wanted.employment.EmploymentRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class ApplicationService { | ||
|
||
private final UserRepository userRepository; | ||
private final EmploymentRepository employmentRepository; | ||
private final ApplicationRepository applicationRepository; | ||
private final CompanyRepository companyRepository; | ||
public void enroll(String email, Long employmentId) { | ||
User user = userRepository.findByEmail(email) | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.USER_NOT_FOUND)); | ||
Employment employment = employmentRepository.findById(employmentId) | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.EMPLOYMENT_NOT_FOUND)); | ||
applicationRepository.findByUserAndEmployment(user, employment) | ||
.ifPresent((application -> { | ||
if(application.getApplicationStatus() == ApplicationStatus.CANCEL) { | ||
application.updateStatus(ApplicationStatus.ONGOING); | ||
} else throw new BaseException(BaseResponseStatus.APPLICATION_ALREADY_EXIST); | ||
})); | ||
applicationRepository.save(Application.newEnrollment(user, employment)); | ||
} | ||
|
||
public void estimate(String email, EstimateRequestDto requestDto, Long employmentId) { | ||
User user = userRepository.findByEmail(email) | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.USER_NOT_FOUND)); | ||
if(user.getUserType() == UserType.CORPORATE_USER) throw new BaseException(BaseResponseStatus.REQUEST_NOT_ALLOWED); | ||
Employment employment = employmentRepository.findById(employmentId) | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.EMPLOYMENT_NOT_FOUND)); | ||
Application application = applicationRepository.findByUserAndEmployment(user, employment) | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.EMPLOYMENT_NOT_FOUND)); | ||
application.updateStatus(ApplicationStatus.returnStatus(requestDto.getApplicationStatus())); | ||
} | ||
|
||
public void cancel(String email, Long employmentId) { | ||
User user = userRepository.findByEmail(email) | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.USER_NOT_FOUND)); | ||
Employment employment = employmentRepository.findById(employmentId) | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.EMPLOYMENT_NOT_FOUND)); | ||
Application application = applicationRepository.findByUserAndEmployment(user, employment) | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.EMPLOYMENT_NOT_FOUND)); | ||
application.updateStatus(ApplicationStatus.CANCEL); | ||
} | ||
|
||
public List<UserApplicationResponseDto> getUserApplications(String email) { | ||
User user = userRepository.findByEmail(email) | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.USER_NOT_FOUND)); | ||
return applicationRepository.findAllByUser(user) | ||
.stream() | ||
.map(UserApplicationResponseDto::of) | ||
.toList(); | ||
} | ||
|
||
public List<CompanyApplicationResponseDto> getCompanyApplications(String email, Long employmentId) { | ||
User user = userRepository.findByEmail(email) | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.USER_NOT_FOUND)); | ||
if(user.getUserType() == UserType.CORPORATE_USER) throw new BaseException(BaseResponseStatus.REQUEST_NOT_ALLOWED); | ||
Company company = companyRepository.findByUser(user) | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.COMPANY_NOT_FOUND)); | ||
if(company.getUser() != user) throw new BaseException(BaseResponseStatus.REQUEST_NOT_ALLOWED); | ||
Employment employment = employmentRepository.findById(employmentId) | ||
.orElseThrow(() -> new BaseException(BaseResponseStatus.EMPLOYMENT_NOT_FOUND)); | ||
return applicationRepository.findAllByEmployment(employment) | ||
.stream() | ||
.map(CompanyApplicationResponseDto::of) | ||
.toList(); | ||
} | ||
} |
8 changes: 7 additions & 1 deletion
8
src/main/java/com/clone/wanted/application/ApplicationStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
package com.clone.wanted.application; | ||
|
||
public enum ApplicationStatus { | ||
ONGOING, CANCEL, FAIL, PASS | ||
ONGOING, CANCEL, FAIL, PASS; | ||
public static ApplicationStatus returnStatus(String type){ | ||
if(type.equals("ONGOING")) return ApplicationStatus.ONGOING; | ||
if(type.equals("CANCEL")) return ApplicationStatus.CANCEL; | ||
if(type.equals("FAIL")) return ApplicationStatus.FAIL; | ||
return ApplicationStatus.PASS; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/clone/wanted/application/requestDto/EstimateRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.clone.wanted.application.requestDto; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor | ||
@Getter | ||
public class EstimateRequestDto { | ||
public String applicationStatus; | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/clone/wanted/application/responseDto/CompanyApplicationResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.clone.wanted.application.responseDto; | ||
|
||
import com.clone.wanted.application.Application; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CompanyApplicationResponseDto { | ||
|
||
private Long employmentId; | ||
private String username; | ||
private String position; | ||
private LocalDateTime registerDate; | ||
private String applicationStatus; | ||
|
||
public static CompanyApplicationResponseDto of(Application application){ | ||
return new CompanyApplicationResponseDto( | ||
application.getEmployment().getId(), | ||
application.getUser().getUsername(), | ||
application.getEmployment().getEmploymentTitle(), | ||
application.getCreatedAt(), | ||
application.getApplicationStatus().name()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/clone/wanted/application/responseDto/UserApplicationResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.clone.wanted.application.responseDto; | ||
|
||
import com.clone.wanted.application.Application; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class UserApplicationResponseDto { | ||
private Long employmentId; | ||
private String companyName; | ||
private String position; | ||
private LocalDateTime registerDate; | ||
private String applicationStatus; | ||
|
||
public static UserApplicationResponseDto of(Application application){ | ||
return new UserApplicationResponseDto( | ||
application.getEmployment().getId(), | ||
application.getEmployment().getCompany().getCompanyName(), | ||
application.getEmployment().getEmploymentTitle(), | ||
application.getCreatedAt(), | ||
application.getApplicationStatus().name()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.