-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.2.0
- Loading branch information
Showing
29 changed files
with
1,324 additions
and
551 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
main/src/main/java/org/sopt/makers/crew/main/entity/meeting/CoLeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.sopt.makers.crew.main.entity.meeting; | ||
|
||
import static org.sopt.makers.crew.main.global.exception.ErrorStatus.*; | ||
|
||
import java.util.Objects; | ||
|
||
import org.sopt.makers.crew.main.entity.common.BaseTimeEntity; | ||
import org.sopt.makers.crew.main.entity.user.User; | ||
import org.sopt.makers.crew.main.global.exception.BadRequestException; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "co_leader") | ||
public class CoLeader extends BaseTimeEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "meetingId") | ||
@NotNull | ||
private Meeting meeting; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "userId") | ||
@NotNull | ||
private User user; | ||
|
||
@Builder | ||
private CoLeader(Meeting meeting, User user) { | ||
if (Objects.equals(meeting.getUserId(), user.getId())) { | ||
throw new BadRequestException(LEADER_CANNOT_BE_CO_LEADER_APPLY.getErrorCode()); | ||
} | ||
this.meeting = meeting; | ||
this.user = user; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
main/src/main/java/org/sopt/makers/crew/main/entity/meeting/CoLeaderRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.sopt.makers.crew.main.entity.meeting; | ||
|
||
import java.util.List; | ||
|
||
import org.sopt.makers.crew.main.entity.user.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CoLeaderRepository extends JpaRepository<CoLeader, Integer> { | ||
|
||
void deleteAllByMeetingId(Integer meetingId); | ||
|
||
List<CoLeader> findAllByMeetingId(Integer meetingId); | ||
|
||
List<CoLeader> findAllByMeetingIdIn(List<Integer> meetingId); | ||
|
||
List<CoLeader> findAllByUserId(Integer userId); | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
main/src/main/java/org/sopt/makers/crew/main/entity/meeting/CoLeaders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.sopt.makers.crew.main.entity.meeting; | ||
|
||
import static org.sopt.makers.crew.main.global.exception.ErrorStatus.*; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import org.sopt.makers.crew.main.global.exception.BadRequestException; | ||
|
||
public class CoLeaders { | ||
/** | ||
* Key : MeetingId | ||
* Value : 해당 모임의 공동 모임장 목록 | ||
* | ||
* @implNote : List 내에 있는 CoLeader 객체는 fetch join 으로 다른 객체를 불러오지 않은 상태 | ||
* @implNote : 해당 자료형을 사용할 때는 'isCoLeaderPresent' 메서드 사용 적극 권장 | ||
* | ||
* */ | ||
private final Map<Integer, List<CoLeader>> coLeadersMap; | ||
|
||
public CoLeaders(List<CoLeader> coLeaders) { | ||
this.coLeadersMap = coLeaders.stream() | ||
.collect(Collectors.groupingBy(coLeader -> coLeader.getMeeting().getId())); | ||
} | ||
|
||
public void validateCoLeader(Integer meetingId, Integer requestUserId) { | ||
if (isCoLeader(meetingId, requestUserId)) { | ||
throw new BadRequestException(CO_LEADER_CANNOT_APPLY.getErrorCode()); | ||
} | ||
} | ||
|
||
public boolean isCoLeader(Integer meetingId, Integer requestUserId) { | ||
if (!isCoLeaderPresent(meetingId)) { | ||
return false; | ||
} | ||
|
||
return coLeadersMap.get(meetingId).stream() | ||
.anyMatch(coLeader -> coLeader.getUser().getId().equals(requestUserId)); | ||
} | ||
|
||
public List<CoLeader> getCoLeaders(Integer meetingId) { | ||
if (!isCoLeaderPresent(meetingId)) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
return Collections.unmodifiableList(coLeadersMap.get(meetingId)); | ||
} | ||
|
||
private boolean isCoLeaderPresent(Integer meetingId) { | ||
return coLeadersMap.containsKey(meetingId); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.