-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from Modagbul/develop
merge from develop to main
- Loading branch information
Showing
21 changed files
with
565 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
|
||
[[Fire-API]] | ||
= Fire API | ||
|
||
[[Fire-불던지기]] | ||
=== 불 던지기 | ||
operation::fire-controller-test/불_던지기[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] | ||
|
||
--- | ||
[[Fire-불던질사람조회]] | ||
=== 불 던질 사람 조회 | ||
operation::fire-controller-test/불_던질_사람_조회[snippets='http-request,path-parameters,request-fields,http-response,response-fields'] | ||
|
||
--- | ||
|
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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/moing/backend/domain/fire/application/dto/res/FireReceiveRes.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,19 @@ | ||
package com.moing.backend.domain.fire.application.dto.res; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
public class FireReceiveRes { | ||
|
||
private Long receiveMemberId; | ||
private String nickname; | ||
private String fireStatus; | ||
|
||
public void updateFireStatus(boolean status) { | ||
if (status) | ||
this.fireStatus = "True"; | ||
else this.fireStatus = "False"; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/moing/backend/domain/fire/application/dto/res/FireThrowRes.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,11 @@ | ||
package com.moing.backend.domain.fire.application.dto.res; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class FireThrowRes { | ||
|
||
private Long receiveMemberId; | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/moing/backend/domain/fire/application/mapper/FireMapper.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,34 @@ | ||
package com.moing.backend.domain.fire.application.mapper; | ||
|
||
import com.moing.backend.domain.fire.application.dto.res.FireReceiveRes; | ||
import com.moing.backend.domain.fire.application.dto.res.FireThrowRes; | ||
import com.moing.backend.domain.fire.domain.entity.Fire; | ||
import com.moing.backend.domain.member.domain.entity.Member; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FireMapper { | ||
|
||
public static FireThrowRes mapToFireThrowRes(Fire fire) { | ||
return FireThrowRes.builder() | ||
.receiveMemberId(fire.getReceiveMemberId()) | ||
.build(); | ||
} | ||
|
||
public static List<FireReceiveRes> mapToFireReceiversList(List<Member> members) { | ||
List<FireReceiveRes> fireReceiveResList = new ArrayList<>(); | ||
members.forEach( | ||
member -> fireReceiveResList.add(FireMapper.mapToFireReceiveRes(member)) | ||
); | ||
return fireReceiveResList; | ||
} | ||
|
||
public static FireReceiveRes mapToFireReceiveRes(Member member) { | ||
return FireReceiveRes.builder() | ||
.receiveMemberId(member.getMemberId()) | ||
.nickname(member.getNickName()) | ||
.fireStatus("TRUE") | ||
.build(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/moing/backend/domain/fire/application/service/FireThrowUseCase.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 com.moing.backend.domain.fire.application.service; | ||
|
||
import com.moing.backend.domain.fire.application.dto.res.FireReceiveRes; | ||
import com.moing.backend.domain.fire.application.dto.res.FireThrowRes; | ||
import com.moing.backend.domain.fire.application.mapper.FireMapper; | ||
import com.moing.backend.domain.fire.domain.entity.Fire; | ||
import com.moing.backend.domain.fire.domain.repository.FireCustomRepository; | ||
import com.moing.backend.domain.fire.domain.service.FireQueryService; | ||
import com.moing.backend.domain.fire.domain.service.FireSaveService; | ||
import com.moing.backend.domain.fire.exception.NoAuthThrowFireException; | ||
import com.moing.backend.domain.member.domain.service.MemberGetService; | ||
import com.moing.backend.domain.mission.application.service.MissionCreateUseCase; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class FireThrowUseCase { | ||
|
||
public final FireSaveService fireSaveService; | ||
public final FireQueryService fireQueryService; | ||
private final MemberGetService memberGetService; | ||
|
||
public FireThrowRes createFireThrow(String userId, Long receiveMemberId) { | ||
|
||
Long throwMemberId = memberGetService.getMemberBySocialId(userId).getMemberId(); | ||
|
||
if (!fireQueryService.hasFireCreatedWithinOneHour(throwMemberId, receiveMemberId)) { | ||
throw new NoAuthThrowFireException(); | ||
} | ||
|
||
return FireMapper.mapToFireThrowRes(fireSaveService.save(Fire.builder() | ||
.throwMemberId(throwMemberId) | ||
.receiveMemberId(receiveMemberId) | ||
.build())); | ||
} | ||
|
||
public List<FireReceiveRes> getFireReceiveList(String userId,Long teamId, Long missionId) { | ||
Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId(); | ||
|
||
List<FireReceiveRes> fireReceiveRes = FireMapper.mapToFireReceiversList(fireQueryService.getNotYetMissionMember(teamId, missionId)); | ||
fireReceiveRes.forEach( | ||
res -> res.updateFireStatus(fireQueryService.hasFireCreatedWithinOneHour(memberId,res.getReceiveMemberId()) | ||
)); | ||
|
||
return fireReceiveRes; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/moing/backend/domain/fire/domain/entity/Fire.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,28 @@ | ||
package com.moing.backend.domain.fire.domain.entity; | ||
|
||
import com.moing.backend.global.entity.BaseTimeEntity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Fire extends BaseTimeEntity { | ||
|
||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "fire_id") | ||
private Long id; | ||
|
||
private Long throwMemberId; | ||
|
||
private Long receiveMemberId; | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/moing/backend/domain/fire/domain/repository/FireCustomRepository.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,16 @@ | ||
package com.moing.backend.domain.fire.domain.repository; | ||
|
||
|
||
import com.moing.backend.domain.fire.domain.entity.Fire; | ||
import com.moing.backend.domain.member.domain.entity.Member; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface FireCustomRepository { | ||
|
||
boolean hasFireCreatedWithinOneHour(Long throwMemberId, Long receiveMemberId); | ||
Optional<List<Member>> getFireReceivers(Long teamId, Long missionId); | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/com/moing/backend/domain/fire/domain/repository/FireCustomRepositoryImpl.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,74 @@ | ||
package com.moing.backend.domain.fire.domain.repository; | ||
|
||
import com.moing.backend.domain.fire.domain.entity.Fire; | ||
import com.moing.backend.domain.fire.domain.entity.QFire; | ||
import com.moing.backend.domain.member.domain.entity.Member; | ||
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; | ||
import com.querydsl.jpa.JPAExpressions; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import javax.persistence.EntityManager; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static com.moing.backend.domain.fire.domain.entity.QFire.fire; | ||
import static com.moing.backend.domain.member.domain.entity.QMember.member; | ||
import static com.moing.backend.domain.mission.domain.entity.QMission.mission; | ||
import static com.moing.backend.domain.missionArchive.domain.entity.QMissionArchive.missionArchive; | ||
import static com.moing.backend.domain.team.domain.entity.QTeam.team; | ||
import static com.moing.backend.domain.teamMember.domain.entity.QTeamMember.teamMember; | ||
import static com.querydsl.jpa.JPAExpressions.max; | ||
import static com.querydsl.jpa.JPAExpressions.select; | ||
|
||
public class FireCustomRepositoryImpl implements FireCustomRepository { | ||
private final JPAQueryFactory queryFactory; | ||
|
||
public FireCustomRepositoryImpl(EntityManager em) { | ||
this.queryFactory = new JPAQueryFactory(em); | ||
} | ||
|
||
|
||
public boolean hasFireCreatedWithinOneHour(Long throwMemberId, Long receiveMemberId) { | ||
|
||
|
||
LocalDateTime oneHourAgo = LocalDateTime.now().minusHours(1); // 현재 시간에서 1시간을 뺀 시간 | ||
long count = queryFactory | ||
.select() | ||
.from(fire) | ||
.where( | ||
fire.throwMemberId.eq(throwMemberId), | ||
fire.receiveMemberId.eq(receiveMemberId), | ||
fire.createdDate.after(oneHourAgo) // createdDate가 oneHourAgo 이후인 데이터 | ||
) | ||
.fetchCount(); | ||
|
||
return count <= 0; // 1시간 이내에 생성된 데이터가 존재하면 true를 반환, 그렇지 않으면 false 반환 | ||
} | ||
|
||
|
||
public Optional<List<Member>> getFireReceivers(Long teamId, Long missionId) { | ||
return Optional.ofNullable(queryFactory | ||
.select(teamMember.member) | ||
.from(teamMember) | ||
.where( | ||
teamMember.team.teamId.eq(teamId), | ||
teamMember.member.memberId.notIn( | ||
JPAExpressions | ||
.select(missionArchive.member.memberId) | ||
.from(missionArchive,mission) | ||
.where(missionArchive.mission.id.eq(missionId), | ||
mission.id.eq(missionId)) | ||
.groupBy(missionArchive.member.memberId, missionArchive.mission.id, | ||
missionArchive.count, mission.number) | ||
.having( | ||
missionArchive.mission.id.eq(missionId), | ||
missionArchive.count.max().goe(mission.number) | ||
) | ||
) | ||
) | ||
.fetch()); | ||
|
||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/moing/backend/domain/fire/domain/repository/FireRepository.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,7 @@ | ||
package com.moing.backend.domain.fire.domain.repository; | ||
|
||
import com.moing.backend.domain.fire.domain.entity.Fire; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FireRepository extends JpaRepository<Fire,Long>,FireCustomRepository { | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/moing/backend/domain/fire/domain/service/FireQueryService.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,28 @@ | ||
package com.moing.backend.domain.fire.domain.service; | ||
|
||
import com.moing.backend.domain.fire.domain.entity.Fire; | ||
import com.moing.backend.domain.fire.domain.repository.FireCustomRepository; | ||
import com.moing.backend.domain.fire.domain.repository.FireRepository; | ||
import com.moing.backend.domain.fire.exception.NotFoundFireException; | ||
import com.moing.backend.domain.fire.exception.NotFoundFireReceiversException; | ||
import com.moing.backend.domain.member.domain.entity.Member; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FireQueryService { | ||
|
||
private final FireRepository fireRepository; | ||
|
||
public boolean hasFireCreatedWithinOneHour(Long throwMemberId, Long receiveMemberId) { | ||
return fireRepository.hasFireCreatedWithinOneHour(throwMemberId,receiveMemberId); | ||
} | ||
|
||
public List<Member> getNotYetMissionMember(Long teamId, Long missionId) { | ||
return fireRepository.getFireReceivers(teamId, missionId).orElseThrow(NotFoundFireReceiversException::new); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/moing/backend/domain/fire/domain/service/FireSaveService.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,20 @@ | ||
package com.moing.backend.domain.fire.domain.service; | ||
|
||
import com.moing.backend.domain.fire.domain.entity.Fire; | ||
import com.moing.backend.domain.fire.domain.repository.FireCustomRepository; | ||
import com.moing.backend.domain.fire.domain.repository.FireRepository; | ||
import com.moing.backend.global.annotation.DomainService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@DomainService | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class FireSaveService { | ||
|
||
private final FireRepository fireRepository; | ||
|
||
public Fire save(Fire fire) { | ||
return fireRepository.save(fire); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/moing/backend/domain/fire/exception/FireException.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,13 @@ | ||
package com.moing.backend.domain.fire.exception; | ||
|
||
import com.moing.backend.global.exception.ApplicationException; | ||
import com.moing.backend.global.response.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public abstract class FireException extends ApplicationException { | ||
|
||
protected FireException(ErrorCode errorCode, HttpStatus httpStatus) { | ||
super(errorCode, httpStatus); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/moing/backend/domain/fire/exception/NoAuthThrowFireException.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,12 @@ | ||
package com.moing.backend.domain.fire.exception; | ||
|
||
import com.moing.backend.global.response.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class NoAuthThrowFireException extends FireException { | ||
|
||
public NoAuthThrowFireException() { | ||
super(ErrorCode.NOT_AUTH_FIRE_THROW, | ||
HttpStatus.NOT_FOUND); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/moing/backend/domain/fire/exception/NotFoundFireException.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,12 @@ | ||
package com.moing.backend.domain.fire.exception; | ||
|
||
import com.moing.backend.global.response.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class NotFoundFireException extends FireException { | ||
|
||
public NotFoundFireException() { | ||
super(ErrorCode.NOT_FOUND_FIRE, | ||
HttpStatus.NOT_FOUND); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/moing/backend/domain/fire/exception/NotFoundFireReceiversException.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,12 @@ | ||
package com.moing.backend.domain.fire.exception; | ||
|
||
import com.moing.backend.global.response.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class NotFoundFireReceiversException extends FireException { | ||
|
||
public NotFoundFireReceiversException() { | ||
super(ErrorCode.NOT_FOUND_FIRE_RECEIVERS, | ||
HttpStatus.NOT_FOUND); | ||
} | ||
} |
Oops, something went wrong.