Skip to content

Commit

Permalink
Merge pull request #1 from KAKAO-TOUR-API-CONTEST/develop
Browse files Browse the repository at this point in the history
숙박, 식당 상세정보 조회
  • Loading branch information
femmefatalehaein authored Jul 22, 2024
2 parents b31ecbe + 48b007a commit 97e4cee
Show file tree
Hide file tree
Showing 18 changed files with 501 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +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.service.MainVIewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

@Autowired
private MainVIewService mainViewService;

/*
@GetMapping("/mainList")
public ResponseEntity<String> signOut(@RequestBody WithdrawRequest withdrawRequest) {
String response = userService.withDraw(withdrawRequest);
return ResponseEntity.ok(response);
}*/

/*
@GetMapping("/mainList")
public User getUserById(@PathVariable Long id) {
return userService.getUserById(id);
}
*/

@GetMapping("/restaurant/detailList")
public Restaurant getUserById(@RequestParam int restaurantId) {
return mainViewService.getRestaurantList(restaurantId);
}


@GetMapping("/stay/detailList")
public Stay getStayById(@RequestParam int stayId) {
return mainViewService.getStayList(stayId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.ai_jeju.controller;

public class PhotoBookController {


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

//HTTP 요청을 처리하는 Controller 클래스
@RestController
@RequestMapping("/api")
Expand All @@ -16,8 +18,9 @@ public class UserController {
private UserService userService;

//회원가입
/*여기 확인해보자*/
@PostMapping("/signup")
public ResponseEntity<String> signUp(@RequestBody SignUpRequest signUpRequest) {
public ResponseEntity<String> signUp(@RequestBody SignUpRequest signUpRequest) throws IOException {
String response = userService.signUp(signUpRequest);
//System.out.println(response);
return ResponseEntity.ok(response);
Expand All @@ -29,7 +32,7 @@ public ResponseEntity<String> signUp(@RequestBody SignUpRequest signUpRequest) {
@GetMapping("/withdraw")
public ResponseEntity<String> signOut(@RequestBody WithdrawRequest withdrawRequest) {
String response = userService.withDraw(withdrawRequest);
System.out.println(response);

return ResponseEntity.ok(response);
}

Expand Down
36 changes: 36 additions & 0 deletions src/main/java/com/example/ai_jeju/domain/Child.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.example.ai_jeju.domain;

import jakarta.persistence.*;
import lombok.*;

import java.sql.Date;

@Table(name="child")
@NoArgsConstructor(access= AccessLevel.PROTECTED) //기본생성자
@Getter
@Entity
@AllArgsConstructor // 모든 필드를 초기화하는 생성자
@Builder // 빌더 패턴
public class Child {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "child_id", updatable = false, unique = true)
private Long childId;

@Column
private Long userId;

@Column
private Date birthDate;

@Column
private String childName;

@Column
private Boolean gender;

@Column
private long childProfile;

}
15 changes: 14 additions & 1 deletion src/main/java/com/example/ai_jeju/domain/RefreshToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ public class RefreshToken {
String refresh_token;

@Column
String user_id;
private Long userId;


//생성자
public RefreshToken(Long userId, String refreshToken){
this.userId = userId;
this.refresh_token = refreshToken;
}

//update 메서드
public RefreshToken update(String newRefreshToken){
this.refresh_token = newRefreshToken;
return this;
}


}
47 changes: 47 additions & 0 deletions src/main/java/com/example/ai_jeju/domain/Restaurant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.ai_jeju.domain;


import jakarta.persistence.*;
import lombok.*;

@Table(name="restaurant")
@NoArgsConstructor(access= AccessLevel.PROTECTED) //기본생성자
@Getter
@Entity
@AllArgsConstructor // 모든 필드를 초기화하는 생성자
@Builder // 빌더 패턴
public class Restaurant {


@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "restaraunt_id", updatable = false, unique = true)
int restarauntId;


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

@Column(name = "latitude", updatable = false, unique = true)
double latitude;

@Column(name = "longitude", updatable = false, unique = true)
double longitude;

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

@Column(name = "chair", updatable = false, unique = true)
int chair;

@Column(name = "palyground", updatable = false, unique = true)
int playground;

@Column(name = "stroller", updatable = false, unique = true)
int stroller;

@Column(name = "operation_time", updatable = false, unique = true)
int operationTime;


}
41 changes: 41 additions & 0 deletions src/main/java/com/example/ai_jeju/domain/Stay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.example.ai_jeju.domain;

import jakarta.persistence.*;
import lombok.*;

@Table(name="stay")
@NoArgsConstructor(access= AccessLevel.PROTECTED) //기본생성자
@Getter
@Entity
@AllArgsConstructor // 모든 필드를 초기화하는 생성자
@Builder // 빌더 패턴
public class Stay {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "stay_id", updatable = false, unique = true)
int stayId;

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

@Column(name = "latitude", updatable = false, unique = true)
double latitude;

@Column(name = "longitude", updatable = false, unique = true)
double longitude;

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

@Column(name = "bed_forchild", updatable = false, unique = true)
int chair;

@Column(name = "stroller", updatable = false, unique = true)
int stroller;

@Column(name = "operation_time", updatable = false, unique = true)
int operationTime;


}
5 changes: 5 additions & 0 deletions src/main/java/com/example/ai_jeju/dto/SignUpRequest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.example.ai_jeju.dto;

import com.example.ai_jeju.domain.Child;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class SignUpRequest {
Expand All @@ -12,5 +15,7 @@ public class SignUpRequest {
private String email;
private String profile;
private String provider;
//함께 보낼 동반 아동에 대한 정보 -> 여러명일 수도 있으므로 배열 형식으로 받는다.
private List<Child> child;

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ public class NickNameGenerator {
private String nickname;
List<String> adjective = Arrays.asList("행복한","쓸쓸한","따뜻한","작은","큰","맛있는","달콤한","어려운","재미있는"
,"훌륭한","잘생긴","예쁜","귀여운","매력적인","편리한","친절한","순수한","청결한","상냥한","예의바른","높은","먼","정직한","성실한","공정한");
List<String> familyName = Arrays.asList("행복한","쓸쓸한","따뜻한","작은","큰","맛있는","달콤한","어려운","재미있는"
,"훌륭한","잘생긴","예쁜","귀여운","매력적인","편리한","친절한","순수한","청결한","상냥한","예의바른","높은","먼","정직한","성실한","공정한");
public NickNameGenerator(){

String number = (int)(Math.random() * 99)+1 +"";

Collections.shuffle(adjective);
String name = "맘";
Collections.shuffle(familyName);

String adj = adjective.get(0);
this.nickname = adj+name+number;
String fName = familyName.get(0);
this.nickname = adj+fName+number;

}

Expand Down
93 changes: 93 additions & 0 deletions src/main/java/com/example/ai_jeju/handler/SignUpHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.example.ai_jeju.handler;

import com.example.ai_jeju.domain.Child;
import com.example.ai_jeju.domain.RefreshToken;
import com.example.ai_jeju.domain.User;
import com.example.ai_jeju.dto.SignUpRequest;
import com.example.ai_jeju.generator.NickNameGenerator;
import com.example.ai_jeju.jwt.TokenProvider;
import com.example.ai_jeju.repository.ChildRepository;
import com.example.ai_jeju.repository.RefreshTokenRepository;
import com.example.ai_jeju.repository.UserRepository;
import com.example.ai_jeju.util.CookieUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;

import java.io.IOException;
import java.time.Duration;
import java.util.List;

import static com.example.ai_jeju.util.CookieUtil.addCookie;


@AllArgsConstructor
public class SignUpHandler {
public static final String REFRESH_TOKEN_COOKIE_NAME = "refresh_token";
public static final Duration REFRESH_TOKEN_DURATION = Duration.ofDays(14);
public static final Duration ACCESS_TOKEN_DURATION = Duration.ofDays(1);

HttpServletResponse response;


UserRepository userRepository;
RefreshTokenRepository refreshTokenRepository;
TokenProvider tokenProvider;
CookieUtil cookieUtil;
ChildRepository childRepository;

public String successHadler(SignUpRequest signUpRequest) throws IOException {

String nick = signUpRequest.getNickname();
if(nick==null){
nick = new NickNameGenerator().getNickname();
}

// Save new user using builder pattern
User newUser = User.builder()
.name(signUpRequest.getName())
.nickname(nick)
.provider(signUpRequest.getProvider())
.email(signUpRequest.getEmail())
.profile(signUpRequest.getProfile())
.provider(signUpRequest.getProvider())
.build();


String accessToken = tokenProvider.generateToken(newUser, REFRESH_TOKEN_DURATION);
/*-------------------------------------------*/
//동반아동
List<Child> childList = signUpRequest.getChild();
for(int i=0; i<childList.size(); i++){
Child child = Child.builder()
.userId(newUser.getId())
.childName(childList.get(i).getChildName())
.birthDate(childList.get(i).getBirthDate())
.gender(childList.get(i).getGender())
.build();
childRepository.save(child);
}

userRepository.save(newUser);

String refresh_token = tokenProvider.generateToken(newUser, REFRESH_TOKEN_DURATION);
RefreshToken refreshToken = RefreshToken.builder()
.refresh_token(refresh_token)
.userId(newUser.getId()).build();

refreshTokenRepository.save(refreshToken);

userRepository.save(newUser);

int cookieMaxAge = (int) REFRESH_TOKEN_DURATION.toSeconds();

CookieUtil.addCookie(response, REFRESH_TOKEN_COOKIE_NAME, refresh_token, cookieMaxAge);

return accessToken;
}



}
13 changes: 13 additions & 0 deletions src/main/java/com/example/ai_jeju/repository/ChildRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.ai_jeju.repository;


import com.example.ai_jeju.domain.Child;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ChildRepository extends JpaRepository<Child, Long> {



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.ai_jeju.repository;

import com.example.ai_jeju.domain.Restaurant;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface MainListRepository extends JpaRepository<Restaurant, Long> {
Optional<Restaurant> findByRestarauntId(int restaurantId);

}

Loading

0 comments on commit 97e4cee

Please sign in to comment.