Skip to content

Commit

Permalink
Merge pull request #104 from nar0ng/feature/#13-feature-activity-log-…
Browse files Browse the repository at this point in the history
…crud

✨ Feature: #13 feature activity log crud
  • Loading branch information
nar0ng authored Aug 15, 2024
2 parents a685932 + 00426ed commit 2a60c78
Show file tree
Hide file tree
Showing 27 changed files with 327 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cotato.growingpain.log.domain;
package cotato.growingpain.log;

import lombok.Getter;

@Getter
public enum ActivityType {
public enum ActivityCategory {

EXTRA_ACTIVITY("대외활동"),
VOLUNTEER_ACTIVITY("봉사활동"),
Expand All @@ -14,7 +14,7 @@ public enum ActivityType {

private final String description;

ActivityType(String description) {
ActivityCategory(String description) {
this.description = description;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cotato.growingpain.log.domain;
package cotato.growingpain.log;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cotato.growingpain.log.domain;
package cotato.growingpain.log;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package cotato.growingpain.log.controller;

import static cotato.growingpain.common.Response.createSuccess;

import cotato.growingpain.common.Response;
import cotato.growingpain.log.dto.ActivityLogDTO;
import cotato.growingpain.log.dto.request.ActivityLogRequestDTO;
import cotato.growingpain.log.service.ActivityLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/activity-logs")
@RequiredArgsConstructor
public class ActivityLogController {
private final ActivityLogService activityLogService;

@Operation(summary = "활동 기록 저장", description = "활동 기록을 등록하기 위한 메소드")
@ApiResponse(content = @Content(schema = @Schema(implementation = Response.class)))
@PostMapping("")
@ResponseStatus(HttpStatus.CREATED)
public Response<ActivityLogRequestDTO> createJobPost(
@RequestBody @Valid ActivityLogRequestDTO activityLogRequestDTO,
@AuthenticationPrincipal Long memberId) {
activityLogService.createActivityLog(activityLogRequestDTO, memberId);
return createSuccess("활동 기록 등록 완료", null);
}

@Operation(summary = "활동 기록 리스트 조회", description = "활동 기록 리스트를 조회하기 위한 메소드")
@ApiResponse(content = @Content(schema = @Schema(implementation = Response.class)))
@GetMapping("")
@ResponseStatus(HttpStatus.OK)
public Response<List<ActivityLogRequestDTO>> retrieveActivityLogList(
@AuthenticationPrincipal Long memberId) {
List<ActivityLogRequestDTO> activityLogList = activityLogService.retrieveActivityLogsByMemberId(memberId);
return createSuccess("활동 기록 조회 완료", activityLogList);
}

@Operation(summary = "활동 기록 상세 조회", description = "활동 기록을 상세 조회하기 위한 메소드")
@ApiResponse(content = @Content(schema = @Schema(implementation = Response.class)))
@GetMapping("/{activityLogId}")
@ResponseStatus(HttpStatus.OK)
public Response<ActivityLogDTO> retrieveActivityLogById(
@PathVariable Long activityLogId) {
ActivityLogDTO activityLogDTO = activityLogService.retrieveActivityLogById(activityLogId);
return Response.createSuccess("활동 기록 상세 조회 완료", activityLogDTO);
}

@Operation(summary = "활동 기록 수정", description = "활동 기록을 수정하기 위한 메소드")
@ApiResponse(content = @Content(schema = @Schema(implementation = Response.class)))
@PatchMapping("/{activityLogId}")
@ResponseStatus(HttpStatus.OK)
public Response<ActivityLogDTO> updateActivityLog(@PathVariable Long activityLogId,
@RequestBody ActivityLogDTO updatedActivityLogDTO) {
ActivityLogDTO updatedActivityLog = activityLogService.updateActivityLog(activityLogId, updatedActivityLogDTO);
return Response.createSuccess("활동 기록 수정 완료", updatedActivityLog);
}

@Operation(summary = "활동 기록 삭제", description = "활동 기록을 삭제하기 위한 메소드")
@ApiResponse(content = @Content(schema = @Schema(implementation = Response.class)))
@DeleteMapping("/{activityLogId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public Response<?> deleteActivityLog(@PathVariable Long activityLogId,
@AuthenticationPrincipal Long memberId) {
activityLogService.deleteActivityLog(activityLogId, memberId);

return Response.createSuccess("활동 기록 삭제 완료", null);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cotato.growingpain.log.domain.controller;
package cotato.growingpain.log.controller;

import cotato.growingpain.common.Response;
import cotato.growingpain.log.domain.dto.JobPostListRetrieveDTO;
import cotato.growingpain.log.domain.dto.JobPostRequestDTO;
import cotato.growingpain.log.domain.dto.JobPostRetrieveDTO;
import cotato.growingpain.log.domain.entity.JobPost;
import cotato.growingpain.log.domain.service.JobService;
import cotato.growingpain.log.dto.request.JobPostRequestDTO;
import cotato.growingpain.log.dto.request.JobPostRetrieveDTO;
import cotato.growingpain.log.dto.retrieve.JobPostListRetrieveDTO;
import cotato.growingpain.log.service.JobService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -18,9 +18,9 @@
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
Expand Down Expand Up @@ -66,7 +66,7 @@ public Response<JobPostRetrieveDTO> getJobPostById(@PathVariable Long jobPostId)

@Operation(summary = "지원 현황 내용 수정", description = "지원 현황을 수정하기 위한 메소드")
@ApiResponse(content = @Content(schema = @Schema(implementation = Response.class)))
@PutMapping("/{jobPostId}")
@PatchMapping("/{jobPostId}")
@ResponseStatus(HttpStatus.OK)
public Response<JobPost> updateJobPost(
@PathVariable Long jobPostId,
Expand Down
54 changes: 31 additions & 23 deletions src/main/java/cotato/growingpain/log/domain/entity/ActivityLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import cotato.growingpain.common.domain.BaseTimeEntity;
import cotato.growingpain.log.domain.ActivityType;
import cotato.growingpain.log.ActivityCategory;
import cotato.growingpain.log.dto.ActivityLogDTO;
import cotato.growingpain.member.domain.entity.Member;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -40,8 +41,8 @@ public class ActivityLog extends BaseTimeEntity {
/* ------------ Information Column ------------ */
/* -------------------------------------------- */
@Enumerated(EnumType.STRING)
@Column(name = "activity_type")
private ActivityType activityType;
@Column(name = "activity_category")
private ActivityCategory activityCategory;

@Column(name = "activity_name")
private String activityName;
Expand All @@ -58,17 +59,14 @@ public class ActivityLog extends BaseTimeEntity {
@Column(name = "contribution")
private int contribution;

@Column(name = "activity_start_date")
private String activityStartDate;

@Column(name = "activity_close_date")
private String activityCloseDate;
@Column(name = "activity_duration")
private String activityDuration;

@Column(name = "image_url")
private String imageUrl;
@Column(name = "activity_type")
private String activityType;

@Column(name = "file_url")
private String fileUrl;
@Column(name = "url")
private String url;

@CreatedDate
@Column(updatable = false)
Expand All @@ -87,31 +85,41 @@ public class ActivityLog extends BaseTimeEntity {

@Builder
public ActivityLog(
ActivityType activityType,
ActivityCategory activityCategory,
String activityName,
String content,
String performance,
String role,
Integer contribution,
String activityStartDate,
String activityCloseDate,
String imageUrl,
String fileUrl,
String activityDuration,
String activityType,
String url,
int contribution,
Member member
) {
// Relation Column
this.member = member;

// Information Column
this.activityType = activityType;
this.activityCategory = activityCategory;
this.activityName = activityName;
this.content = content;
this.performance = performance;
this.role = role;
this.activityDuration = activityDuration;
this.contribution = contribution;
this.activityStartDate = activityStartDate;
this.activityCloseDate = activityCloseDate;
this.imageUrl = imageUrl;
this.fileUrl = fileUrl;
this.activityType = activityType;
this.url = url;
}

public void updateFromDTO(ActivityLogDTO updatedActivityLogDTO) {
this.activityCategory = updatedActivityLogDTO.activityCategory();
this.activityName = updatedActivityLogDTO.activityName();
this.content = updatedActivityLogDTO.content();
this.performance = updatedActivityLogDTO.performance();
this.role = updatedActivityLogDTO.role();
this.activityDuration = updatedActivityLogDTO.activityDuration();
this.activityType = updatedActivityLogDTO.activityType();
this.url = updatedActivityLogDTO.url();
this.contribution = updatedActivityLogDTO.contribution();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import cotato.growingpain.log.domain.dto.ApplicationDetailRequestDTO;
import cotato.growingpain.log.dto.request.ApplicationDetailRequestDTO;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import cotato.growingpain.common.domain.BaseTimeEntity;
import cotato.growingpain.log.domain.ApplicationType;
import cotato.growingpain.log.domain.Result;
import cotato.growingpain.log.domain.dto.ApplicationDetailRequestDTO;
import cotato.growingpain.log.domain.dto.JobApplicationRequestDTO;
import cotato.growingpain.log.domain.repository.ApplicationDetailRepository;
import cotato.growingpain.log.ApplicationType;
import cotato.growingpain.log.Result;
import cotato.growingpain.log.dto.request.ApplicationDetailRequestDTO;
import cotato.growingpain.log.dto.request.JobApplicationRequestDTO;
import cotato.growingpain.log.repository.ApplicationDetailRepository;
import cotato.growingpain.member.domain.entity.Member;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import cotato.growingpain.log.domain.dto.JobApplicationRequestDTO;
import cotato.growingpain.log.domain.dto.JobPostRequestDTO;
import cotato.growingpain.log.domain.repository.ApplicationDetailRepository;
import cotato.growingpain.log.domain.repository.JobApplicationRepository;
import cotato.growingpain.log.dto.request.JobApplicationRequestDTO;
import cotato.growingpain.log.dto.request.JobPostRequestDTO;
import cotato.growingpain.log.repository.ApplicationDetailRepository;
import cotato.growingpain.log.repository.JobApplicationRepository;
import cotato.growingpain.member.domain.entity.Member;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
Expand Down

This file was deleted.

54 changes: 54 additions & 0 deletions src/main/java/cotato/growingpain/log/dto/ActivityLogDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package cotato.growingpain.log.dto;

import cotato.growingpain.log.ActivityCategory;
import cotato.growingpain.log.domain.entity.ActivityLog;
import cotato.growingpain.member.domain.entity.Member;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Builder
public record ActivityLogDTO(
Long id,
ActivityCategory activityCategory,
String activityName,
String content,
String performance,
String role,
String activityDuration,
String activityType,
String url,
int contribution
) {
public static ActivityLogDTO fromEntity(ActivityLog activityLog) {
return ActivityLogDTO.builder()
.id(activityLog.getId())
.activityName(activityLog.getActivityName())
.activityCategory(activityLog.getActivityCategory())
.activityDuration(activityLog.getActivityDuration())
.content(activityLog.getContent())
.performance(activityLog.getPerformance())
.role(activityLog.getRole())
.activityDuration(activityLog.getActivityDuration())
.activityType(activityLog.getActivityType())
.contribution(activityLog.getContribution())
.url(activityLog.getUrl())
.build();
}

public ActivityLog toEntity(Member member) {
ActivityLog activityLog = ActivityLog.builder()
.activityName(this.activityName)
.activityCategory(this.activityCategory)
.activityDuration(this.activityDuration)
.content(this.content)
.performance(this.performance)
.role(this.role)
.contribution(this.contribution)
.activityType(this.activityType)
.url(this.url)
.member(member)
.build();
return activityLog;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cotato.growingpain.log.domain.dto;
package cotato.growingpain.log.dto;

import cotato.growingpain.log.domain.entity.ApplicationDetail;
import lombok.Builder;
Expand Down
Loading

0 comments on commit 2a60c78

Please sign in to comment.