Skip to content

Commit

Permalink
feat: 단체분야 & 협업유형 리스트화 (#362)
Browse files Browse the repository at this point in the history
* feat: 단체분야 & 협업유형 리스트 형식으로 변경

* feat: 단체 조회 시, 본인은 조회 안되도록 변경
  • Loading branch information
kimday0326 authored Jul 15, 2024
1 parent 55da5e2 commit a2be0c4
Show file tree
Hide file tree
Showing 30 changed files with 342 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import java.time.LocalDateTime;

import com.sponus.coredomain.domain.bookmark.Bookmark;
import com.sponus.coredomain.domain.organization.Club;
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coredomain.domain.organization.enums.OrganizationType;
import com.sponus.sponusbe.domain.organization.club.dto.ClubGetResponse;

import lombok.Builder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sponus.sponusbe.domain.organization.club.dto;

import com.sponus.coredomain.domain.organization.Club;
import java.util.List;

import com.sponus.coredomain.domain.organization.club.Club;

public record ClubGetResponse(
Long id,
Expand All @@ -14,7 +16,7 @@ public record ClubGetResponse(
String profileStatus,
String role,
int memberCount,
String clubType
List<String> clubTypes
) {
public static ClubGetResponse of(Club club) {
return new ClubGetResponse(
Expand All @@ -29,7 +31,7 @@ public static ClubGetResponse of(Club club) {
club.getProfileStatus().name(),
club.getRole().name(),
club.getMemberCount(),
club.getClubType().name()
club.getSubTypeNames()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sponus.sponusbe.domain.organization.club.dto;

import com.sponus.coredomain.domain.organization.enums.ClubType;
import java.util.List;

import com.sponus.coredomain.domain.organization.club.ClubTypeEnum;
import com.sponus.coredomain.domain.organization.enums.ProfileStatus;

import jakarta.validation.constraints.Min;
Expand All @@ -23,7 +25,7 @@ public record ClubUpdateRequest(
int memberCount,

@NotNull(message = "[ERROR] 동아리 타입은 필수 입력 값입니다.")
ClubType clubType,
List<ClubTypeEnum> clubTypes,

@NotNull(message = "[ERROR] 프로필 공개 여부는 필수 입력 값입니다.")
ProfileStatus profileStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sponus.coredomain.domain.organization.Club;
import com.sponus.coredomain.domain.organization.club.Club;
import com.sponus.coredomain.domain.organization.club.ClubType;
import com.sponus.coredomain.domain.organization.repository.ClubRepository;
import com.sponus.coredomain.domain.organization.repository.ClubTypeRepository;
import com.sponus.sponusbe.domain.organization.club.dto.ClubGetResponse;
import com.sponus.sponusbe.domain.organization.club.dto.ClubUpdateRequest;
import com.sponus.sponusbe.domain.organization.exception.ClubErrorCode;
Expand All @@ -17,6 +19,7 @@
@RequiredArgsConstructor
public class ClubService {
private final ClubRepository clubRepository;
private final ClubTypeRepository clubTypeRepository;

public ClubGetResponse getClub(Long clubId) {
final Club club = findClubById(clubId);
Expand All @@ -30,9 +33,13 @@ public void updateClub(Long clubId, ClubUpdateRequest request) {
request.description(),
request.imageUrl(),
request.memberCount(),
request.clubType(),
request.profileStatus()
);
request.clubTypes().forEach(type -> {
ClubType clubType = new ClubType(type);
clubType.updateClub(club);
clubTypeRepository.save(clubType);
});
}

private Club findClubById(Long clubId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.sponus.sponusbe.domain.organization.company.dto;

import com.sponus.coredomain.domain.organization.Company;
import java.util.List;

import lombok.Builder;
import com.sponus.coredomain.domain.organization.company.Company;

@Builder
public record CompanyGetResponse(
Long id,
String name,
Expand All @@ -16,25 +15,25 @@ public record CompanyGetResponse(
String organizationType,
String profileStatus,
String role,
String companyType,
String collaborationType,
List<String> companyTypes,
List<String> collaborationTypes,
String sponsorshipContent
) {
public static CompanyGetResponse of(Company company) {
return CompanyGetResponse.builder()
.id(company.getId())
.name(company.getName())
.email(company.getEmail())
.description(company.getDescription())
.imageUrl(company.getImageUrl())
.bookmarkCount(company.getBookmarkCount())
.viewCount(company.getViewCount())
.organizationType(company.getOrganizationType().name())
.profileStatus(company.getProfileStatus().name())
.role(company.getRole().name())
.companyType(company.getCompanyType().name())
.collaborationType(company.getCollaborationType().name())
.sponsorshipContent(company.getSponsorshipContent())
.build();
return new CompanyGetResponse(
company.getId(),
company.getName(),
company.getEmail(),
company.getDescription(),
company.getImageUrl(),
company.getBookmarkCount(),
company.getViewCount(),
company.getOrganizationType().name(),
company.getProfileStatus().name(),
company.getRole().name(),
company.getSubTypeNames(),
company.getCollaborationTypeNames(),
company.getSponsorshipContent()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.sponus.sponusbe.domain.organization.company.dto;

import com.sponus.coredomain.domain.organization.enums.CollaborationType;
import com.sponus.coredomain.domain.organization.enums.CompanyType;
import java.util.List;

import com.sponus.coredomain.domain.organization.company.CollaborationTypeEnum;
import com.sponus.coredomain.domain.organization.company.CompanyTypeEnum;
import com.sponus.coredomain.domain.organization.enums.ProfileStatus;

import jakarta.validation.constraints.NotBlank;
Expand All @@ -20,10 +22,10 @@ public record CompanyUpdateRequest(
String imageUrl,

@NotNull(message = "[ERROR] 회사 타입은 필수 입력 값입니다.")
CompanyType companyType,
List<CompanyTypeEnum> companyTypes,

@NotNull(message = "[ERROR] 협업 타입은 필수 입력 값입니다.")
CollaborationType collaborationType,
List<CollaborationTypeEnum> collaborationTypes,

String sponsorshipContent, // 협찬 물품

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sponus.sponusbe.domain.organization.company.dto;

import java.util.List;

import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coredomain.domain.organization.enums.OrganizationType;

Expand All @@ -15,7 +17,7 @@ public record OrganizationGetResponse(
int bookmarkCount,
int viewCount,
OrganizationType organizationType,
String subType,
List<String> subTypes,
boolean isBookmarked
) {

Expand All @@ -29,7 +31,7 @@ public static OrganizationGetResponse of(Organization organization, boolean isBo
.bookmarkCount(organization.getBookmarkCount())
.viewCount(organization.getViewCount())
.organizationType(organization.getOrganizationType())
.subType(organization.getSubType())
.subTypes(organization.getSubTypeNames())
.isBookmarked(isBookmarked)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sponus.coredomain.domain.organization.Company;
import com.sponus.coredomain.domain.organization.company.CollaborationType;
import com.sponus.coredomain.domain.organization.company.Company;
import com.sponus.coredomain.domain.organization.company.CompanyType;
import com.sponus.coredomain.domain.organization.repository.CollaborationRepository;
import com.sponus.coredomain.domain.organization.repository.CompanyRepository;
import com.sponus.coredomain.domain.organization.repository.CompanyTypeRepository;
import com.sponus.sponusbe.domain.organization.company.dto.CompanyGetResponse;
import com.sponus.sponusbe.domain.organization.company.dto.CompanyUpdateRequest;
import com.sponus.sponusbe.domain.organization.exception.CompanyErrorCode;
Expand All @@ -17,6 +21,8 @@
@RequiredArgsConstructor
public class CompanyService {
private final CompanyRepository companyRepository;
private final CompanyTypeRepository companyTypeRepository;
private final CollaborationRepository collaborationRepository;

public CompanyGetResponse getCompany(Long companyId) {
final Company company = findCompanyById(companyId);
Expand All @@ -29,11 +35,19 @@ public void updateCompany(Long companyId, CompanyUpdateRequest request) {
request.name(),
request.description(),
request.imageUrl(),
request.collaborationType(),
request.sponsorshipContent(),
request.companyType(),
request.profileStatus()
request.profileStatus(),
request.sponsorshipContent()
);
request.companyTypes().forEach(type -> {
final CompanyType companyType = new CompanyType(type);
companyType.updateCompany(company);
companyTypeRepository.save(companyType);
});
request.collaborationTypes().forEach(type -> {
final CollaborationType collaborationType = new CollaborationType(type);
collaborationType.updateCompany(company);
collaborationRepository.save(collaborationType);
});
}

private Company findCompanyById(Long companyId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import org.springframework.web.multipart.MultipartFile;

import com.sponus.coredomain.domain.bookmark.repository.BookmarkRepository;
import com.sponus.coredomain.domain.organization.Club;
import com.sponus.coredomain.domain.organization.Company;
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coredomain.domain.organization.club.Club;
import com.sponus.coredomain.domain.organization.company.Company;
import com.sponus.coredomain.domain.organization.enums.OrganizationType;
import com.sponus.coredomain.domain.organization.enums.ProfileStatus;
import com.sponus.coredomain.domain.organization.repository.OrganizationRepository;
Expand Down Expand Up @@ -82,7 +82,7 @@ public PageResponse<OrganizationGetResponse> getOrganizations(
.collect(Collectors.toSet());
Pageable pageable = PageRequest.of(pageCondition.getPage() - 1, pageCondition.getSize());
List<OrganizationGetResponse> organizations = organizationRepository.findOrganizations(
organizationType, pageable)
organizationType, pageable, authOrganization.getId())
.stream()
.map(organization ->
OrganizationGetResponse.of(organization, bookmarkedOrganizationIds.contains(organization.getId())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.sponus.coredomain.domain.organization.Club;
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coredomain.domain.organization.club.Club;
import com.sponus.coredomain.domain.organization.repository.ClubRepository;
import com.sponus.coredomain.domain.portfolio.Portfolio;
import com.sponus.coredomain.domain.portfolio.PortfolioImage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sponus.coredomain.domain.organization;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.sponus.coredomain.domain.bookmark.Bookmark;
Expand Down Expand Up @@ -133,7 +134,7 @@ public boolean isCompany() {
return this.organizationType == OrganizationType.COMPANY;
}

public String getSubType() {
return null;
public List<String> getSubTypeNames() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.sponus.coredomain.domain.organization;
package com.sponus.coredomain.domain.organization.club;

import com.sponus.coredomain.domain.organization.enums.ClubType;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coredomain.domain.organization.enums.OrganizationType;
import com.sponus.coredomain.domain.organization.enums.ProfileStatus;
import com.sponus.coredomain.domain.organization.enums.Role;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand All @@ -26,15 +30,13 @@ public class Club extends Organization {
@Column(name = "member_count")
private int memberCount;

@Enumerated(EnumType.STRING)
@Column(name = "company_type")
private ClubType clubType;

@OneToMany(mappedBy = "club", cascade = CascadeType.ALL)
private Set<ClubType> clubTypes = new HashSet<>();

// 초기 생성 시 사용
public Club(String name, String email, String password) {
super(name, email, password, null, null, OrganizationType.CLUB, ProfileStatus.INACTIVE, Role.GUEST);
this.memberCount = 0;
this.clubType = ClubType.NONE;
}

// 프로필 업데이트 시 사용
Expand All @@ -43,15 +45,13 @@ public void updateInfo(
String description,
String imageUrl,
int memberCount,
ClubType clubType,
ProfileStatus profileStatus) {
super.updateInfo(name, description, imageUrl, profileStatus);
this.memberCount = memberCount;
this.clubType = clubType;
}

@Override
public String getSubType() {
return clubType.name();
public List<String> getSubTypeNames() {
return clubTypes.stream().map(type -> type.getType().name()).toList();
}
}
Loading

0 comments on commit a2be0c4

Please sign in to comment.