Skip to content

Commit

Permalink
#26 feat: 지원 시 지원파트 size 감소 코드 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui committed Feb 2, 2024
1 parent e003ad6 commit 1caf13a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public record ApplicationRes(
Boolean is_decision,
String application,
String recruit_part,
List<String> list
List<String> category
) {
public static ApplicationRes of(Apply apply,List<String> list){
return new ApplicationRes(apply.getIs_decision(),apply.getApplication(), apply.getRecruit_part(),list);
public static ApplicationRes of(Apply apply,List<String> category){
return new ApplicationRes(apply.getIs_decision(),apply.getApplication(), apply.getRecruit_part(),category);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.gongjakso.server.domain.member.entity.Member;
import com.gongjakso.server.domain.post.entity.Category;
import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.enumerate.CategoryType;
import com.gongjakso.server.domain.post.repository.CategoryRepository;
import com.gongjakso.server.domain.post.repository.PostRepository;
import com.gongjakso.server.global.common.ApplicationResponse;
Expand Down Expand Up @@ -40,7 +41,13 @@ public Apply save(Member member, Long post_id, ApplyReq req){
throw new ApplicationException(ErrorCode.NOT_APPLY_EXCEPTION);
}else {
Apply apply = req.toEntity(member, post);
return applyRepository.save(apply);
Category category = categoryRepository.findCategoryByPostAndCategoryType(post, CategoryType.valueOf(req.recruit_part()));
if(category.getSize()-1<=0){
throw new ApplicationException(ErrorCode.OVER_APPLY_EXCEPTION);
}else {
category.setSize(category.getSize()-1);
return applyRepository.save(apply);
}
}
}else {
throw new ApplicationException(ErrorCode.ALREADY_APPLY_EXCEPTION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import com.gongjakso.server.domain.post.enumerate.CategoryType;
import com.gongjakso.server.global.common.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

@Getter
@Setter
@Entity
@Table(name = "category")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.gongjakso.server.domain.post.entity.Category;
import com.gongjakso.server.domain.post.entity.Post;
import com.gongjakso.server.domain.post.enumerate.CategoryType;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface CategoryRepository extends JpaRepository<Category, Long> {
List<Category> findCategoryByPost(Post post);
Category findCategoryByPostAndCategoryType(Post post, CategoryType categoryType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public enum ErrorCode {
ALREADY_APPLY_EXCEPTION(HttpStatus.BAD_REQUEST,4003,"이미 지원했습니다."),
ALREADY_DECISION_EXCEPION(HttpStatus.BAD_REQUEST,4004,"이미 지원 결정했습니다."),
NOT_RECRUITING_EXCEPION(HttpStatus.BAD_REQUEST,4005,"이 공고는 모집 중이 아닙니다."),
NOT_FOUND_CATEGORY_EXCEPTION(HttpStatus.NOT_FOUND,4006,"카테고리가 없습니다");
NOT_FOUND_CATEGORY_EXCEPTION(HttpStatus.NOT_FOUND,4006,"카테고리가 없습니다"),
OVER_APPLY_EXCEPTION(HttpStatus.NOT_FOUND,4007,"지원 파트 정원이 찼습니다.");

private final HttpStatus httpStatus;
private final Integer code;
Expand Down

0 comments on commit 1caf13a

Please sign in to comment.