Skip to content

Commit

Permalink
[DDING-109] Club 엔터티 formUrl 속성 제거 및 formId 속성 추가 (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seooooo24 authored Feb 16, 2025
1 parent 2293445 commit b4cf4bb
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import ddingdong.ddingdongBE.domain.club.controller.dto.response.UserClubResponse;
import ddingdong.ddingdongBE.domain.club.service.FacadeUserClubService;
import ddingdong.ddingdongBE.domain.club.service.dto.query.UserClubQuery;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -20,7 +19,7 @@ public class UserClubController implements UserClubApi {

@Override
public List<UserClubListResponse> getClubs() {
return facadeUserClubService.findAllWithRecruitTimeCheckPoint(LocalDateTime.now()).stream()
return facadeUserClubService.findAllWithRecruitTimeCheckPoint(LocalDate.now()).stream()
.map(UserClubListResponse::from)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public record UpdateClubInfoRequest(
@Schema(description = "동아리방 위치", example = "S1111")
@NotNull(message = "동아리방 위치는 필수로 입력해야 합니다.")
String location,
@Schema(description = "모집시작 날짜", example = "2024-01-01 00:00")
String startRecruitPeriod,
@Schema(description = "모집마감 날짜", example = "2024-01-01 00:00")
String endRecruitPeriod,
@Schema(description = "정기활동", example = "정기활동")
@NotNull(message = "정기활동은 필수로 입력해야 합니다.")
String regularMeeting,
Expand All @@ -42,8 +38,6 @@ public record UpdateClubInfoRequest(
String activity,
@Schema(description = "인재상", example = "인재상")
String ideal,
@Schema(description = "모집 Url", example = "Url")
String formUrl,
@Schema(description = "동아리 프로필 이미지 식별자", example = "0192c828-ffce-7ee8-94a8-d9d4c8cdec00")
String profileImageId,
@Schema(description = "동아리 소개 이미지 식별자", example = "0192c828-ffce-7ee8-94a8-d9d4c8cdec00")
Expand All @@ -60,13 +54,10 @@ public UpdateClubInfoCommand toCommand(Long userId) {
clubLeader,
phoneNumber,
location,
startRecruitPeriod,
endRecruitPeriod,
regularMeeting,
introduction,
activity,
ideal,
formUrl,
profileImageId,
introductionImageId
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package ddingdong.ddingdongBE.domain.club.controller.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import ddingdong.ddingdongBE.domain.club.service.dto.query.MyClubInfoQuery;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlQuery;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.time.LocalDate;

@Schema(
name = "MyClubInfoResponse",
Expand All @@ -24,11 +23,9 @@ public record MyClubInfoResponse(
@Schema(description = "동아리방 위치", example = "S1111")
String location,
@Schema(description = "모집시작날짜", example = "2024-01-01 00:00")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "Asia/Seoul")
LocalDateTime startRecruitPeriod,
LocalDate startDate,
@Schema(description = "모집마감날짜", example = "2024-01-01 00:00")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "Asia/Seoul")
LocalDateTime endRecruitPeriod,
LocalDate endDate,
@Schema(description = "정기활동", example = "정기활동")
String regularMeeting,
@Schema(description = "동아리 소개", example = "소개")
Expand All @@ -37,8 +34,6 @@ public record MyClubInfoResponse(
String activity,
@Schema(description = "인재상", example = "인재상")
String ideal,
@Schema(description = "모집Url", example = "url")
String formUrl,
@Schema(description = "동아리 프로필 이미지 Url", example = "url")
MyClubInfoImageUrlResponse profileImage,
MyClubInfoImageUrlResponse introductionImage
Expand All @@ -52,13 +47,12 @@ public static MyClubInfoResponse from(MyClubInfoQuery query) {
query.leader(),
query.phoneNumber(),
query.location(),
query.startRecruitPeriod(),
query.endRecruitPeriod(),
query.startDate(),
query.endDate(),
query.regularMeeting(),
query.introduction(),
query.activity(),
query.ideal(),
query.formUrl(),
MyClubInfoImageUrlResponse.from(query.profileImageUrlQuery()),
MyClubInfoImageUrlResponse.from(query.introductionImageUrlQuery())
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package ddingdong.ddingdongBE.domain.club.controller.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import ddingdong.ddingdongBE.domain.club.service.dto.query.UserClubQuery;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlQuery;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.time.LocalDate;

@Schema(
name = "UserClubResponse",
Expand All @@ -23,12 +22,10 @@ public record UserClubResponse(
String phoneNumber,
@Schema(description = "동아리방 위치", example = "S1111")
String location,
@Schema(description = "모집시작날짜", example = "2024-01-01 00:00")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "Asia/Seoul")
LocalDateTime startRecruitPeriod,
@Schema(description = "모집마감날짜", example = "2024-01-01 00:00")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "Asia/Seoul")
LocalDateTime endRecruitPeriod,
@Schema(description = "모집시작날짜", example = "2024-01-01")
LocalDate startDate,
@Schema(description = "모집마감날짜", example = "2024-01-01")
LocalDate endDate,
@Schema(description = "정기활동", example = "정기활동")
String regularMeeting,
@Schema(description = "동아리 소개", example = "소개")
Expand All @@ -37,8 +34,8 @@ public record UserClubResponse(
String activity,
@Schema(description = "인재상", example = "인재상")
String ideal,
@Schema(description = "모집Url", example = "url")
String formUrl,
@Schema(description = "모집 폼 ID", example = "6")
Long formId,
UserClubImageUrlResponse profileImage,
UserClubImageUrlResponse introductionImage
) {
Expand All @@ -51,13 +48,13 @@ public static UserClubResponse from(UserClubQuery query) {
query.leader(),
query.phoneNumber(),
query.location(),
query.startRecruitPeriod(),
query.endRecruitPeriod(),
query.startDate(),
query.endDate(),
query.regularMeeting(),
query.introduction(),
query.activity(),
query.ideal(),
query.formUrl(),
query.formId(),
UserClubImageUrlResponse.from(query.profileImageUrlQuery()),
UserClubImageUrlResponse.from(query.introductionImageUrlQuery())
);
Expand Down
21 changes: 5 additions & 16 deletions src/main/java/ddingdong/ddingdongBE/domain/club/entity/Club.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public class Club extends BaseEntity {
@Embedded
private Location location;

private LocalDateTime startRecruitPeriod;

private LocalDateTime endRecruitPeriod;

private String regularMeeting;

private String introduction;
Expand All @@ -70,19 +66,18 @@ public class Club extends BaseEntity {

private String ideal;

private String formUrl;

@Embedded
private Score score;

@Column(name = "deleted_at", columnDefinition = "TIMESTAMP")
private LocalDateTime deletedAt;

@Builder
private Club(Long id, User user, List<ClubMember> clubMembers, String name, String category, String tag,
String leader, PhoneNumber phoneNumber, Location location, LocalDateTime startRecruitPeriod,
LocalDateTime endRecruitPeriod, String regularMeeting, String introduction, String activity,
String ideal, String formUrl, Score score, LocalDateTime deletedAt) {
private Club(Long id, User user, List<ClubMember> clubMembers, String name, String category,
String tag,
String leader, PhoneNumber phoneNumber, Location location, String regularMeeting,
String introduction, String activity,
String ideal, Score score, LocalDateTime deletedAt) {
this.id = id;
this.user = user;
this.clubMembers = clubMembers;
Expand All @@ -92,13 +87,10 @@ private Club(Long id, User user, List<ClubMember> clubMembers, String name, Stri
this.leader = leader;
this.phoneNumber = phoneNumber;
this.location = location;
this.startRecruitPeriod = startRecruitPeriod;
this.endRecruitPeriod = endRecruitPeriod;
this.regularMeeting = regularMeeting;
this.introduction = introduction;
this.activity = activity;
this.ideal = ideal;
this.formUrl = formUrl;
this.score = score;
this.deletedAt = deletedAt;
}
Expand All @@ -110,13 +102,10 @@ public void updateClubInfo(Club club) {
this.leader = club.getLeader();
this.phoneNumber = club.getPhoneNumber();
this.location = club.getLocation();
this.startRecruitPeriod = club.getStartRecruitPeriod();
this.endRecruitPeriod = club.getEndRecruitPeriod();
this.regularMeeting = club.getRegularMeeting();
this.introduction = club.getIntroduction();
this.activity = club.getActivity();
this.ideal = club.getIdeal();
this.formUrl = club.getFormUrl();
}

public BigDecimal editScore(Score score) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import ddingdong.ddingdongBE.domain.club.service.dto.query.MyClubInfoQuery;
import ddingdong.ddingdongBE.domain.filemetadata.entity.DomainType;
import ddingdong.ddingdongBE.domain.filemetadata.service.FileMetaDataService;
import ddingdong.ddingdongBE.domain.form.entity.Form;
import ddingdong.ddingdongBE.domain.form.service.FormService;
import ddingdong.ddingdongBE.file.service.S3FileService;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlQuery;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -19,12 +22,18 @@ public class FacadeCentralClubServiceImpl implements FacadeCentralClubService {
private final ClubService clubService;
private final FileMetaDataService fileMetaDataService;
private final S3FileService s3FileService;
private final FormService formService;

@Override
public MyClubInfoQuery getMyClubInfo(Long userId) {
Club club = clubService.getByUserId(userId);
List<Form> forms = formService.getAllByClub(club);
Form form = formService.findActiveForm(forms) != null
? formService.findActiveForm(forms)
: formService.getNewestForm(forms);
return MyClubInfoQuery.of(
club,
form,
getFileKey(DomainType.CLUB_PROFILE, club.getId()),
getFileKey(DomainType.CLUB_INTRODUCTION, club.getId())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import ddingdong.ddingdongBE.domain.club.service.dto.query.UserClubListQuery;
import ddingdong.ddingdongBE.domain.club.service.dto.query.UserClubQuery;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.util.List;

public interface FacadeUserClubService {

List<UserClubListQuery> findAllWithRecruitTimeCheckPoint(LocalDateTime now);
List<UserClubListQuery> findAllWithRecruitTimeCheckPoint(LocalDate now);

UserClubQuery getClub(Long clubId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import ddingdong.ddingdongBE.domain.club.service.dto.query.UserClubQuery;
import ddingdong.ddingdongBE.domain.filemetadata.entity.DomainType;
import ddingdong.ddingdongBE.domain.filemetadata.service.FileMetaDataService;
import ddingdong.ddingdongBE.domain.form.entity.Form;
import ddingdong.ddingdongBE.domain.form.service.FormService;
import ddingdong.ddingdongBE.file.service.S3FileService;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlQuery;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -26,30 +28,42 @@ public class FacadeUserClubServiceImpl implements FacadeUserClubService {
private final ClubService clubService;
private final FileMetaDataService fileMetaDataService;
private final S3FileService s3FileService;
private final FormService formService;

@Override
public List<UserClubListQuery> findAllWithRecruitTimeCheckPoint(LocalDateTime now) {
public List<UserClubListQuery> findAllWithRecruitTimeCheckPoint(LocalDate now) {
return clubService.findAll().stream()
.map(club -> UserClubListQuery.of(club, checkRecruit(now, club).getText()))
.map(club -> {
List<Form> forms = formService.getAllByClub(club);
Form form = formService.findActiveForm(forms) != null
? formService.findActiveForm(forms)
: formService.getNewestForm(forms);
return UserClubListQuery.of(club, checkRecruit(now, form).getText());
})
.toList();
}

@Override
public UserClubQuery getClub(Long clubId) {
Club club = clubService.getById(clubId);
List<Form> forms = formService.getAllByClub(club);
Form form = formService.findActiveForm(forms) != null
? formService.findActiveForm(forms)
: formService.getNewestForm(forms);
return UserClubQuery.of(
club,
form,
getFileKey(DomainType.CLUB_PROFILE, clubId),
getFileKey(DomainType.CLUB_INTRODUCTION, clubId)
);
}

private RecruitmentStatus checkRecruit(LocalDateTime now, Club club) {
if (club.getStartRecruitPeriod() == null || club.getEndRecruitPeriod() == null
|| club.getStartRecruitPeriod().isAfter(now)) {
private RecruitmentStatus checkRecruit(LocalDate now, Form form) {
if (form == null
|| form.getStartDate().isAfter(now)) {
return BEFORE_RECRUIT;
}
return club.getEndRecruitPeriod().isAfter(now) ? RECRUITING : END_RECRUIT;
return form.getEndDate().isAfter(now) ? RECRUITING : END_RECRUIT;
}

private UploadedFileUrlQuery getFileKey(DomainType domainType, Long clubId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ public record UpdateClubInfoCommand(
String clubLeader,
String phoneNumber,
String location,
String startRecruitPeriod,
String endRecruitPeriod,
String regularMeeting,
String introduction,
String activity,
String ideal,
String formUrl,
String profileImageId,
String introductionImageId
) {
Expand All @@ -33,18 +30,10 @@ public Club toEntity() {
.leader(clubLeader)
.phoneNumber(PhoneNumber.from(phoneNumber))
.location(Location.from(location))
.startRecruitPeriod(parseLocalDateTime(startRecruitPeriod))
.endRecruitPeriod(parseLocalDateTime(endRecruitPeriod))
.regularMeeting(regularMeeting)
.introduction(introduction)
.activity(activity)
.ideal(ideal)
.formUrl(formUrl)
.build();
}

private LocalDateTime parseLocalDateTime(String inputLocalDateTimeFormat) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
return LocalDateTime.parse(inputLocalDateTimeFormat, formatter);
}
}
Loading

0 comments on commit b4cf4bb

Please sign in to comment.