From de53781cef20323ded2ed7583f03b3b0a0c8dab1 Mon Sep 17 00:00:00 2001 From: Arata Date: Wed, 24 Jul 2024 18:39:22 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A7=94=E5=93=A1=E9=96=8B=E5=82=AC?= =?UTF-8?q?=E4=BC=81=E7=94=BB=E3=81=8C=E5=AF=BE=E8=B1=A1=E3=81=A7=E3=81=AA?= =?UTF-8?q?=E3=81=84=E7=94=B3=E8=AB=8B=E3=81=AF=E3=80=81=E5=A7=94=E5=93=A1?= =?UTF-8?q?=E9=96=8B=E5=82=AC=E4=BC=81=E7=94=BB=E3=81=AB=E9=80=81=E4=BF=A1?= =?UTF-8?q?=E3=81=97=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/sos24-domain/src/entity/project.rs | 36 ++++++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/crates/sos24-domain/src/entity/project.rs b/crates/sos24-domain/src/entity/project.rs index 0140b2ab..4e0f9731 100644 --- a/crates/sos24-domain/src/entity/project.rs +++ b/crates/sos24-domain/src/entity/project.rs @@ -407,7 +407,13 @@ bitflags! { impl ProjectAttributes { pub fn matches(self, attributes: ProjectAttributes) -> bool { - attributes.intersects(self) + if self.contains(Self::OFFICIAL) { + // フィルターに委員会開催企画が含まれている場合はORで判定する + attributes.intersects(self) + } else { + // フィルターに委員会開催企画が含まれていない場合はORで判定し、かつ、委員会開催企画が含まれていない企画のみを対象とする + attributes.intersects(self) && !attributes.contains(Self::OFFICIAL) + } } } @@ -499,23 +505,37 @@ mod tests { #[test] fn match_project_attributes() { let filter_attributes = ProjectAttributes::ACADEMIC | ProjectAttributes::INSIDE; - for attributes in ProjectAttributes::all().iter() { - if attributes.contains(ProjectAttributes::ACADEMIC) - || attributes.contains(ProjectAttributes::INSIDE) + for attributes_bits in 0..ProjectAttributes::all().bits() { + let attributes = ProjectAttributes::from_bits(attributes_bits).unwrap(); + if !attributes.contains(ProjectAttributes::OFFICIAL) + && (attributes.contains(ProjectAttributes::ACADEMIC) + || attributes.contains(ProjectAttributes::INSIDE)) { assert!(filter_attributes.matches(attributes)); } else { assert!(!filter_attributes.matches(attributes)); } } + + let filter_attributes = ProjectAttributes::OFFICIAL; + assert!(filter_attributes.matches(ProjectAttributes::OFFICIAL)); + assert!( + filter_attributes.matches(ProjectAttributes::OFFICIAL | ProjectAttributes::ACADEMIC) + ); } #[test] fn not_match_project_attributes() { - let attributes = ProjectAttributes::empty(); - assert!(!attributes.matches(ProjectAttributes::ACADEMIC)); + let filter_attributes = ProjectAttributes::empty(); + assert!(!filter_attributes.matches(ProjectAttributes::ACADEMIC)); + + let filter_attributes = ProjectAttributes::ACADEMIC | ProjectAttributes::INSIDE; + assert!(!filter_attributes.matches(ProjectAttributes::OUTSIDE)); - let attributes = ProjectAttributes::ACADEMIC | ProjectAttributes::INSIDE; - assert!(!attributes.matches(ProjectAttributes::OUTSIDE)); + let filter_attributes = ProjectAttributes::ACADEMIC; + assert!(!filter_attributes.matches(ProjectAttributes::OFFICIAL)); + assert!( + !filter_attributes.matches(ProjectAttributes::OFFICIAL | ProjectAttributes::ACADEMIC) + ); } }