Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions src/main/java/org/hansung/zigma/domain/promise/entity/Promise.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ public void confirm() {
this.status = PromiseStatus.CONFIRMED;
}

public void proceed() {
if (this.status == PromiseStatus.PENDING) {
this.status = PromiseStatus.PROCEEDING;
}
}

public void pend() {
if (this.status == PromiseStatus.PROCEEDING) {
this.status = PromiseStatus.PENDING;
}
}

public void startRevote(LocalDateTime endAt) {
this.isMultipleVoting = false;
this.endAt = endAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public interface CandidateRepository extends JpaRepository<Candidate, Long> {
List<Candidate> findAllByPromiseIdAndIsActiveTrue(Long promiseId);

Optional<Candidate> findByIdAndPromiseId(Long candidateId, Long promiseId);

long countByPromiseId(Long promiseId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

재투표 등으로 인해 비활성화된(inactive) 후보지가 남아있는 경우에도, 활성 후보지가 없다면 약속 상태를 '장소 미정(PENDING)'으로 전환하는 것이 비즈니스 로직상 더 적절합니다. 따라서 단순히 전체 개수를 세는 countByPromiseId 대신 활성 상태인 후보지만 카운트하는 메서드를 사용하는 것을 권장합니다.

Suggested change
long countByPromiseId(Long promiseId);
long countByPromiseIdAndIsActiveTrue(Long promiseId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public CandidateRes createCandidate(Long userId, Long promiseId, CandidateCreate
);
Candidate savedCandidate = candidateRepository.save(candidate);

// 첫 후보지가 등록되면 약속 상태를 진행 중으로 전환
pm.getPromise().proceed();

return CandidateRes.of(savedCandidate, userId);
}

Expand Down Expand Up @@ -106,6 +109,11 @@ public void deleteCandidate(Long userId, Long promiseId, Long candidateId) {
}

candidateRepository.delete(candidate);

// 마지막 후보지 삭제 시 약속 상태를 다시 장소 미정으로 되돌림
if (candidateRepository.countByPromiseId(promiseId) == 0) {
Comment on lines +113 to +114

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

비활성화된 후보지가 존재하더라도 활성화된 후보지가 모두 삭제되었다면 약속 상태를 '장소 미정(PENDING)'으로 되돌려야 합니다. 앞서 CandidateRepository에 제안한 countByPromiseIdAndIsActiveTrue 메서드를 사용하여 활성 후보지 존재 여부를 체크하도록 수정하는 것이 좋습니다.

Suggested change
// 마지막 후보지 삭제 시 약속 상태를 다시 장소 미정으로 되돌림
if (candidateRepository.countByPromiseId(promiseId) == 0) {
// 마지막 활성 후보지 삭제 시 약속 상태를 다시 장소 미정으로 되돌림
if (candidateRepository.countByPromiseIdAndIsActiveTrue(promiseId) == 0) {

candidate.getPromise().pend();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
Expand All @@ -29,6 +30,7 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.cors(Customizer.withDefaults())
.csrf(csrf -> csrf.disable()) // CSRF 비활성화
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // 세션 비활성화
.authorizeHttpRequests(auth -> auth
Expand Down
Loading