Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init: 제품 추천 조회 초기 구현 #3

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions application.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
gitspring.application.name=yessir
spring.application.name=yessir

# Google OAuth2 settings
spring.security.oauth2.client.registration.google.client-id=722806291043-dd66qtm2niho4o4kdraeuisi8qj0q3.apps.googleusercontent.com
spring.security.oauth2.client.registration.google.client-secret=G0CSPX-FY2pqQbeE_YP2ilAXtVvSY5YX7
spring.security.oauth2.client.registration.google.redirect-uri=http://localhost:8080/login/oauth2/code/google
spring.security.oauth2.client.registration.google.redirect-uri=https://api.yessir.site/login/oauth2/code/google

# JWT settings
jwt.secret-key=JDSFHJ435kjh43i5y9348urdfskjdhf9832ur4fsdjfhskdjfh3498r
Expand All @@ -13,11 +13,17 @@ jwt.expire-length=3600000
url.access-token=https://oauth2.googleapis.com/token
url.profile=https://www.googleapis.com/userinfo/v2/me

# db ??
# Database settings
spring.datasource.url=jdbc:mysql://localhost:3306/yessir_db
spring.datasource.username=yessir_user
spring.datasource.password=mk0702!!
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

# Base URL
app.base.url=https://api.yessir.site

spring.mvc.view.prefix=/templates/
spring.mvc.view.suffix=.html
24 changes: 24 additions & 0 deletions src/main/java/yes1sir/yessir/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package yes1sir.yessir;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((requests) -> requests
.requestMatchers("/api/**").permitAll() // /api/** 경로에 대한 접근 허용
.anyRequest().authenticated()
)
.csrf(csrf -> csrf.disable()); // CSRF 비활성화

return http.build();
}
}
12 changes: 12 additions & 0 deletions src/main/java/yes1sir/yessir/controller/HomeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package yes1sir.yessir.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeController {
@GetMapping("/")
public String index() {
return "index";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package yes1sir.yessir.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import yes1sir.yessir.dto.ProductResponseDTO;
import yes1sir.yessir.model.Product;
import yes1sir.yessir.model.SkinType;
import yes1sir.yessir.service.ProductService;
import yes1sir.yessir.service.SkinTypeService;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/recommendations")
public class RecommendationController {

private final SkinTypeService skinTypeService;
private final ProductService productService;

@Autowired
public RecommendationController(SkinTypeService skinTypeService, ProductService productService) {
this.skinTypeService = skinTypeService;
this.productService = productService;
}

@GetMapping("/{skinTypeName}")
public List<ProductResponseDTO> getRecommendationsBySkinType(@PathVariable String skinTypeName) {
Optional<SkinType> skinType = skinTypeService.getSkinTypeByTypeName(skinTypeName);
if (skinType.isPresent()) {
List<Product> products = productService.getProductsBySkinType(skinType.get());
return products.stream().map(product -> new ProductResponseDTO(
product.getProductName(),
product.getBrandName(),
product.getRecommendedType(),
product.getApplicableSkinTypes().stream()
.map(SkinType::getTypeName)
.collect(Collectors.joining(", ")),
product.getPrice().doubleValue(),
product.getPurpose(),
product.getImage()
)).collect(Collectors.toList());
} else {
return null; // 또는 적절한 에러 처리를 추가할 수 있습니다.
}
}
}
93 changes: 0 additions & 93 deletions src/main/java/yes1sir/yessir/controller/SkinTypeController.java

This file was deleted.

79 changes: 79 additions & 0 deletions src/main/java/yes1sir/yessir/dto/ProductResponseDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package yes1sir.yessir.dto;

public class ProductResponseDTO {
private String productName;
private String brandName;
private String recommendedType;
private String applicableTypes;
private double price;
private String purpose;
private String image;

public ProductResponseDTO(String productName, String brandName, String recommendedType, String applicableTypes, double price, String purpose, String image) {
this.productName = productName;
this.brandName = brandName;
this.recommendedType = recommendedType;
this.applicableTypes = applicableTypes;
this.price = price;
this.purpose = purpose;
this.image = image;
}

// Getters and setters

public String getProductName() {
return productName;
}

public void setProductName(String productName) {
this.productName = productName;
}

public String getBrandName() {
return brandName;
}

public void setBrandName(String brandName) {
this.brandName = brandName;
}

public String getRecommendedType() {
return recommendedType;
}

public void setRecommendedType(String recommendedType) {
this.recommendedType = recommendedType;
}

public String getApplicableTypes() {
return applicableTypes;
}

public void setApplicableTypes(String applicableTypes) {
this.applicableTypes = applicableTypes;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
this.price = price;
}

public String getPurpose() {
return purpose;
}

public void setPurpose(String purpose) {
this.purpose = purpose;
}

public String getImage() {
return image;
}

public void setImage(String image) {
this.image = image;
}
}
92 changes: 92 additions & 0 deletions src/main/java/yes1sir/yessir/model/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package yes1sir.yessir.model;

import jakarta.persistence.*;
import java.math.BigDecimal;
import java.util.Set;

@Entity
public class Product {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String productName;
private String brandName;
private String recommendedType;
private BigDecimal price;
private String purpose;
private String image;

@ManyToMany
@JoinTable(
name = "product_skin_type",
joinColumns = @JoinColumn(name = "product_id"),
inverseJoinColumns = @JoinColumn(name = "skin_type_id")
)
private Set<SkinType> applicableSkinTypes;

// getters and setters
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getProductName() {
return productName;
}

public void setProductName(String productName) {
this.productName = productName;
}

public String getBrandName() {
return brandName;
}

public void setBrandName(String brandName) {
this.brandName = brandName;
}

public String getRecommendedType() {
return recommendedType;
}

public void setRecommendedType(String recommendedType) {
this.recommendedType = recommendedType;
}

public BigDecimal getPrice() {
return price;
}

public void setPrice(BigDecimal price) {
this.price = price;
}

public String getPurpose() {
return purpose;
}

public void setPurpose(String purpose) {
this.purpose = purpose;
}

public String getImage() {
return image;
}

public void setImage(String image) {
this.image = image;
}

public Set<SkinType> getApplicableSkinTypes() {
return applicableSkinTypes;
}

public void setApplicableSkinTypes(Set<SkinType> applicableSkinTypes) {
this.applicableSkinTypes = applicableSkinTypes;
}
}
Loading