Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
package com.somemore.domains.recruitboard.controller;


import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;

import com.somemore.domains.recruitboard.dto.request.RecruitBoardCreateRequestDto;
import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto;
import com.somemore.domains.recruitboard.dto.request.RecruitBoardStatusUpdateRequestDto;
import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto;
import com.somemore.domains.recruitboard.usecase.command.CreateRecruitBoardUseCase;
import com.somemore.domains.recruitboard.usecase.command.DeleteRecruitBoardUseCase;
import com.somemore.domains.recruitboard.usecase.command.UpdateRecruitBoardUseCase;
import com.somemore.domains.recruitboard.usecase.CreateRecruitBoardUseCase;
import com.somemore.domains.recruitboard.usecase.DeleteRecruitBoardUseCase;
import com.somemore.domains.recruitboard.usecase.UpdateRecruitBoardUseCase;
import com.somemore.global.auth.annotation.CurrentUser;
import com.somemore.global.common.response.ApiResponse;
import com.somemore.global.imageupload.dto.ImageUploadRequestDto;
import com.somemore.global.imageupload.usecase.ImageUploadUseCase;
import com.somemore.domains.recruitboard.dto.request.RecruitBoardCreateRequestDto;
import com.somemore.domains.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto;
import com.somemore.domains.recruitboard.dto.request.RecruitBoardStatusUpdateRequestDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.time.LocalDateTime;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.UUID;

import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;

@Tag(name = "Recruit Board Command API", description = "봉사 활동 모집글 생성 수정 삭제 API")
@RequiredArgsConstructor
@RequestMapping("/api")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
package com.somemore.domains.recruitboard.controller;

import static org.springframework.data.domain.Sort.Direction.DESC;

import com.somemore.domains.recruitboard.dto.condition.RecruitBoardNearByCondition;
import com.somemore.domains.recruitboard.dto.condition.RecruitBoardSearchCondition;
import com.somemore.domains.recruitboard.usecase.query.RecruitBoardQueryUseCase;
import com.somemore.global.common.response.ApiResponse;
import com.somemore.domains.recruitboard.domain.RecruitStatus;
import com.somemore.domains.recruitboard.domain.VolunteerCategory;
import com.somemore.domains.recruitboard.dto.condition.RecruitBoardNearByCondition;
import com.somemore.domains.recruitboard.dto.condition.RecruitBoardSearchCondition;
import com.somemore.domains.recruitboard.dto.response.RecruitBoardDetailResponseDto;
import com.somemore.domains.recruitboard.dto.response.RecruitBoardResponseDto;
import com.somemore.domains.recruitboard.dto.response.RecruitBoardWithCenterResponseDto;
import com.somemore.domains.recruitboard.dto.response.RecruitBoardWithLocationResponseDto;
import com.somemore.domains.recruitboard.usecase.RecruitBoardQueryUseCase;
import com.somemore.global.common.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

import static org.springframework.data.domain.Sort.Direction.DESC;

@Tag(name = "Recruit Board Query API", description = "봉사 활동 모집 조회 관련 API")
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
package com.somemore.domains.recruitboard.domain;

import static jakarta.persistence.EnumType.STRING;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import com.somemore.domains.recruitboard.dto.request.RecruitBoardUpdateRequestDto;
import com.somemore.global.common.entity.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.UUID;
import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.UUID;

import static jakarta.persistence.EnumType.STRING;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

@Getter
@NoArgsConstructor(access = PROTECTED)
@Entity
Expand Down Expand Up @@ -56,7 +49,7 @@ public class RecruitBoard extends BaseEntity {

@Builder
public RecruitBoard(UUID centerId, Long locationId, String title, String content,
RecruitmentInfo recruitmentInfo, String imgUrl) {
RecruitmentInfo recruitmentInfo, String imgUrl) {
this.centerId = centerId;
this.locationId = locationId;
this.title = title;
Expand All @@ -65,10 +58,6 @@ public RecruitBoard(UUID centerId, Long locationId, String title, String content
this.imgUrl = imgUrl;
}

public LocalTime getVolunteerHours() {
return recruitmentInfo.calculateVolunteerTime();
}

public boolean isWriter(UUID centerId) {
return this.centerId.equals(centerId);
}
Expand Down Expand Up @@ -102,6 +91,7 @@ private void updateRecruitmentInfo(RecruitBoardUpdateRequestDto dto) {
dto.volunteerCategory(),
dto.volunteerStartDateTime(),
dto.volunteerEndDateTime(),
dto.volunteerHours(),
dto.admitted()
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.somemore.domains.recruitboard.domain;

import static jakarta.persistence.EnumType.STRING;
import static java.time.temporal.ChronoUnit.MINUTES;
import static lombok.AccessLevel.PROTECTED;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Enumerated;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

import static jakarta.persistence.EnumType.STRING;
import static java.time.temporal.ChronoUnit.MINUTES;
import static lombok.AccessLevel.PROTECTED;

@Getter
@NoArgsConstructor(access = PROTECTED)
@Embeddable
Expand All @@ -31,6 +30,9 @@ public class RecruitmentInfo {
@Column(name = "volunteer_end_date_time", nullable = false)
private LocalDateTime volunteerEndDateTime;

@Column(name = "volunteer_hours", nullable = false)
private int volunteerHours;

@Enumerated(value = STRING)
@Column(name = "volunteer_category", nullable = false, length = 30)
private VolunteerCategory volunteerCategory;
Expand All @@ -39,50 +41,32 @@ public class RecruitmentInfo {
private Boolean admitted;

@Builder
public RecruitmentInfo(String region, Integer recruitmentCount,
LocalDateTime volunteerStartDateTime, LocalDateTime volunteerEndDateTime,
VolunteerCategory volunteerCategory, Boolean admitted) {

validateVolunteerDateTime(volunteerStartDateTime, volunteerEndDateTime);
public RecruitmentInfo(String region, Integer recruitmentCount, LocalDateTime volunteerStartDateTime, LocalDateTime volunteerEndDateTime,
int volunteerHours, VolunteerCategory volunteerCategory, Boolean admitted) {

this.region = region;
this.recruitmentCount = recruitmentCount;
this.volunteerStartDateTime = volunteerStartDateTime.truncatedTo(MINUTES);
this.volunteerEndDateTime = volunteerEndDateTime.truncatedTo(MINUTES);
this.volunteerHours = volunteerHours;
this.volunteerCategory = volunteerCategory;
this.admitted = admitted;
}

public LocalTime calculateVolunteerTime() {
Duration duration = Duration.between(volunteerStartDateTime, volunteerEndDateTime);

long hours = duration.toHours();
long minutes = duration.toMinutes() % 60;

return LocalTime.of((int) hours, (int) minutes);
}

public void updateWith(String region, Integer recruitmentCount, VolunteerCategory volunteerCategory,
LocalDateTime volunteerStartDateTime, LocalDateTime volunteerEndDateTime,
Boolean admitted) {

validateVolunteerDateTime(volunteerStartDateTime, volunteerEndDateTime);

LocalDateTime volunteerStartDateTime, LocalDateTime volunteerEndDateTime,
Integer volunteerHours, Boolean admitted) {
this.region = region;
this.recruitmentCount = recruitmentCount;
this.volunteerCategory = volunteerCategory;
this.volunteerStartDateTime = volunteerStartDateTime.truncatedTo(MINUTES);
this.volunteerEndDateTime = volunteerEndDateTime.truncatedTo(MINUTES);
this.volunteerHours = volunteerHours;
this.admitted = admitted;
}

public void updateWith(String region) {
this.region = region;
}

private void validateVolunteerDateTime(LocalDateTime startDateTime, LocalDateTime endDateTime) {
if (endDateTime.isEqual(startDateTime) || endDateTime.isBefore(startDateTime)) {
throw new IllegalArgumentException("종료 시간은 시작 시간보다 이후여야 합니다.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

import java.time.LocalDateTime;
import java.util.UUID;
import lombok.Builder;

@JsonNaming(SnakeCaseStrategy.class)
@Builder
Expand All @@ -37,6 +38,9 @@ public record RecruitBoardCreateRequestDto(
@NotNull(message = "봉사 종료 일시는 필수 값입니다.")
@Future(message = "봉사 종료 일시는 내일부터 가능합니다.")
LocalDateTime volunteerEndDateTime,
@Schema(description = "봉사 시간", example = "2")
@NotNull(message = "봉사 시간은 필수 값입니다.")
Integer volunteerHours,
@Schema(description = "봉사 활동 유형", example = "ENVIRONMENTAL_PROTECTION")
@NotNull(message = "봉사 활동 유형은 필수 값입니다.")
VolunteerCategory volunteerCategory,
Expand All @@ -53,6 +57,7 @@ public RecruitBoard toEntity(UUID centerId, Long locationId, String imgUrl) {
.recruitmentCount(recruitmentCount)
.volunteerStartDateTime(volunteerStartDateTime)
.volunteerEndDateTime(volunteerEndDateTime)
.volunteerHours(volunteerHours)
.volunteerCategory(volunteerCategory)
.admitted(admitted)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
import lombok.Builder;

import java.time.LocalDateTime;

@JsonNaming(SnakeCaseStrategy.class)
@Builder
public record RecruitBoardUpdateRequestDto(
Expand All @@ -31,7 +32,11 @@ public record RecruitBoardUpdateRequestDto(
LocalDateTime volunteerStartDateTime,
@Schema(description = "봉사 종료 일시", example = "2024-12-20T12:00:00", type = "string")
@NotNull(message = "봉사 종료 일시는 필수 값입니다.")
@Future(message = "봉사 종료 일시는 내일부터 가능합니다.")LocalDateTime volunteerEndDateTime,
@Future(message = "봉사 종료 일시는 내일부터 가능합니다.")
LocalDateTime volunteerEndDateTime,
@Schema(description = "봉사 시간", example = "2")
@NotNull(message = "봉사 시간는 필수 값입니다.")
Integer volunteerHours,
@Schema(description = "봉사 활동 유형", example = "ENVIRONMENTAL_PROTECTION")
@NotNull(message = "봉사 활동 유형은 필수 값입니다.")
VolunteerCategory volunteerCategory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.somemore.domains.center.dto.response.CenterSimpleInfoResponseDto;
import com.somemore.domains.recruitboard.repository.mapper.RecruitBoardDetail;
import com.somemore.domains.location.dto.response.LocationResponseDto;
import com.somemore.domains.recruitboard.domain.RecruitBoard;
import com.somemore.domains.recruitboard.domain.RecruitStatus;
import com.somemore.domains.recruitboard.domain.RecruitmentInfo;
import com.somemore.domains.recruitboard.domain.VolunteerCategory;
import com.somemore.domains.recruitboard.repository.mapper.RecruitBoardDetail;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.time.LocalTime;
import lombok.Builder;

import java.time.LocalDateTime;


@Builder
@JsonNaming(SnakeCaseStrategy.class)
Expand Down Expand Up @@ -41,8 +41,8 @@ public record RecruitBoardDetailResponseDto(
LocalDateTime volunteerEndDateTime,
@Schema(description = "봉사 유형", example = "LIVING_SUPPORT")
VolunteerCategory volunteerCategory,
@Schema(description = "봉사 시간", example = "04:00:00")
LocalTime volunteerTime,
@Schema(description = "봉사 시간", example = "4")
Integer volunteerHours,
@Schema(description = "시간 인정 여부", example = "true")
Boolean admitted,
@Schema(description = "이미지 URL", example = "https://image.domain.com/links")
Expand Down Expand Up @@ -74,7 +74,7 @@ public static RecruitBoardDetailResponseDto from(RecruitBoardDetail recruitBoard
.volunteerStartDateTime(info.getVolunteerStartDateTime())
.volunteerEndDateTime(info.getVolunteerEndDateTime())
.volunteerCategory(info.getVolunteerCategory())
.volunteerTime(info.calculateVolunteerTime())
.volunteerHours(info.getVolunteerHours())
.admitted(info.getAdmitted())
.imgUrl(board.getImgUrl())
.location(location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import com.somemore.domains.recruitboard.domain.RecruitmentInfo;
import com.somemore.domains.recruitboard.domain.VolunteerCategory;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.UUID;
import lombok.Builder;

@Builder
@JsonNaming(SnakeCaseStrategy.class)
Expand Down Expand Up @@ -42,8 +42,8 @@ public record RecruitBoardResponseDto(
LocalDateTime volunteerEndDateTime,
@Schema(description = "봉사 유형", example = "LIVING_SUPPORT")
VolunteerCategory volunteerCategory,
@Schema(description = "봉사 시간", example = "04:00:00")
LocalTime volunteerTime,
@Schema(description = "봉사 시간", example = "4")
Integer volunteerHours,
@Schema(description = "시간 인정 여부", example = "true")
Boolean admitted,
@Schema(description = "이미지 URL", example = "https://image.domain.com/links")
Expand All @@ -66,7 +66,7 @@ public static RecruitBoardResponseDto from(RecruitBoard board) {
.volunteerStartDateTime(info.getVolunteerStartDateTime())
.volunteerEndDateTime(info.getVolunteerEndDateTime())
.volunteerCategory(info.getVolunteerCategory())
.volunteerTime(info.calculateVolunteerTime())
.volunteerHours(info.getVolunteerHours())
.admitted(info.getAdmitted())
.imgUrl(board.getImgUrl())
.build();
Expand Down
Loading
Loading