Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.2.0 #474

Merged
merged 17 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
211e9be
refactor(AdvertisementGetDto): isSponsoredContent ν•„λ“œ DTOμ—μ„œ 제거
hoonyworld Sep 28, 2024
dc04cf4
Merge branch 'develop' of https://github.com/sopt-makers/sopt-crew-ba…
hoonyworld Sep 29, 2024
f12e17d
Merge branch 'develop' of https://github.com/sopt-makers/sopt-crew-ba…
hoonyworld Sep 29, 2024
0b3f12a
Merge branch 'develop' of https://github.com/sopt-makers/sopt-crew-ba…
hoonyworld Oct 2, 2024
92234d6
Merge branch 'develop' of https://github.com/sopt-makers/sopt-crew-ba…
hoonyworld Oct 5, 2024
72cb18a
Merge branch 'develop' of https://github.com/sopt-makers/sopt-crew-ba…
hoonyworld Oct 9, 2024
d037187
Merge branch 'develop' of https://github.com/sopt-makers/sopt-crew-ba…
hoonyworld Oct 12, 2024
5bb615f
Merge branch 'develop' of https://github.com/sopt-makers/sopt-crew-ba…
hoonyworld Oct 13, 2024
2f94ddf
hotfix: λ³€κ²½λœ dev μ„œλ²„ λ„λ©”μΈμœΌλ‘œ λ³€κ²½
hoonyworld Oct 13, 2024
ce20f79
feat: 전체 μ‚¬μš©μž 쑰회 API κ΅¬ν˜„ (#448)
mikekks Oct 13, 2024
01dbc3a
feat: 곡동 λͺ¨μž„μž₯ κ΅¬ν˜„ (#449)
mikekks Oct 13, 2024
3d5c260
feat: 곡동 λͺ¨μž„μž₯ μΆ”κ°€ κ΅¬ν˜„ (#463)
mikekks Oct 16, 2024
82c999e
feat: 둜그 좜λ ₯용 AOP κ΅¬ν˜„ (#430)
mikekks Oct 16, 2024
0534d13
refactor: 승인된 μ‹ μ²­μž 수 ν•„λ“œ μΆ”κ°€ (#464)
mikekks Oct 27, 2024
e15f8d8
chore: approvedCount ν•„λ“œ μΆ”κ°€ (#466)
mikekks Oct 30, 2024
00a6ba8
fix: λͺ¨μž„ μˆ˜μ • 였λ₯˜ ν•΄κ²° (#470)
mikekks Oct 31, 2024
91f2139
fix: λͺ¨μž„μž₯은 곡동λͺ¨μž„μž₯이 될 수 μ—†λ‹€. (#476)
mikekks Nov 8, 2024
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
Expand Up @@ -14,41 +14,47 @@

public interface ApplyRepository extends JpaRepository<Apply, Integer>, ApplySearchRepository {

@Query("select a from Apply a join fetch a.meeting m where a.userId = :userId and a.status = :statusValue")
List<Apply> findAllByUserIdAndStatus(@Param("userId") Integer userId,
@Param("statusValue") EnApplyStatus statusValue);

@Query("select a from Apply a join fetch a.meeting m join fetch m.user u where a.userId = :userId")
List<Apply> findAllByUserId(@Param("userId") Integer userId);

@Query("select a "
+ "from Apply a "
+ "join fetch a.user u "
+ "where a.meetingId = :meetingId "
+ "and a.status in :statuses order by :order")
List<Apply> findAllByMeetingIdWithUser(@Param("meetingId") Integer meetingId, @Param("statuses") List<EnApplyStatus> statuses, @Param("order") String order);

List<Apply> findAllByMeetingIdAndStatus(Integer meetingId, EnApplyStatus statusValue);

List<Apply> findAllByMeetingId(Integer meetingId);

List<Apply> findAllByMeetingIdIn(List<Integer> meetingIds);

boolean existsByMeetingIdAndUserId(Integer meetingId, Integer userId);

@Transactional
@Modifying
@Query("delete from Apply a where a.meeting.id = :meetingId and a.userId = :userId")
void deleteByMeetingIdAndUserId(@Param("meetingId") Integer meetingId, @Param("userId") Integer userId);

default Apply findByIdOrThrow(Integer applyId) {
return findById(applyId)
.orElseThrow(() -> new BadRequestException(NOT_FOUND_APPLY.getErrorCode()));
}

@Modifying(clearAutomatically = true)
@Transactional
@Query("DELETE FROM Apply a WHERE a.meetingId = :meetingId")
void deleteAllByMeetingIdQuery(Integer meetingId);
@Query("select a from Apply a join fetch a.meeting m where a.userId = :userId and a.status = :statusValue")
List<Apply> findAllByUserIdAndStatus(@Param("userId") Integer userId,
@Param("statusValue") EnApplyStatus statusValue);

@Query("select a "
+ "from Apply a "
+ "join fetch a.meeting m "
+ "join fetch m.user u "
+ "where a.userId = :userId "
+ "ORDER BY a.id DESC ")
List<Apply> findAllByUserIdOrderByIdDesc(@Param("userId") Integer userId);

@Query("select a "
+ "from Apply a "
+ "join fetch a.user u "
+ "where a.meetingId = :meetingId "
+ "and a.status in :statuses order by :order")
List<Apply> findAllByMeetingIdWithUser(@Param("meetingId") Integer meetingId,
@Param("statuses") List<EnApplyStatus> statuses, @Param("order") String order);

List<Apply> findAllByMeetingIdAndStatus(Integer meetingId, EnApplyStatus statusValue);

List<Apply> findAllByMeetingId(Integer meetingId);

List<Apply> findAllByMeetingIdIn(List<Integer> meetingIds);

boolean existsByMeetingIdAndUserId(Integer meetingId, Integer userId);

@Transactional
@Modifying(clearAutomatically = true)
@Query("delete from Apply a where a.meeting.id = :meetingId and a.userId = :userId")
void deleteByMeetingIdAndUserId(@Param("meetingId") Integer meetingId, @Param("userId") Integer userId);

default Apply findByIdOrThrow(Integer applyId) {
return findById(applyId)
.orElseThrow(() -> new BadRequestException(NOT_FOUND_APPLY.getErrorCode()));
}

@Modifying(clearAutomatically = true)
@Transactional
@Query("DELETE FROM Apply a WHERE a.meetingId = :meetingId")
void deleteAllByMeetingIdQuery(Integer meetingId);

}
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;
}
}
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);

}
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ public void validateMeetingCreator(Integer requestUserId) {
}
}

public void validateIsNotMeetingLeader(Integer requestUserId) {
if (checkMeetingLeader(requestUserId)) {
throw new BadRequestException(LEADER_CANNOT_APPLY.getErrorCode());
}
}

public Boolean checkMeetingLeader(Integer userId) {
return this.userId.equals(userId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@
import java.util.List;

import org.sopt.makers.crew.main.global.exception.BadRequestException;
import org.sopt.makers.crew.main.entity.user.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface MeetingRepository extends JpaRepository<Meeting, Integer>, MeetingSearchRepository {

List<Meeting> findAllByUserId(Integer userId);

List<Meeting> findAllByUser(User user);
/**
* @implSpec : νŠΉμ • μœ μ €κ°€ λͺ¨μž„μž₯μ΄κ±°λ‚˜ 곡동λͺ¨μž„μž₯인 λͺ¨μž„을 μ΅œκ·Όμ— λ§Œλ“€μ–΄μ§„ 순으둜 μ‘°νšŒν•œλ‹€.
* **/
@Query("SELECT m "
+ "FROM Meeting m "
+ "JOIN fetch m.user "
+ "WHERE m.user.id =:userId "
+ "OR m.id IN (:coLeaderMeetingIds)"
+ "ORDER BY m.id DESC ")
List<Meeting> findAllByUserIdOrIdInWithUser(Integer userId, List<Integer> coLeaderMeetingIds);

default Meeting findByIdOrThrow(Integer meetingId) {
return findById(meetingId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import static org.sopt.makers.crew.main.global.exception.ErrorStatus.*;

import java.util.List;
import java.util.Optional;

import org.sopt.makers.crew.main.global.exception.NotFoundException;
import org.sopt.makers.crew.main.global.exception.UnAuthorizedException;
import org.springframework.data.jpa.repository.JpaRepository;

Expand All @@ -16,4 +18,19 @@ default User findByIdOrThrow(Integer userId) {
.orElseThrow(() -> new UnAuthorizedException(UNAUTHORIZED_USER.getErrorCode()));
}

List<User> findAllByIdIn(List<Integer> userIds);

default List<User> findAllByIdInOrThrow(List<Integer> userIds) {
List<User> users = findAllByIdIn(userIds);
List<Integer> foundUserIds = users.stream()
.map(User::getId)
.toList();

if (!foundUserIds.containsAll(userIds)) {
throw new NotFoundException(NOT_FOUND_USER.getErrorCode());
}

return users;
}

}
Loading
Loading