Skip to content

Commit

Permalink
Merge pull request #8 from KAKAO-TOUR-API-CONTEST/develop
Browse files Browse the repository at this point in the history
 FEAT : detailList, mainList, listFiltering, searchByKeyword, searchB…
  • Loading branch information
femmefatalehaein authored Aug 16, 2024
2 parents c3518ea + 2ad92e5 commit efbef0f
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 148 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
package com.example.ai_jeju.controller;

import com.example.ai_jeju.domain.Restaurant;
import com.example.ai_jeju.domain.Stay;
import com.example.ai_jeju.domain.Store;
import com.example.ai_jeju.service.MainVIewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/api")
public class MainViewController {

@Autowired
private MainVIewService mainViewService;

@GetMapping("/restaurant/detailList")
public Restaurant getUserById(@RequestParam int restaurantId) {
return mainViewService.getRestaurantList(restaurantId);
@GetMapping("/detailList")
public Optional<Store> getUserById(@RequestParam Long storeId) {
return mainViewService.getDetailList(storeId);
}

@GetMapping("/mainList")
public List<Store> getMainLInst() {
return mainViewService.getMainList();
}

@GetMapping("/mainList/filters")
public List<Store> getListByCategory(@RequestParam int categoryId){
return mainViewService.getListByCategory(categoryId);
}

@GetMapping("/searchList")
public List<Store> getListBySearch(@RequestParam String keyword){
return mainViewService.getListBySearch(keyword);
}

@GetMapping("/searchList/filters")
public List<Store> searchByCategory(@RequestParam String keyword, @RequestParam int categoryId){
return mainViewService.searchByCategory(keyword,categoryId);
}


Expand Down
35 changes: 19 additions & 16 deletions src/main/java/com/example/ai_jeju/controller/MyPageController.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.example.ai_jeju.controller;

import com.example.ai_jeju.domain.User;
import com.example.ai_jeju.dto.MyPageResponse;
import com.example.ai_jeju.service.MyPageService;
import com.example.ai_jeju.service.S3Service;
import com.example.ai_jeju.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -18,18 +20,28 @@ public class MyPageController {

@Autowired
private MyPageService myPageService;

@Autowired
private UserService userService;

@Autowired
private S3Service s3Service;

//마이페이지 회원 1명씩 조회

// @GetMapping("/mypage")
// public ResponseEntity<User> getUserById(@RequestParam Long userId) {
// Optional<User> user = myPageService.getUserById(userId);
// if (user.isPresent()) {
// return ResponseEntity.ok(user.get());
// } else {
// return ResponseEntity.notFound().build();
// }
// }

@GetMapping("/mypage")
public ResponseEntity<User> getUserById(@RequestParam Long userId) {
Optional<User> user = myPageService.getUserById(userId);
if (user.isPresent()) {
return ResponseEntity.ok(user.get());
} else {
return ResponseEntity.notFound().build();
}
public MyPageResponse myPage(@RequestParam Long userId){
return userService.getMyPage(userId);
}

@PutMapping("/mypage/nickname")
Expand All @@ -48,13 +60,6 @@ public ResponseEntity<String> updateProfileImage(@RequestParam Long userId, @Req
return ResponseEntity.ok("success");
}

/*
@DeleteMapping("/mypage/snsprofile")
public ResponseEntity<String> deleteSnsProfile(@RequestParam Long id) {
myPageService.deleteSnsProfile(id);
return ResponseEntity.ok("deleted");
}*/

@DeleteMapping("/mypage/profileimg")
public ResponseEntity<String> deleteProfileImage(@RequestParam Long userId) {
myPageService.deleteProfileImage(userId);
Expand All @@ -68,6 +73,4 @@ public ResponseEntity<String> createPresignedUrl(@RequestBody Map<String, String
return ResponseEntity.ok(presignedUrl);
}



}
13 changes: 1 addition & 12 deletions src/main/java/com/example/ai_jeju/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import java.io.IOException;


@RestController
@RequestMapping("/api/users")
public class UserController {
Expand All @@ -28,26 +27,16 @@ public class UserController {
public Long registerUser(@RequestBody SignUpRequest signUpRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
return userService.registerUser(signUpRequest,request,response);
}

@GetMapping("/checks")
public Long CheckIfUser(@RequestParam String email, HttpServletRequest request, HttpServletResponse response){
return userService.checkIfUser(email,request,response);
}

@GetMapping("/mypage")
public MyPageResponse myPage(@RequestParam Long userId){
return userService.getMyPage(userId);
}

// @GetMapping("/RandomList")
// public Object GetRandomList(){
// return userService.getRandomList();
// }

//탈퇴하기
@GetMapping("/withdraw")
public ResponseEntity<String> signOut(@RequestBody WithdrawRequest withdrawRequest) {
String response = userService.withDraw(withdrawRequest);

return ResponseEntity.ok(response);
}

Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/example/ai_jeju/domain/Child.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@ public class Child {

@Column
private Long userId;

@Column
private String birthDate;

@Column
private String childName;

@Column
private Boolean gender;

@Column
private String realtion;

@Column
private long childProfile;
}
28 changes: 14 additions & 14 deletions src/main/java/com/example/ai_jeju/domain/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ public class Store {
String name;

//이미지 소스
@Column(name = "imgSrc",updatable = false)
boolean imgSrc;
@Column(name = "imgSrc",updatable = false,nullable = true)
String imgSrc;

@Column(name = "address",updatable = false)
@Column(name = "address",updatable = false,nullable = true)
String address;


@Column(name = "mapX",updatable = false)
@Column(name = "mapX",updatable = false,nullable = true)
double mapX;

@Column(name = "mapY",updatable = false)
@Column(name = "mapY",updatable = false,nullable = true)
double mapY;


Expand All @@ -45,32 +45,32 @@ public class Store {
*/

//유모차 대여여부
@Column(name = "stroller",updatable = false)
@Column(name = "stroller",updatable = false,nullable = true)
boolean stroller;

//유모차 편의성
@Column(name = "strollerVal",updatable = false)
int strollerVal;
@Column(name = "strollerVal",updatable = false,nullable = true)
boolean strollerVal;

//아이 스페어 체어
@Column(name = "babySpareChair",updatable = false)
@Column(name = "babySpareChair",updatable = false,nullable = true)
boolean babySpareChair;

//아이 놀이방
@Column(name = "playground",updatable = false)
@Column(name = "playground",updatable = false,nullable = true)
boolean playground;

//노키즈존 여부
@Column(name = "noKidsZone",updatable = false)
@Column(name = "noKidsZone",updatable = false,nullable = true)
boolean noKidsZone;

@Column(name = "categoryId",updatable = false)
@Column(name = "categoryId",updatable = false,nullable = true)
int categoryId;

@Column(name = "operationTime",updatable = false)
@Column(name = "operationTime",updatable = false,nullable = true)
String operationTime;

@Column(name = "tel",updatable = false)
@Column(name = "tel",updatable = false,nullable = true)
String tel;

}
4 changes: 1 addition & 3 deletions src/main/java/com/example/ai_jeju/dto/MyPageResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
@NoArgsConstructor
public class MyPageResponse {



private String email;
private String name;
private String nickname;
private String profileImg;
private String rgtDate;
private String phoneNum;

private int numOfChilds;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ public interface ChildRepository extends JpaRepository<Child, Long> {
@Query("SELECT c FROM Child c WHERE c.userId = :userId")
List<Child> findAllById(@Param("userId") Long userId);


}
12 changes: 12 additions & 0 deletions src/main/java/com/example/ai_jeju/repository/StoreRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
import com.example.ai_jeju.domain.Store;
import com.example.ai_jeju.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

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

@Repository
public interface StoreRepository extends JpaRepository<Store, Long> {
Optional<Store> findById(Long id);
List<Store> findByCategoryId(int categoryId);
@Query(value = "SELECT * FROM stores ORDER BY RAND()", nativeQuery = true)
List<Store> findAllOrderByRandomNative();

@Query(value = "SELECT * FROM stores WHERE name LIKE %:keyword%", nativeQuery = true)
List<Store> findBySearch(String keyword);

@Query(value = "SELECT * FROM stores WHERE name LIKE %:keyword% AND categoryId = :categoryId", nativeQuery = true)
List<Store> findByKeywordAndCategoryId(String keyword, int categoryId);

}
33 changes: 24 additions & 9 deletions src/main/java/com/example/ai_jeju/service/MainVIewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,46 @@

import com.example.ai_jeju.domain.Restaurant;
import com.example.ai_jeju.domain.Stay;
import com.example.ai_jeju.domain.Store;
import com.example.ai_jeju.repository.RestaurantRepository;
import com.example.ai_jeju.repository.StayRepository;
import com.example.ai_jeju.repository.StoreRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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


@Service
public class MainVIewService {

@Autowired
private RestaurantRepository restaurantRepository;
@Autowired
private StayRepository stayRepository;
private StoreRepository storeRepository;


public Restaurant getRestaurantList(int restaruantId){
return restaurantRepository.findByRestarauntId(restaruantId)
.orElseThrow(
()-> new IllegalArgumentException("unexpected restaurant"));
public Optional<Store> getDetailList(Long storeId){
return storeRepository.findById(storeId);
}

public Stay getStayList(int stayId){
return stayRepository.findByStayId(stayId)
.orElseThrow(
()-> new IllegalArgumentException("unexpected stay"));
public List<Store> getMainList(){
return storeRepository.findAllOrderByRandomNative();
}

public List<Store>getListByCategory(int categoryId){
return storeRepository.findByCategoryId(categoryId);
}

public List<Store>getListBySearch(String keyword){
return storeRepository.findBySearch(keyword);
}

public List<Store>searchByCategory(String keyword, int categoryId){
return storeRepository.findByKeywordAndCategoryId(keyword,categoryId);
}



}
Loading

0 comments on commit efbef0f

Please sign in to comment.