diff --git a/src/main/java/umc/kkijuk/server/career/controller/BaseCareerController.java b/src/main/java/umc/kkijuk/server/career/controller/BaseCareerController.java index 8f6203b1..8bc52ec5 100644 --- a/src/main/java/umc/kkijuk/server/career/controller/BaseCareerController.java +++ b/src/main/java/umc/kkijuk/server/career/controller/BaseCareerController.java @@ -15,10 +15,9 @@ import umc.kkijuk.server.member.domain.Member; import umc.kkijuk.server.member.service.MemberService; -import java.util.List; -@Tag(name="basecareer",description = "활동 관련 API") +@Tag(name="Career",description = "활동 생성, 수정, 삭제 관련 API") @RestController @RequiredArgsConstructor @RequestMapping("/career") @@ -191,29 +190,31 @@ public CareerResponse updateProject( baseCareerService.updateProject(requestMember, projectId, projectReqDto) ); } - @GetMapping("") - @Operation( - summary = "활동 목록", - description = "활동을 조회합니다. query 값으로 category(카테고리 기준), year(연도 기준), 또는 all(전체 조회) 중 하나를 선택하여 요청해주세요." ) - public CareerResponse findAllCareersGroupedYear( + @PostMapping("/etc") + @Operation(summary = "커리어(기타) 생성", description = "주어진 정보를 바탕으로 활동을 추가합니다.") + public CareerResponse createEtc( @Login LoginInfo loginInfo, - @RequestParam(name="status") String value + @Valid @RequestBody EtcReqDto etcReqDto ) { Member requestMember = memberService.getById(loginInfo.getMemberId()); - if(value.equals("category")){ - return CareerResponse.success( - CareerResponseMessage.CAREER_FINDALL_SUCCESS, - baseCareerService.findAllCareerGroupedCategory(requestMember.getId()) - ); - }else if (value.equals("all")){ - return CareerResponse.success( - CareerResponseMessage.CAREER_FINDALL_SUCCESS, - baseCareerService.findAllCareer(requestMember.getId()) - ); - } return CareerResponse.success( - CareerResponseMessage.CAREER_FINDALL_SUCCESS, - baseCareerService.findAllCareerGroupedYear(requestMember.getId()) + CareerResponseMessage.CAREER_CREATE_SUCCESS, + baseCareerService.createEtc(requestMember, etcReqDto) + ); + } + + @PatchMapping("/etc/{etcId}") + @Operation(summary = "커리어(기타) 수정", description = "활동 ID에 해당하는 활동을 수정합니다.") + @Parameter(name="etcId", description = "커리어(기타) Id, path variable 입니다.",example = "1") + public CareerResponse updateEtc( + @Login LoginInfo loginInfo, + @PathVariable Long etcId, + @Valid @RequestBody EtcReqDto etcReqDto + ) { + Member requestMember = memberService.getById(loginInfo.getMemberId()); + return CareerResponse.success( + CareerResponseMessage.CAREER_UPDATE_SUCCESS, + baseCareerService.updateEtc(requestMember, etcId, etcReqDto) ); } @@ -233,20 +234,7 @@ public CareerResponse deleteBaseCareer( ); } - @GetMapping("/{type}/{careerId}") - @Operation(summary = "활동 상세", description = "활동 ID에 해당하는 활동의 세부 내용과, 활동 기록을 조회합니다.") - @Parameter(name = "careerId", description = "활동 Id, path variable 입니다.", example = "1") - public CareerResponse findCareer( - @Login LoginInfo loginInfo, - @PathVariable String type, - @PathVariable Long careerId - ){ - Member requestMember = memberService.getById(loginInfo.getMemberId()); - return CareerResponse.success( - CareerResponseMessage.CAREER_FINDALL_SUCCESS, - baseCareerService.findCareer(requestMember, careerId, type) - ); - } + @PatchMapping("/{careerId}") @Operation(summary = "활동 내역 수정", description = "활동 ID에 해당하는 활동에 활동 내역을 추가합니다.") @Parameter(name = "careerId", description = "활동 Id, path variable 입니다.", example = "1") @@ -262,83 +250,4 @@ public CareerResponse createSummary( ); } - @GetMapping("/find/detail") - @Operation( - summary = "활동 검색 - 활동 기록", - description = "활동기록을 주어진 조건에 맞추어 조회합니다. query 값으로 검색어(keyword)와 정렬 기준(new,old)을 요청해주세요. " ) - public CareerResponse> findDetail( - @Login LoginInfo loginInfo, - @RequestParam(name="keyword")String keyword, - @RequestParam(name="sort") String sort - ) { - Member reqeustMember = memberService.getById(loginInfo.getMemberId()); - return CareerResponse.success( - CareerResponseMessage.CAREER_FINDALL_SUCCESS, - baseCareerService.findAllDetail(reqeustMember,keyword,sort) - ); - } - - @GetMapping("/find/taglist") - @Operation( - summary = "활동 검색 - 태그 ( 검색 태그 조회 )", - description = "검색어를 포함하는 활동 태그들을 가나다 순으로 조회합니다. " + - "query 값으로 검색어(keyword)를 요청해주세요. " ) - public CareerResponse> findTag( - @Login LoginInfo loginInfo, - @RequestParam(name="keyword")String keyword - ) { - Member requestMember = memberService.getById(loginInfo.getMemberId()); - return CareerResponse.success( - CareerResponseMessage.CAREER_SEARCH_SUCCESS, - baseCareerService.findAllTag(requestMember, keyword) - ); - } - - @GetMapping("/find/tag") - @Operation( - summary = "활동 검색 - 태그 ( 선택한 태그에 대한 활동 기록 조회 )", - description = "선택한 태그를 포함하는 활동 기록들을 조회합니다. " + - " query 값으로 태그의 ID 와 정렬 기준(new,old)을 요청해주세요. " ) - public CareerResponse> findTagAndDetail( - @Login LoginInfo loginInfo, - @RequestParam(name="tagId") Long tagId, - @RequestParam(name="sort") String sort - ){ - Member requestMember = memberService.getById(loginInfo.getMemberId()); - return CareerResponse.success( - CareerResponseMessage.CAREER_FINDALL_SUCCESS, - baseCareerService.findAllDetailByTag(requestMember, tagId, sort) - ); - } - @GetMapping("/find") - @Operation( - summary = "활동 검색 - 활동", - description = "활동을 주어진 조건에 맞추어 조회합니다. query 값으로 검색어(keyword)와 정렬 기준(new,old)을 요청해주세요. " ) - public CareerResponse> findCareerWithKeyword( - @Login LoginInfo loginInfo, - @RequestParam(name = "keyword") String keyword, - @RequestParam(name = "sort") String sort - ){ - Member requestMember = memberService.getById(loginInfo.getMemberId()); - return CareerResponse.success( - CareerResponseMessage.CAREER_FINDALL_SUCCESS, - baseCareerService.findCareerWithKeyword(requestMember, keyword, sort) - ); - - } - @GetMapping("/timeline") - @Operation( - summary = "활동 타임라인", - description = "타임라인에 필요한 활동 정보들을 조회합니다.") - public CareerResponse> findCareerForTimeline( - @Login LoginInfo loginInfo - ){ - Member requestMember = memberService.getById(loginInfo.getMemberId()); - return CareerResponse.success( - CareerResponseMessage.CAREER_FINDALL_SUCCESS, - baseCareerService.findCareerForTimeline(requestMember) - ); - - } - } diff --git a/src/main/java/umc/kkijuk/server/career/controller/CareerSearchController.java b/src/main/java/umc/kkijuk/server/career/controller/CareerSearchController.java new file mode 100644 index 00000000..f8e84a23 --- /dev/null +++ b/src/main/java/umc/kkijuk/server/career/controller/CareerSearchController.java @@ -0,0 +1,142 @@ +package umc.kkijuk.server.career.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; +import umc.kkijuk.server.career.controller.response.*; +import umc.kkijuk.server.career.service.BaseCareerService; +import umc.kkijuk.server.login.argumentresolver.Login; +import umc.kkijuk.server.login.controller.dto.LoginInfo; +import umc.kkijuk.server.member.domain.Member; +import umc.kkijuk.server.member.service.MemberService; + +import java.util.List; + +@Tag(name="Search Career", description = "활동 조회 및 검색 관련 API") +@RestController +@RequiredArgsConstructor +@RequestMapping("/career") +public class CareerSearchController { + private final BaseCareerService baseCareerService; + private final MemberService memberService; + @GetMapping("") + @Operation( + summary = "활동 목록", + description = "활동을 조회합니다. query 값으로 category(카테고리 기준), year(연도 기준), 또는 all(전체 조회) 중 하나를 선택하여 요청해주세요." ) + public CareerResponse findAllCareersGroupedYear( + @Login LoginInfo loginInfo, + @RequestParam(name="status") String value + ) { + Member requestMember = memberService.getById(loginInfo.getMemberId()); + if(value.equals("category")){ + return CareerResponse.success( + CareerResponseMessage.CAREER_FINDALL_SUCCESS, + baseCareerService.findAllCareerGroupedCategory(requestMember.getId()) + ); + }else if (value.equals("all")){ + return CareerResponse.success( + CareerResponseMessage.CAREER_FINDALL_SUCCESS, + baseCareerService.findAllCareer(requestMember.getId()) + ); + } + return CareerResponse.success( + CareerResponseMessage.CAREER_FINDALL_SUCCESS, + baseCareerService.findAllCareerGroupedYear(requestMember.getId()) + ); + } + @GetMapping("/{type}/{careerId}") + @Operation(summary = "활동 상세", description = "활동 ID에 해당하는 활동의 세부 내용과, 활동 기록을 조회합니다.") + @Parameter(name = "careerId", description = "활동 Id, path variable 입니다.", example = "1") + public CareerResponse findCareer( + @Login LoginInfo loginInfo, + @PathVariable String type, + @PathVariable Long careerId + ){ + Member requestMember = memberService.getById(loginInfo.getMemberId()); + return CareerResponse.success( + CareerResponseMessage.CAREER_FINDALL_SUCCESS, + baseCareerService.findCareer(requestMember, careerId, type) + ); + } + @GetMapping("/find/detail") + @Operation( + summary = "활동 검색 - 활동 기록", + description = "활동기록을 주어진 조건에 맞추어 조회합니다. query 값으로 검색어(keyword)와 정렬 기준(new,old)을 요청해주세요. " ) + public CareerResponse> findDetail( + @Login LoginInfo loginInfo, + @RequestParam(name="keyword")String keyword, + @RequestParam(name="sort") String sort + ) { + Member reqeustMember = memberService.getById(loginInfo.getMemberId()); + return CareerResponse.success( + CareerResponseMessage.CAREER_FINDALL_SUCCESS, + baseCareerService.findAllDetail(reqeustMember,keyword,sort) + ); + } + + @GetMapping("/find/taglist") + @Operation( + summary = "활동 검색 - 태그 ( 검색 태그 조회 )", + description = "검색어를 포함하는 활동 태그들을 가나다 순으로 조회합니다. " + + "query 값으로 검색어(keyword)를 요청해주세요. " ) + public CareerResponse> findTag( + @Login LoginInfo loginInfo, + @RequestParam(name="keyword")String keyword + ) { + Member requestMember = memberService.getById(loginInfo.getMemberId()); + return CareerResponse.success( + CareerResponseMessage.CAREER_SEARCH_SUCCESS, + baseCareerService.findAllTag(requestMember, keyword) + ); + } + + @GetMapping("/find/tag") + @Operation( + summary = "활동 검색 - 태그 ( 선택한 태그에 대한 활동 기록 조회 )", + description = "선택한 태그를 포함하는 활동 기록들을 조회합니다. " + + " query 값으로 태그의 ID 와 정렬 기준(new,old)을 요청해주세요. " ) + public CareerResponse> findTagAndDetail( + @Login LoginInfo loginInfo, + @RequestParam(name="tagId") Long tagId, + @RequestParam(name="sort") String sort + ){ + Member requestMember = memberService.getById(loginInfo.getMemberId()); + return CareerResponse.success( + CareerResponseMessage.CAREER_FINDALL_SUCCESS, + baseCareerService.findAllDetailByTag(requestMember, tagId, sort) + ); + } + @GetMapping("/find") + @Operation( + summary = "활동 검색 - 활동", + description = "활동을 주어진 조건에 맞추어 조회합니다. query 값으로 검색어(keyword)와 정렬 기준(new,old)을 요청해주세요. " ) + public CareerResponse> findCareerWithKeyword( + @Login LoginInfo loginInfo, + @RequestParam(name = "keyword") String keyword, + @RequestParam(name = "sort") String sort + ){ + Member requestMember = memberService.getById(loginInfo.getMemberId()); + return CareerResponse.success( + CareerResponseMessage.CAREER_FINDALL_SUCCESS, + baseCareerService.findCareerWithKeyword(requestMember, keyword, sort) + ); + + } + @GetMapping("/timeline") + @Operation( + summary = "활동 타임라인", + description = "타임라인에 필요한 활동 정보들을 조회합니다.") + public CareerResponse> findCareerForTimeline( + @Login LoginInfo loginInfo + ){ + Member requestMember = memberService.getById(loginInfo.getMemberId()); + return CareerResponse.success( + CareerResponseMessage.CAREER_FINDALL_SUCCESS, + baseCareerService.findCareerForTimeline(requestMember) + ); + + } + +} diff --git a/src/main/java/umc/kkijuk/server/career/controller/response/CategoryResponse.java b/src/main/java/umc/kkijuk/server/career/controller/response/CategoryResponse.java new file mode 100644 index 00000000..e6cedab6 --- /dev/null +++ b/src/main/java/umc/kkijuk/server/career/controller/response/CategoryResponse.java @@ -0,0 +1,15 @@ +package umc.kkijuk.server.career.controller.response; + +import lombok.*; + +@Data +@Getter +@Setter +@Builder +@AllArgsConstructor +public class CategoryResponse { + private int categoryId; + private String categoryKoName; + private String categoryEnName; + +} diff --git a/src/main/java/umc/kkijuk/server/career/controller/response/EtcResponse.java b/src/main/java/umc/kkijuk/server/career/controller/response/EtcResponse.java new file mode 100644 index 00000000..89789fd5 --- /dev/null +++ b/src/main/java/umc/kkijuk/server/career/controller/response/EtcResponse.java @@ -0,0 +1,51 @@ +package umc.kkijuk.server.career.controller.response; + +import lombok.*; +import umc.kkijuk.server.career.domain.CareerEtc; +import umc.kkijuk.server.detail.controller.response.BaseCareerDetailResponse; +import umc.kkijuk.server.detail.domain.BaseCareerDetail; +import umc.kkijuk.server.detail.domain.CareerType; + +import java.time.LocalDate; +import java.util.List; +import java.util.stream.Collectors; + +@Data +@Getter +@Setter +@Builder +@AllArgsConstructor +public class EtcResponse implements BaseCareerResponse{ + private Long id; + private String category; + private String name; + private String alias; + private Boolean unknown; + private String summary; + private LocalDate startdate; + private LocalDate enddate; + private List detailList; + + public EtcResponse(CareerEtc etc) { + this.id = etc.getId(); + this.category = CareerType.ETC.getDescription(); + this.name = etc.getName(); + this.alias = etc.getAlias(); + this.unknown = etc.getUnknown(); + this.summary = etc.getSummary(); + this.startdate = etc.getStartdate(); + this.enddate = etc.getEnddate(); + } + + public EtcResponse(CareerEtc etc, List details) { + this(etc); + this.detailList = details.stream() + .map(BaseCareerDetailResponse::new) + .collect(Collectors.toList()); + } + + @Override + public LocalDate getEndDate() { + return null; + } +} diff --git a/src/main/java/umc/kkijuk/server/career/controller/response/TimelineResponse.java b/src/main/java/umc/kkijuk/server/career/controller/response/TimelineResponse.java index ad53e2a6..0ccec8c3 100644 --- a/src/main/java/umc/kkijuk/server/career/controller/response/TimelineResponse.java +++ b/src/main/java/umc/kkijuk/server/career/controller/response/TimelineResponse.java @@ -2,8 +2,11 @@ import lombok.*; import umc.kkijuk.server.career.domain.BaseCareer; +import umc.kkijuk.server.detail.domain.CareerType; import java.time.LocalDate; +import java.util.List; +import java.util.stream.Collector; @Data @Getter @@ -12,16 +15,15 @@ @AllArgsConstructor public class TimelineResponse { private Long careerId; - private String category; + private CategoryResponse category; private String title; private LocalDate startdate; private LocalDate enddate; - public TimelineResponse(BaseCareer career, String type){ + public TimelineResponse(BaseCareer career, CareerType type){ this.careerId = career.getId(); this.title = career.getName(); this.startdate = career.getStartdate(); this.enddate = career.getEnddate(); - this.category = type; + this.category = new CategoryResponse(type.getId(),type.getDescription(),type.name()); } - } diff --git a/src/main/java/umc/kkijuk/server/career/domain/Activity.java b/src/main/java/umc/kkijuk/server/career/domain/Activity.java index d3430189..7bf412db 100644 --- a/src/main/java/umc/kkijuk/server/career/domain/Activity.java +++ b/src/main/java/umc/kkijuk/server/career/domain/Activity.java @@ -34,8 +34,7 @@ public void setSummary(String summary) { } @Builder public Activity(Long memberId, String name, String alias, Boolean unknown, - String summary, LocalDate startdate, - LocalDate enddate, String organizer, + LocalDate startdate, LocalDate enddate, String organizer, String role, int teamSize, int contribution, Boolean isTeam) { super(memberId, name, alias, unknown,startdate, enddate); diff --git a/src/main/java/umc/kkijuk/server/career/domain/CareerEtc.java b/src/main/java/umc/kkijuk/server/career/domain/CareerEtc.java new file mode 100644 index 00000000..093c68f7 --- /dev/null +++ b/src/main/java/umc/kkijuk/server/career/domain/CareerEtc.java @@ -0,0 +1,37 @@ +package umc.kkijuk.server.career.domain; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.*; + +import java.time.LocalDate; + +@Entity +@Getter +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class CareerEtc extends BaseCareer{ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @Override + public Long getId() { + return id; + } + @Override + public void setSummary(String summary) { + super.setSummary(summary); + } + @Builder + public CareerEtc(Long memberId, String name, String alias, Boolean unknown, + LocalDate startdate, LocalDate enddate) { + super(memberId, name, alias, unknown,startdate, enddate); + } + public void updateCareerEtc(String name, String alias, Boolean unknown, + LocalDate startdate, LocalDate enddate ) { + this.updateBaseCareer(name, alias, unknown, startdate, enddate); + } + +} diff --git a/src/main/java/umc/kkijuk/server/career/dto/EtcReqDto.java b/src/main/java/umc/kkijuk/server/career/dto/EtcReqDto.java new file mode 100644 index 00000000..93e1a765 --- /dev/null +++ b/src/main/java/umc/kkijuk/server/career/dto/EtcReqDto.java @@ -0,0 +1,43 @@ +package umc.kkijuk.server.career.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Builder +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class EtcReqDto { + @NotBlank(message = "활동명은 필수 입력 항목입니다. 최대 20자 까지 입력 가능") + @Size(max = 20) + @Schema(description = "활동명", example = "학원 채점 아르바이트", type="string") + private String name; + + @NotBlank(message = "활동 별칭은 필수 입력 항목입니다. 최대 20자 까지 입력 가능") + @Size(max = 20) + @Schema(description = "활동 별칭", example = "UMC", type="string") + private String alias; + + @NotNull(message = "활동 기간을 알고 있는지 여부를 나타냅니다.") + @Schema(description = "활동 기간 인지 여부", example = "false", type = "boolean") + private Boolean unknown; + + @NotNull(message = "활동 시작 날짜는 필수 입력 항목입니다.") + @JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") + @Schema(description = "활동 시작 날짜", example = "2024-04-14", type="string") + private LocalDate startdate; + + @JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") + @Schema(description = "활동 종료 날짜", example = "2024-07-20", type = "string") + private LocalDate enddate; + +} diff --git a/src/main/java/umc/kkijuk/server/career/dto/converter/BaseCareerConverter.java b/src/main/java/umc/kkijuk/server/career/dto/converter/BaseCareerConverter.java index c875e7f9..fa772224 100644 --- a/src/main/java/umc/kkijuk/server/career/dto/converter/BaseCareerConverter.java +++ b/src/main/java/umc/kkijuk/server/career/dto/converter/BaseCareerConverter.java @@ -89,4 +89,14 @@ public static Circle toCircle(Member requestMember, CircleReqDto circleReqDto) { .role(circleReqDto.getRole()).build(); } + public static CareerEtc toEtc(Member requestMember, EtcReqDto etcReqDto) { + return CareerEtc.builder() + .memberId(requestMember.getId()) + .name(etcReqDto.getName()) + .alias(etcReqDto.getAlias()) + .unknown(etcReqDto.getUnknown()) + .startdate(etcReqDto.getStartdate()) + .enddate(etcReqDto.getEnddate()) + .build(); + } } diff --git a/src/main/java/umc/kkijuk/server/career/repository/CareerEtcRepository.java b/src/main/java/umc/kkijuk/server/career/repository/CareerEtcRepository.java new file mode 100644 index 00000000..60710bfa --- /dev/null +++ b/src/main/java/umc/kkijuk/server/career/repository/CareerEtcRepository.java @@ -0,0 +1,7 @@ +package umc.kkijuk.server.career.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import umc.kkijuk.server.career.domain.CareerEtc; + +public interface CareerEtcRepository extends JpaRepository { +} diff --git a/src/main/java/umc/kkijuk/server/career/service/BaseCareerService.java b/src/main/java/umc/kkijuk/server/career/service/BaseCareerService.java index a97d3d20..10fe2f03 100644 --- a/src/main/java/umc/kkijuk/server/career/service/BaseCareerService.java +++ b/src/main/java/umc/kkijuk/server/career/service/BaseCareerService.java @@ -19,6 +19,7 @@ public interface BaseCareerService { EmploymentResponse createEmployment(Member requestMember, EmploymentReqDto employmentReqDto); ProjectResponse createProject(Member requestMember, ProjectReqDto projectReqDto); + EtcResponse createEtc(Member requestMember, EtcReqDto etcReqDto); void deleteActivity(Member requestMember, Long activityId); @@ -31,6 +32,7 @@ public interface BaseCareerService { void deleteEmp(Member requestMember, Long employmentId); void deleteProject(Member requestMember, Long projectId); + void deleteEtc(Member requestMember, Long etcId); ActivityResponse updateActivity(Member requestMember, Long activityId, ActivityReqDto request); @@ -41,6 +43,7 @@ public interface BaseCareerService { EduCareerResponse updateEdu(Member requestMember, Long educareerId, EduCareerReqDto eduCareerReqDto); EmploymentResponse updateEmp(Member requestMember, Long employmentId, EmploymentReqDto employmentReqDto); + EtcResponse updateEtc(Member requestMember, Long etcId, EtcReqDto etcReqDto); ProjectResponse updateProject(Member requestMember, Long projectId, ProjectReqDto projectReqDto); diff --git a/src/main/java/umc/kkijuk/server/career/service/BaseCareerServiceImpl.java b/src/main/java/umc/kkijuk/server/career/service/BaseCareerServiceImpl.java index 7fe4e373..9964225a 100644 --- a/src/main/java/umc/kkijuk/server/career/service/BaseCareerServiceImpl.java +++ b/src/main/java/umc/kkijuk/server/career/service/BaseCareerServiceImpl.java @@ -25,7 +25,6 @@ @Service @RequiredArgsConstructor -@Transactional(readOnly = true) public class BaseCareerServiceImpl implements BaseCareerService{ private final ActivityRepository activityRepository; private final CircleRepository circleRepository; @@ -35,6 +34,7 @@ public class BaseCareerServiceImpl implements BaseCareerService{ private final EmploymentRepository employmentRepository; private final BaseCareerDetailRepository detailRepository; private final TagRepository tagRepository; + private final CareerEtcRepository etcRepository; @Override @Transactional @@ -84,6 +84,13 @@ public ProjectResponse createProject(Member requestMember, ProjectReqDto project setCommonFields(project); return new ProjectResponse(projectRepository.save(project)); } + @Override + @Transactional + public EtcResponse createEtc(Member requestMember, EtcReqDto etcReqDto){ + CareerEtc etc = BaseCareerConverter.toEtc(requestMember, etcReqDto); + setCommonFields(etc); + return new EtcResponse(etcRepository.save(etc)); + } @Override @Transactional @@ -95,6 +102,7 @@ public void deleteBaseCareer(Member requestMember, Long careerId, String type) { case "edu" -> deleteEdu(requestMember, careerId); case "competition" -> deleteComp(requestMember, careerId); case "employment" -> deleteEmp(requestMember, careerId); + case "etc" -> deleteEtc(requestMember, careerId); default -> throw new IllegalArgumentException("지원하지 않는 활동 유형입니다 : " + type); } } @@ -172,6 +180,17 @@ public void deleteProject(Member requestMember, Long projectId) { } @Override @Transactional + public void deleteEtc(Member requestMember, Long etcId){ + CareerEtc etc = etcRepository.findById(etcId).orElseThrow( + () -> new ResourceNotFoundException("Etc", etcId) + ); + if(!etc.getMemberId().equals(requestMember.getId())){ + throw new OwnerMismatchException(); + } + etcRepository.delete(etc); + } + @Override + @Transactional public ActivityResponse updateActivity(Member requestMember, Long activityId, ActivityReqDto request){ Activity updateActivity = activityRepository.findById(activityId).orElseThrow( () -> new ResourceNotFoundException("Activity",activityId) @@ -283,6 +302,25 @@ public EmploymentResponse updateEmp(Member requestMember, Long employmentId, Emp } + @Override + @Transactional + public EtcResponse updateEtc(Member requestMember, Long etcId, EtcReqDto request) { + CareerEtc updateEtc = etcRepository.findById(etcId).orElseThrow( + () -> new ResourceNotFoundException("Etc",etcId) + ); + if(!updateEtc.getMemberId().equals(requestMember.getId())){ + throw new OwnerMismatchException(); + } + updateEtc.updateCareerEtc( + request.getName(), + request.getAlias(), + request.getUnknown(), + request.getStartdate(), + request.getEnddate() + ); + return new EtcResponse(updateEtc); + } + @Override @Transactional public ProjectResponse updateProject(Member requestMember, Long projectId, ProjectReqDto request) { @@ -572,10 +610,28 @@ public List findCareerForTimeline(Member requestMember) { careers.sort(Comparator.comparing(BaseCareer::getEnddate).reversed()); return careers.stream() - .map(career -> new TimelineResponse(career, career.getClass().getSimpleName())) + .map(career -> new TimelineResponse(career, resolveCareerType(career))) .collect(Collectors.toList()); } + private CareerType resolveCareerType(BaseCareer career) { + if (career instanceof Activity) { + return CareerType.ACTIVITY; + } else if (career instanceof Project) { + return CareerType.PROJECT; + } else if (career instanceof Employment) { + return CareerType.EMP; + } else if (career instanceof EduCareer) { + return CareerType.EDU; + } else if (career instanceof Circle) { + return CareerType.CIRCLE; + } else if (career instanceof Competition) { + return CareerType.COM; + } else { + return CareerType.ETC; + } + } + private List buildDetailResponse(List detailList, String sort) { Map>> groupedDetails = new HashMap<>(); diff --git a/src/main/java/umc/kkijuk/server/detail/domain/CareerType.java b/src/main/java/umc/kkijuk/server/detail/domain/CareerType.java index 1b683215..ea04684f 100644 --- a/src/main/java/umc/kkijuk/server/detail/domain/CareerType.java +++ b/src/main/java/umc/kkijuk/server/detail/domain/CareerType.java @@ -1,20 +1,24 @@ package umc.kkijuk.server.detail.domain; public enum CareerType { - ACTIVITY("대외활동"), - PROJECT("프로젝트"), - EDU("교육"), - EMP("경력"), - CIRCLE("동아리"), - COM("대회"); + ACTIVITY(1,"대외활동"), + PROJECT(2,"프로젝트"), + EDU(3,"교육"), + EMP(4,"경력"), + CIRCLE(5,"동아리"), + COM(6,"대회"), + ETC(7,"기타"); + private final int id; private final String description; - CareerType(String description) { + CareerType(int id,String description) { + this.id = id; this.description = description; } public String getDescription() { return description; } + public int getId() {return id;} }