Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/kkijuk/backend into feat…
Browse files Browse the repository at this point in the history
…ure/record
  • Loading branch information
nanna29 committed Aug 6, 2024
2 parents c0a0f3e + ef4e46d commit 5e09cbf
Show file tree
Hide file tree
Showing 27 changed files with 596 additions and 52 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CICD_DEVELOP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
- name: Generate application.properties
run: |
echo commit.hash=${{ steps.slug.outputs.sha7 }} >> ./src/main/resources/application-prod.properties
echo api.server.url=${{ secrets.API_URL }} >> ./src/main/resources/application-prod.properties
echo "spring.datasource.url=jdbc:mysql://${{ secrets.DATASOURCE_DB_URL }}:3306/kkijuk?useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Seoul" >> ./src/main/resources/application-prod.properties
echo "spring.datasource.username=${{ secrets.DATASOURCE_DB_USERNAME }}" >> ./src/main/resources/application-prod.properties
echo "spring.datasource.password=${{ secrets.DATASOURCE_DB_PASSWORD }}" >> ./src/main/resources/application-prod.properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,26 @@ public class CareerController {
.build();

@PostMapping("")
@Operation(summary = "활동 추가 API", description = "내 커리어 - 활동을 추가하는 API")
@Operation(summary = "활동 생성", description = "주어진 정보를 바탕으로 활동을 추가합니다.")
public CareerResponse<CareerResponseDto.CareerResultDto> create(@RequestBody @Valid CareerRequestDto.CreateCareerDto request){
Career career = careerService.createCareer(requestMember, request);
return CareerResponse.success(HttpStatus.CREATED,
CareerResponseMessage.CAREER_CREATE_SUCCESS,
CareerConverter.toCareerResultDto(career));
}

@GetMapping("/{careerId}")
@Operation(summary = "활동 상세", description = "활동 ID에 해당하는 활동의 세부 내용과, 활동 기록을 조회합니다.")
@Parameter(name = "careerId", description = "활동 Id, path variable 입니다.", example = "1")
public CareerResponse<CareerResponseDto.CareerDetailDto> findCareer(@PathVariable Long careerId) {
Career careerDetail = careerService.findCareerDetail(requestMember, careerId);
return CareerResponse.success(HttpStatus.OK,
CareerResponseMessage.CAREER_FINDALL_SUCCESS,
CareerConverter.toCareerDetailDto(careerDetail));
}

@DeleteMapping("/{careerId}")
@Operation(summary = "활동 삭제 API", description = "내 커리어 - 활동을 삭제하는 API")
@Operation(summary = "활동 삭제", description = "활동 ID에 해당하는 활동을 삭제합니다.")
@Parameter(name="careerId", description = "활동 Id, path variable 입니다.",example = "1")
public CareerResponse<Object> delete(@PathVariable Long careerId){
careerService.deleteCareer(requestMember, careerId);
Expand All @@ -51,7 +61,7 @@ public CareerResponse<Object> delete(@PathVariable Long careerId){
}

@PatchMapping("/{careerId}")
@Operation(summary = "활동 수정 API", description = "내 커리어 - 활동을 수정하는 API")
@Operation(summary = "활동 수정", description = "주어진 정보를 바탕으로 활동 데이터를 수정합니다.")
@Parameter(name="careerId", description = "활동 Id, path variable 입니다.",example = "1")
public CareerResponse<Object> update(@RequestBody @Valid CareerRequestDto.UpdateCareerDto request,
@PathVariable Long careerId) {
Expand All @@ -63,8 +73,8 @@ public CareerResponse<Object> update(@RequestBody @Valid CareerRequestDto.Update

@GetMapping("")
@Operation(
summary = "활동 조회 API - category(카테고리 기준) , year(연도 기준) ",
description = "내 커리어 - 활동을 카테고리, 연도 별로 조회하는 API입니다. query 값으로 category year 값을 주세요. " )
summary = "활동 목록",
description = "활동을 카테고리, 연도 별로 조회합니다. query 값으로 category(카테고리 기준)나, year(연도 기준) 값을 주세요. " )
public CareerResponse<List<? extends CareerGroupedByResponse>> read(@RequestParam(name="status") String value){
return CareerResponse.success(HttpStatus.OK,
CareerResponseMessage.CAREER_FINDALL_SUCCESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@
@Builder
@Getter
public class CareerResponse<T> {
private int status;
private String message;
@JsonInclude(JsonInclude.Include.NON_NULL)
private T data;

public CareerResponse(final int status,final String message,T data){
this.status = status;
public CareerResponse(final String message,T data){
this.message = message;
this.data = data;
}
public static <T> CareerResponse<T> success(HttpStatus status, String message, T data){
return new CareerResponse<>(status.value(),message,data);
return new CareerResponse<>(message,data);
}
}
1 change: 1 addition & 0 deletions src/main/java/umc/kkijuk/server/career/domain/Career.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void setAlias(String alias) {
this.alias = alias;
}


public void setUnknown(Boolean unknown) {
this.unknown = unknown;
}
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/umc/kkijuk/server/career/dto/CareerRequestDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import jakarta.validation.constraints.Size;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -57,23 +59,31 @@ public static class CreateCareerDto{
@Builder
public static class UpdateCareerDto{
@Size(max = 20)
@Schema(description = "수정된 활동명", example = "IT 서비스 개발 동아리", type="string")
@Nullable
@Schema(description = "수정된 활동명", example = "수정된 활동명", type="string")
String careerName;
@Size(max = 20)
@Schema(description = "수정된 활동 별칭", example = "동아리", type="string")
@Nullable
@Schema(description = "수정된 활동 별칭", example = "수정된 활동 별칭", type="string")
String alias;
@Size(max = 50)
@Schema(description = "수정된 활동 내역", example = "활동 내역 최대 50자까지 입력 가능(선택사항입니다.)",type = "string")
@Nullable
@Schema(description = "수정된 활동 내역", example = "수정된 활동 내역",type = "string")
String summary;
@Nullable
@Schema(description = "수정된 활동 기간 인지 여부", example = "false", type = "boolean")
Boolean isUnknown;
@Nullable
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
@Schema(description = "수정된 활동 시작 날짜", example = "2024-04-14", type="string")
LocalDate startDate;

@Nullable
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
@Schema(description = "수정된 활동 종료 날짜", example = "2024-07-20", type = "string")
LocalDate endDate;
@ValidCategory

@Nullable
@Schema(description = "수정된 활동 카테고리", example = "1", type = "int")
Integer category;
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/umc/kkijuk/server/career/dto/CareerResponseDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import umc.kkijuk.server.career.controller.response.CareerGroupedByResponse;
import umc.kkijuk.server.careerdetail.dto.CareerDetailResponseDto;

import java.time.LocalDate;
import java.util.List;
Expand Down Expand Up @@ -64,5 +65,30 @@ public static class CareerGroupedByYearDto extends CareerGroupedByResponse{
private List<CareerDto> careers;
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class CareerDetailDto{
private Long id;
private Long memberId;
private String careerName;
private String alias;
private String summary;

private Boolean isUnknown;
private LocalDate startDate;
private LocalDate endDate;
private int year;

private String categoryName;
private int categoryId;

private int totalDetailCount;
private List<CareerDetailResponseDto.CareerDetailResult> details;
}




}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package umc.kkijuk.server.career.dto.converter;

import umc.kkijuk.server.career.controller.response.CareerResponse;
import umc.kkijuk.server.career.domain.Career;
import umc.kkijuk.server.career.dto.CareerRequestDto;
import umc.kkijuk.server.career.dto.CareerResponseDto;
import umc.kkijuk.server.careerdetail.dto.CareerDetailResponseDto;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -87,6 +89,36 @@ public static List<CareerResponseDto.CareerGroupedByYearDto> toCareerGroupedByYe
.build())
.collect(Collectors.toList());
}
public static CareerResponseDto.CareerDetailDto toCareerDetailDto(Career career){
return CareerResponseDto.CareerDetailDto.builder()
.id(career.getId())
.memberId(career.getMemberId())
.careerName(career.getName())
.alias(career.getAlias())
.summary(career.getSummary())
.isUnknown(career.getUnknown())
.startDate(career.getStartdate())
.endDate(career.getEnddate())
.year(career.getYear())
.categoryId(Math.toIntExact(career.getCategory().getId()))
.categoryName(career.getCategory().getName())
.totalDetailCount(career.getCareerDetailList().size())
.details(career.getCareerDetailList().stream().map(careerDetail -> CareerDetailResponseDto.CareerDetailResult.builder()
.id(careerDetail.getId())
.careerId(careerDetail.getCareer().getId())
.title(careerDetail.getTitle())
.content(careerDetail.getContent())
.startDate(careerDetail.getStartDate())
.endDate(careerDetail.getEndDate())
.careerTagList(careerDetail.getCareerTagList().stream().map(careerTag -> CareerDetailResponseDto.CareerTag.builder()
.id(careerTag.getTag().getId())
.tagName(careerTag.getTag().getName())
.build()).collect(Collectors.toList())
)
.build()).collect(Collectors.toList()))
.build();

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public interface CareerService {
void deleteCareer(Member member, Long careerId);
Optional<Career> findCareer(Long value);
Career updateCareer(Member member, Long careerId, CareerRequestDto.UpdateCareerDto request);
Career findCareerDetail(Member requestMember, Long careerId);
List<? extends CareerGroupedByResponse> getCareerGroupedBy(Member member, String value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import umc.kkijuk.server.career.domain.Category;
import umc.kkijuk.server.common.domian.exception.OwnerMismatchException;
import umc.kkijuk.server.common.domian.exception.CareerValidationException;
import umc.kkijuk.server.career.controller.response.CareerGroupedByResponse;
Expand Down Expand Up @@ -58,24 +59,25 @@ public Career updateCareer(Member requestMember, Long careerId, CareerRequestDto
throw new OwnerMismatchException();
}

if (request.getCareerName()!=null) {
if ( request.getCareerName()!=null && !request.getCareerName().trim().isEmpty() ) {
career.setName(request.getCareerName());
}
if (request.getAlias()!=null) {
if (request.getAlias()!=null && !request.getAlias().trim().isEmpty() ) {
career.setAlias(request.getAlias());
}
if (request.getSummary()!=null) {
if (request.getSummary()!=null){
career.setSummary(request.getSummary());
}
if (request.getStartDate()!=null) {
career.setStartdate(request.getStartDate());
}
if (request.getIsUnknown()!=null || request.getEndDate()!=null ) {
updateEndDateAndUnknownStatus(career,request.getIsUnknown(),request.getEndDate());
validatedPeriod(career);
}
if (request.getStartDate()!=null) {
career.setStartdate(request.getStartDate());
}
if(request.getCategory()!=null){
career.setCategory(categoryRepository.findById(Long.valueOf(request.getCategory())).get());
Category category = categoryRepository.findById(Long.valueOf(request.getCategory())).orElseThrow(() -> new ResourceNotFoundException("Category",request.getCategory()));
career.setCategory(category);
}
return careerRepository.save(career);

Expand All @@ -98,6 +100,14 @@ public List<? extends CareerGroupedByResponse> getCareerGroupedBy(Member request
}
}

@Override
public Career findCareerDetail(Member requestMember, Long careerId) {
Career career = findCareer(careerId).get();
if(!career.getMemberId().equals(requestMember.getId())){
throw new OwnerMismatchException();
}
return career;
}
@Override
public Optional<Career> findCareer(Long careerId) {
return Optional.ofNullable(careerRepository.findById(careerId).orElseThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -13,19 +14,50 @@
import umc.kkijuk.server.careerdetail.dto.CareerDetailResponseDto;
import umc.kkijuk.server.careerdetail.dto.converter.CareerDetailConverter;
import umc.kkijuk.server.careerdetail.service.CareerDetailService;
import umc.kkijuk.server.common.LoginUser;
import umc.kkijuk.server.member.domain.Member;

@Tag(name="careerdetail",description = "내커리어 활동 기록 관련 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/career")
public class CareerDetailController {
private final CareerDetailService careerDetailService;

private final Member requestMember = Member.builder()
.id(LoginUser.get().getId())
.build();

@PostMapping("/{careerId}")
@Operation(summary = "활동 기록 추가 API", description = "내 커리어 - 활동 기록을 생성하는 API")
@Operation(summary = "활동 기록 생성", description = "주어진 정보를 바탕으로 활동기록을 생성합니다.")
@Parameter(name = "careerId", description = "활동 Id, path Variable 입니다.")
public CareerDetailResponse<CareerDetailResponseDto.CareerDetailResult> create(@RequestBody @Valid CareerDetailRequestDto.CareerDetailCreate request , @PathVariable Long careerId) {
CareerDetail newCareerDetail = careerDetailService.create(request, careerId);
CareerDetail newCareerDetail = careerDetailService.create(requestMember, request, careerId);
return CareerDetailResponse.success(HttpStatus.CREATED, "활동 기록을 성공적으로 생성했습니다.", CareerDetailConverter.toCareerDetailResult(newCareerDetail));
}

@DeleteMapping("/{careerId}/{detailId}")
@Operation(summary = "활동 기록 삭제", description = "활동 기록 ID에 해당하는 활동을 삭제합니다.")
@Parameters({
@Parameter(name = "careerId", description = "활동 Id, path variable 입니다."),
@Parameter(name = "detailId", description = "활동 기록 Id, path variable 입니다.")
})
public CareerDetailResponse<Object> delete(@PathVariable Long careerId, @PathVariable Long detailId) {
careerDetailService.delete(requestMember, detailId);
return CareerDetailResponse.success(HttpStatus.OK, "활동 기록을 성공적으로 삭제했습니다.",null);
}
@PutMapping("/{careerId}/{detailId}")
@Operation(summary = "활동 기록 수정",description = "주어진 정보를 바탕으로 활동 기록 ID에 해당하는 활동을 수정합니다. ")
@Parameters({
@Parameter(name = "careerId",description = "활동 Id, path variable 입니다."),
@Parameter(name = "detailId", description = "활동 기록 Id, path variable 입니다. ")
})
public CareerDetailResponse<Object> update(@PathVariable Long careerId,
@PathVariable Long detailId,
@RequestBody @Valid CareerDetailRequestDto.CareerDetailUpdate request){
CareerDetail updateCareerDetail = careerDetailService.update(requestMember, request, careerId ,detailId);
return CareerDetailResponse.success(HttpStatus.OK, "활동 기록을 성공적으로 수정했습니다.", CareerDetailConverter.toCareerDetailResult(updateCareerDetail));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CareerDetail extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="career_detail_id")
private Long id;
@Column(name="career_detail_titlw", length = 30)
@Column(name="career_detail_title", length = 30)
private String title;
@Column(name="career_detail_content", length = 800)
private String content;
Expand All @@ -29,6 +29,9 @@ public class CareerDetail extends BaseEntity {
@Column(name="career_detail_enddate")
private LocalDate endDate;

@Column(nullable = false)
private Long memberId;


@OneToMany(mappedBy = "careerDetail", cascade = CascadeType.ALL)
private List<CareerTag> careerTagList = new ArrayList<>();
Expand All @@ -41,4 +44,24 @@ public void setCareer(Career career) {
this.career = career;
}

public void setTitle(String title) {
this.title = title;
}

public void setContent(String content) {
this.content = content;
}

public void setStartDate(LocalDate startDate) {
this.startDate = startDate;
}

public void setEndDate(LocalDate endDate) {
this.endDate = endDate;
}

public void setMemberId(Long memberId) {
this.memberId = memberId;
}

}
Loading

0 comments on commit 5e09cbf

Please sign in to comment.