Skip to content

Commit e72b832

Browse files
committed
Merge branch 'feat#61-search-api' of https://github.com/swyp-app-team-4/boombim-backend-api into dev
2 parents b80b3a7 + 5267805 commit e72b832

19 files changed

Lines changed: 572 additions & 17 deletions

File tree

src/main/java/boombimapi/domain/congestion/repository/MemberCongestionRepository.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import boombimapi.domain.congestion.entity.MemberCongestion;
44
import java.time.LocalDateTime;
5+
import java.util.List;
56
import java.util.Optional;
67

7-
import feign.Param;
8+
import boombimapi.domain.place.entity.MemberPlace;
9+
import org.springframework.data.repository.query.Param;
10+
import org.springframework.data.domain.Pageable;
11+
812
import org.springframework.data.domain.Pageable;
913
import org.springframework.data.domain.Slice;
1014
import org.springframework.data.jpa.repository.JpaRepository;
@@ -23,13 +27,17 @@ Optional<MemberCongestion> findFirstByMemberPlaceIdAndExpiresAtAfterOrderByCreat
2327
);
2428

2529
@Query("""
26-
SELECT COUNT(mc)
27-
FROM MemberCongestion mc
28-
WHERE mc.memberPlace.id = :placeId
29-
AND CAST(mc.createdAt AS DATE) = CURRENT_DATE
30-
""")
30+
SELECT COUNT(mc)
31+
FROM MemberCongestion mc
32+
WHERE mc.memberPlace.id = :placeId
33+
AND CAST(mc.createdAt AS DATE) = CURRENT_DATE
34+
""")
3135
long countTodayByPlace(@Param("placeId") Long placeId);
3236

37+
38+
Optional<MemberCongestion> findTop1ByMemberPlaceIdOrderByCreatedAtDesc(Long placeId);
39+
40+
3341
Slice<MemberCongestion> findByMemberPlaceIdOrderByIdDesc(
3442
Long memberPlaceId,
3543
Pageable pageable

src/main/java/boombimapi/domain/congestion/repository/OfficialCongestionRepository.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package boombimapi.domain.congestion.repository;
22

33
import boombimapi.domain.congestion.entity.OfficialCongestion;
4+
5+
import java.util.List;
46
import java.util.Optional;
7+
8+
import boombimapi.domain.place.entity.OfficialPlace;
9+
import org.springframework.data.repository.query.Param;
10+
import org.springframework.data.domain.Pageable;
511
import org.springframework.data.jpa.repository.JpaRepository;
12+
import org.springframework.data.jpa.repository.Query;
613

714
public interface OfficialCongestionRepository extends JpaRepository<OfficialCongestion, Long> {
815

@@ -11,4 +18,8 @@ Optional<OfficialCongestion> findTopByOfficialPlaceIdOrderByObservedAtDesc(
1118
Long officialPlaceId
1219
);
1320

21+
22+
23+
24+
1425
}

src/main/java/boombimapi/domain/member/domain/entity/Member.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import boombimapi.domain.alarm.domain.entity.fcm.FcmToken;
66
import boombimapi.domain.congestion.entity.MemberCongestion;
77
import boombimapi.domain.oauth2.domain.entity.SocialProvider;
8+
import boombimapi.domain.search.domain.entity.Search;
89
import boombimapi.domain.vote.domain.entity.Vote;
910
import boombimapi.domain.vote.domain.entity.VoteAnswer;
1011
import boombimapi.domain.vote.domain.entity.VoteDuplication;
@@ -54,9 +55,14 @@ public class Member {
5455
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true)
5556
private List<VoteAnswer> voteAnswers = new ArrayList<>();
5657

58+
// 7) 혼잡도 멤버들
5759
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true)
5860
private List<MemberCongestion> memberCongestions = new ArrayList<>();
5961

62+
// 7) 혼잡도 멤버들
63+
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true)
64+
private List<Search> searchs = new ArrayList<>();
65+
6066
@Column(nullable = false)
6167
private String email;
6268

@@ -86,12 +92,12 @@ public class Member {
8692
private boolean alarmFlag;
8793

8894
// 첫 로그인일시에는 false 이후에는 계속 true
89-
@Column(name= "name_flag", nullable = false)
95+
@Column(name = "name_flag", nullable = false)
9096
private boolean nameFlag;
9197

9298
@Builder
9399
public Member(String id, String email, String name, String profile,
94-
SocialProvider socialProvider, Role role) {
100+
SocialProvider socialProvider, Role role) {
95101
this.id = id;
96102
this.email = email;
97103
this.name = name;
@@ -107,20 +113,27 @@ public void updateEmail(String email) {
107113
}
108114

109115
public void updateName(String name) {
110-
this.name=name;
116+
this.name = name;
111117
}
112118

113-
public void updateProfile(String profile){this.profile= profile;}
119+
public void updateProfile(String profile) {
120+
this.profile = profile;
121+
}
114122

115123
public void updateIsActivateNameFlag() {
116-
this.nameFlag=true;
124+
this.nameFlag = true;
117125
}
118126

119127
public void updateIsActivateAlarmFlag() {
120-
this.alarmFlag=true;
128+
this.alarmFlag = true;
121129
}
130+
122131
public void updateIsDeactivateAlarmFlag() {
123-
this.alarmFlag=false;
132+
this.alarmFlag = false;
133+
}
134+
135+
public void setPassword(String password) {
136+
this.password = password;
124137
}
125138

126139
@PrePersist

src/main/java/boombimapi/domain/member/presentation/controller/AdminController.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package boombimapi.domain.member.presentation.controller;
22

33
import boombimapi.domain.member.application.service.AdminService;
4+
import boombimapi.domain.member.domain.entity.Member;
5+
import boombimapi.domain.member.domain.entity.Role;
6+
import boombimapi.domain.member.domain.repository.MemberRepository;
47
import boombimapi.domain.member.presentation.dto.admin.req.AdminLoginReq;
8+
import boombimapi.domain.oauth2.domain.entity.SocialProvider;
59
import boombimapi.domain.oauth2.presentation.dto.res.LoginToken;
610
import io.swagger.v3.oas.annotations.Operation;
711
import io.swagger.v3.oas.annotations.responses.ApiResponse;
@@ -11,8 +15,12 @@
1115
import lombok.RequiredArgsConstructor;
1216
import lombok.extern.slf4j.Slf4j;
1317
import org.springframework.http.ResponseEntity;
18+
import org.springframework.security.crypto.password.PasswordEncoder;
1419
import org.springframework.web.bind.annotation.*;
1520

21+
import java.util.UUID;
22+
23+
1624
@RestController
1725
@RequestMapping("/api/admin")
1826
@RequiredArgsConstructor
@@ -21,8 +29,10 @@
2129
public class AdminController {
2230

2331
private final AdminService adminService;
32+
private final MemberRepository memberRepository;
33+
private final PasswordEncoder passwordEncoder;
2434

25-
@Operation(summary = "[관리자 전용] 일반 로그인", description = "이메일과 비밀번호로 관리자 로그인을 처리합니다.")
35+
@Operation(summary = "관리자 일반 로그인", description = "이메일과 비밀번호로 관리자 로그인을 처리합니다.")
2636
@ApiResponses(value = {
2737
@ApiResponse(responseCode = "200", description = "로그인 성공"),
2838
@ApiResponse(responseCode = "401", description = "인증 실패 (이메일 또는 비밀번호 불일치)"),
@@ -33,4 +43,23 @@ public ResponseEntity<LoginToken> adminLogin(@Valid @RequestBody AdminLoginReq r
3343
LoginToken loginToken = adminService.postLogin(req);
3444
return ResponseEntity.ok(loginToken);
3545
}
46+
47+
48+
@PostMapping("/join")
49+
public void adminJoin(@Valid @RequestBody AdminLoginReq req) {
50+
Member admin = Member.builder()
51+
.id(UUID.randomUUID().toString())
52+
.email(req.loginId())
53+
.name("관리자") // 기본 이름
54+
.profile(null)
55+
.socialProvider(SocialProvider.KAKAO) // 고정
56+
.role(Role.ADMIN) // 관리자 권한
57+
.build();
58+
59+
// 비밀번호 encode 해서 세팅
60+
admin.setPassword(passwordEncoder.encode(req.password()));
61+
62+
// 저장
63+
memberRepository.save(admin);
64+
}
3665
}

src/main/java/boombimapi/domain/place/repository/MemberPlaceRepository.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
import boombimapi.domain.place.entity.MemberPlace;
44
import java.util.List;
55
import java.util.Optional;
6+
7+
import boombimapi.domain.search.presentation.dto.PlaceNameProjection;
8+
import org.springframework.data.repository.query.Param;
9+
import org.springframework.data.domain.Page;
10+
import org.springframework.data.domain.Pageable;
611
import org.springframework.data.jpa.repository.JpaRepository;
12+
import org.springframework.data.jpa.repository.Query;
713

814
public interface MemberPlaceRepository extends JpaRepository<MemberPlace, Long> {
915

@@ -15,4 +21,21 @@ List<MemberPlace> findByLatitudeBetweenAndLongitudeBetween(
1521
double minLongitude,
1622
double maxLongitude
1723
);
24+
25+
// 연관 검색
26+
@Query("""
27+
select p.name as name
28+
from MemberPlace p
29+
where lower(p.name) like lower(concat('%', ?1, '%'))
30+
order by lower(p.name) asc
31+
""")
32+
List<PlaceNameProjection> searchByName(String keyword, Pageable pageable);
33+
34+
35+
36+
// 검색 결과
37+
List<MemberPlace> findEntitiesByNameContainingIgnoreCase(String keyword, Pageable pageable);
38+
39+
40+
1841
}

src/main/java/boombimapi/domain/place/repository/OfficialPlaceRepository.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import boombimapi.domain.place.entity.OfficialPlace;
44
import java.util.List;
5+
6+
import boombimapi.domain.search.presentation.dto.PlaceNameProjection;
7+
import org.springframework.data.repository.query.Param;
8+
import org.springframework.data.domain.Pageable;
59
import org.springframework.data.jpa.repository.JpaRepository;
10+
import org.springframework.data.jpa.repository.Query;
611

712
public interface OfficialPlaceRepository extends JpaRepository<OfficialPlace, Long> {
813

@@ -14,4 +19,15 @@ List<OfficialPlace> findByCentroidLatitudeBetweenAndCentroidLongitudeBetween(
1419
double maxLongitude
1520
);
1621

22+
// 연관 검색
23+
@Query("""
24+
select o.name as name
25+
from OfficialPlace o
26+
where lower(o.name) like lower(concat('%', ?1, '%'))
27+
order by lower(o.name) asc
28+
""")
29+
List<PlaceNameProjection> searchByName(String keyword, Pageable pageable);
30+
31+
// 검색 결과
32+
List<OfficialPlace> findEntitiesByNameContainingIgnoreCase(String keyword, Pageable pageable);
1733
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package boombimapi.domain.search.application;
2+
3+
import boombimapi.domain.search.presentation.dto.res.SearchHistoryRes;
4+
import boombimapi.domain.search.presentation.dto.res.SearchRelatedRes;
5+
import boombimapi.domain.search.presentation.dto.res.SearchRes;
6+
7+
import java.util.List;
8+
9+
public interface SearchService {
10+
11+
// 최근 검색 내역 10개 조회
12+
List<SearchHistoryRes> getSearchHistory(String userId);
13+
14+
// 연관 검색어 조회
15+
List<SearchRelatedRes> getSearchRelated(String posName);
16+
17+
18+
// 검색 결과 조회 및 검색 내역 저장
19+
List<SearchRes> getSearch(String posName, String userId);
20+
21+
// 개인 삭제
22+
void deletePersonal(Long searchId, String userId);
23+
24+
// 전체 삭제
25+
void deleteAll(String userId);
26+
}

0 commit comments

Comments
 (0)