Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1621acb
Create 1주차 과제.md
gillyongs Jan 23, 2023
ef11139
Delete .github directory
gillyongs Jan 29, 2023
cbd19f5
Delete gradle/wrapper directory
gillyongs Jan 29, 2023
45ee390
Delete src directory
gillyongs Jan 29, 2023
330dfba
Delete .gitignore
gillyongs Jan 29, 2023
8381d49
Delete 1주차 과제.md
gillyongs Jan 29, 2023
7b86916
Delete build.gradle
gillyongs Jan 29, 2023
116e3d5
Delete gradlew
gillyongs Jan 29, 2023
a1d7745
Delete gradlew.bat
gillyongs Jan 29, 2023
eab0da2
Delete settings.gradle
gillyongs Jan 29, 2023
d69ee81
Create README.md
gillyongs Jan 29, 2023
209f891
Add files via upload
gillyongs Jan 29, 2023
9fdd4b9
Update README.md
gillyongs Jan 29, 2023
e87ab5b
Update README.md
gillyongs Jan 29, 2023
1af705a
Update README.md
gillyongs Jan 29, 2023
02c42f8
Create README.md
gillyongs Jan 29, 2023
f81187f
Add files via upload
gillyongs Jan 29, 2023
8789122
Update README.md
gillyongs Jan 29, 2023
6dcd26f
Update README.md
gillyongs Jan 29, 2023
d0a04ef
Create hello.html
gillyongs Jan 29, 2023
a60a360
Create HelloController.java
gillyongs Jan 29, 2023
334fd24
Delete mvc & api/resources directory
gillyongs Jan 29, 2023
025116e
Delete mvc & api/java/hello/hellospring directory
gillyongs Jan 29, 2023
ed736b7
Create README.md
gillyongs Jan 29, 2023
e1b49d5
Update README.md
gillyongs Jan 29, 2023
43710dc
Add files via upload
gillyongs Jan 29, 2023
7b7e823
Add files via upload
gillyongs Jan 29, 2023
70a7425
Delete memory/hellospring directory
gillyongs Jan 29, 2023
8052680
Add files via upload
gillyongs Jan 29, 2023
9ce4077
Delete HelloSpringApplicationTests.java
gillyongs Jan 29, 2023
96c899b
Delete memory/test/service directory
gillyongs Jan 29, 2023
f168fcc
Delete memory/test/repository directory
gillyongs Jan 29, 2023
867f5b1
Create a
gillyongs Jan 29, 2023
f565809
Add files via upload
gillyongs Jan 29, 2023
00d86eb
Delete a
gillyongs Jan 29, 2023
7316e59
Create README.md
gillyongs Jan 29, 2023
7d54bb4
Create a
gillyongs Jan 29, 2023
8e444b5
Delete a
gillyongs Jan 29, 2023
5e82f77
Add files via upload
gillyongs Jan 29, 2023
eed3762
Add files via upload
gillyongs Jan 29, 2023
84ffd94
Update README.md
gillyongs Jan 29, 2023
6fc7e9d
Create README.md
gillyongs Feb 6, 2023
01fc6e0
Add files via upload
gillyongs Feb 6, 2023
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
28 changes: 0 additions & 28 deletions .github/pull_request_template.md

This file was deleted.

37 changes: 0 additions & 37 deletions .gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.dku.springstudy;
package hello.hellospring;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringStudyApplication {
public class HelloSpringApplication {

public static void main(String[] args) {
SpringApplication.run(SpringStudyApplication.class, args);
SpringApplication.run(HelloSpringApplication.class, args);
}

}
File renamed without changes.
29 changes: 29 additions & 0 deletions CarrotMarket/SpringConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package hello.hellospring;
import hello.hellospring.domain.Customer;
import hello.hellospring.repository.*;
import hello.hellospring.service.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class SpringConfig {

private final ProductRepository productRepository;
private final CustomerRepository customerRepository;
public SpringConfig(ProductRepository productRepository, CustomerRepository customerRepository) {
this.customerRepository = customerRepository;
this.productRepository = productRepository;
}
//인터페이스만 만들면 스프링이 구현체를 만들어 bean에

@Bean
public ProductService productService() {
return new ProductService(productRepository);
}

@Bean
public CustomerService customerService() {
return new CustomerService(customerRepository);
}
}
33 changes: 33 additions & 0 deletions CarrotMarket/controller/CustomerController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package hello.hellospring.controller;

import hello.hellospring.domain.Customer;
import hello.hellospring.service.CustomerService;
import org.apache.tomcat.util.json.JSONParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CustomerController {

private final CustomerService customerService;
@Autowired
public CustomerController(CustomerService customerService) {
this.customerService = customerService;
}



@GetMapping("new")
void join(@RequestParam("email") String em, @RequestParam("password") String ps ) {
Customer cus = new Customer();
cus.setemail(em);
cus.setpassword(ps);
customerService.join(cus);

}



}
39 changes: 39 additions & 0 deletions CarrotMarket/controller/ProductController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package hello.hellospring.controller;

import hello.hellospring.domain.Product;
import hello.hellospring.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ProductController {

private final ProductService productService;
@Autowired
public ProductController(ProductService productService) {
this.productService = productService;
}

@GetMapping("products")
public List<Product> list() {
List<Product> products = productService.findProducts();
return products;
}

@GetMapping("heartclick")
void heartclick(@RequestParam("pid") Long pid) {
productService.HeartClick(pid);
}

@GetMapping("heartunclick")
void heartunclick(@RequestParam("pid") Long pid) {
productService.HeartUnClick(pid);
}


}
16 changes: 16 additions & 0 deletions CarrotMarket/controller/ReactController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package hello.hellospring.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
public class ReactController {

@GetMapping("hello")
public List<String> hello() {
return Arrays.asList("강동원","여진구","송중기");
}
}
33 changes: 33 additions & 0 deletions CarrotMarket/domain/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

package hello.hellospring.domain;
import javax.persistence.*;

@Entity
public class Customer{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long cid;
private String cname;
private String email;
private String password;
private String phone;
private String nickname;


public Long getcid() { return cid; }
public void setcid(Long cid) { this.cid = cid; }
public String getcname() {
return cname;
}
public void setcname(String cname) {
this.cname = cname;
}
public String getemail() {return email;}
public void setemail(String email) { this.email = email;}
public String getpassword() { return password;}
public void setpassword(String password) { this.password = password;}
public String getphone() { return phone;}
public void setphone(String phone) {this.phone = phone;}
public String getnickname() {return nickname;}
public void setnickname(String nickname) {this.nickname = nickname;}
}
31 changes: 31 additions & 0 deletions CarrotMarket/domain/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package hello.hellospring.domain;


import javax.persistence.*;

@Entity
public class Product{
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long pid;
private String pname;
private Long price;
private Long heart;
private String seller;

public Long getpid() {
return pid;
}
public void setpid(Long pid) { this.pid = pid; }
public String getpname() {
return pname;
}
public void setpname(String pname) {
this.pname = pname;
}
public String getSeller() {return seller;}
public void setSeller(String seller) { this.seller = seller;}
public Long getPrice() { return price; }
public void setPrice(Long price) { this.price = price; }
public Long getHeart() { return heart; }
public void setHeart(Long heart) { this.heart = heart; }
}
14 changes: 14 additions & 0 deletions CarrotMarket/repository/CustomerRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hello.hellospring.repository;

import hello.hellospring.domain.Customer;
import org.springframework.data.jpa.repository.JpaRepository;

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

public interface CustomerRepository extends JpaRepository<Customer, Long> {
Customer save(Customer product);
Optional<Customer> findByCname(String name);
Customer findByCid(Long pid);
List<Customer> findAll();
}
14 changes: 14 additions & 0 deletions CarrotMarket/repository/ProductRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package hello.hellospring.repository;

import hello.hellospring.domain.Product;
import org.springframework.data.jpa.repository.JpaRepository;

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

public interface ProductRepository extends JpaRepository<Product, Long> {
Product save(Product product);
Optional<Product> findByPname(String name);
Product findByPid(Long pid);
List<Product> findAll();
}
33 changes: 33 additions & 0 deletions CarrotMarket/service/CustomerService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package hello.hellospring.service;

import hello.hellospring.domain.Customer;
import hello.hellospring.repository.CustomerRepository;


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

//@service
public class CustomerService {
private final CustomerRepository customerRepository;
//@Autowired
public CustomerService(CustomerRepository customerRepository) { //의존관계 추가
this.customerRepository = customerRepository;
}

public List<Customer> findCustomers() { //전체 회원 조회
return customerRepository.findAll();
}

public Long join(Customer customer) { // 회원가입
validateDuplicateMember(customer); //중복 회원 체크
customerRepository.save(customer);
return customer.getcid();
}
private void validateDuplicateMember(Customer customer) {
customerRepository.findByCname(customer.getcname())
.ifPresent(m -> { //optinal 값이 null이 아니면
throw new IllegalStateException("이미 존재하는 회원입니다.");
});
}
}
33 changes: 33 additions & 0 deletions CarrotMarket/service/ProductService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package hello.hellospring.service;

import hello.hellospring.domain.Product;
import hello.hellospring.repository.ProductRepository;


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

//@service
public class ProductService {
private final ProductRepository productRepository;
//@Autowired
public ProductService(ProductRepository productRepository) { //의존관계 추가
this.productRepository = productRepository;
}

public List<Product> findProducts() { //전체 회원 조회
return productRepository.findAll();
}

public void HeartClick(Long pid) {
Product pd = productRepository.findByPid(pid);
pd.setHeart(pd.getHeart()+1);
productRepository.save(pd);
}

public void HeartUnClick(Long pid) {
Product pd = productRepository.findByPid(pid);
pd.setHeart(pd.getHeart()-1);
productRepository.save(pd);
}
}
Loading