瀏覽代碼

working on db

Vincent Sima 6 年之前
父節點
當前提交
a987b6d75a

二進制
.DS_Store 查看文件


+ 4
- 0
1.1.1/pom.xml 查看文件

@@ -36,6 +36,10 @@
36 36
 		</dependency>
37 37
 		<dependency>
38 38
 			<groupId>org.springframework.boot</groupId>
39
+			<artifactId>spring-boot-starter-data-rest</artifactId>
40
+		</dependency>
41
+		<dependency>
42
+			<groupId>org.springframework.boot</groupId>
39 43
 			<artifactId>spring-boot-starter-security</artifactId>
40 44
 		</dependency>
41 45
 		<dependency>

+ 23
- 0
1.1.1/src/main/java/DatabaseController/CryptoRepository.java 查看文件

@@ -0,0 +1,23 @@
1
+package DatabaseController;
2
+
3
+import Trades.CryptoTrade;
4
+import org.springframework.data.repository.CrudRepository;
5
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
6
+
7
+import java.util.List;
8
+
9
+@RepositoryRestResource
10
+public interface CryptoRepository extends CrudRepository<CryptoTrade, Long> {
11
+
12
+
13
+//
14
+//        public void saveOrUpdate(CryptoTrade ct);
15
+//
16
+//
17
+//        public void delete(Long ctId);
18
+//
19
+//        public CryptoTrade get(Long ctID);
20
+//
21
+//        public List<CryptoTrade> list();
22
+
23
+}

+ 69
- 0
1.1.1/src/main/java/DatabaseController/CryptoRepositoryImpl.java 查看文件

@@ -0,0 +1,69 @@
1
+//package DatabaseController;
2
+//
3
+//import Trades.CryptoTrade;
4
+//import org.springframework.jdbc.core.JdbcTemplate;
5
+//
6
+//import javax.sql.DataSource;
7
+//
8
+//public class CRUDRepositoryImpl implements CryptoRepository {
9
+//
10
+//    private JdbcTemplate jdbcTemplate;
11
+//
12
+//    public CRUDRepositoryImpl(DataSource dataSource) {
13
+//        jdbcTemplate = new JdbcTemplate(dataSource);
14
+//    }
15
+//
16
+//    public void saveOrUpdate(CryptoTrade ct) {
17
+//        if (ct.getId() > 0) {
18
+//            // update
19
+//            String sql = "UPDATE crypto_test SET ticker=?, exchange=?, signalBuyPrice=?, "
20
+//                    + "actualBuyPrice=?, buyTimestamp=?, signalSellPrice=?, actualSellPrice=?, "
21
+//            + "sellTimestamp=?, strategy1=? WHERE id=?";
22
+//            jdbcTemplate.update(sql, ct.getTicker(), ct.getExchange(),
23
+//                    ct.getSignalBuyPrice(), ct.getActualBuyPrice(),
24
+//                    ct.getBuyTimestamp(), ct.getSignalSellPrice(), ct.getActualSellPrice(), ct.getSellTimestamp(),
25
+//                    ct.getStrategy1());
26
+//        } else {
27
+//            // insert
28
+//            String sql = "INSERT INTO crypto_test (ticker, exchange, signalBuyPrice, actualBuyPrice, buyTimestamp, " +
29
+//                    "signalSellPrice, actualSellPrice, sellTimestamp, strategy1)"
30
+//                    + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
31
+//            jdbcTemplate.update(sql, ct.getTicker(), ct.getExchange(),
32
+//                    ct.getSignalBuyPrice(), ct.getActualBuyPrice(),
33
+//                    ct.getBuyTimestamp(), ct.getSignalSellPrice(), ct.getActualSellPrice(), ct.getSellTimestamp(),
34
+//                    ct.getStrategy1());
35
+//        }
36
+//    }
37
+//
38
+//    public void delete(Long ctId){
39
+//        String sql = "DELETE FROM contact WHERE id=?";
40
+//        jdbcTemplate.update(sql, ctId);}
41
+//
42
+//
43
+////                  GET LIST OF TRADES
44
+////    public CryptoTrade get(Long ctID){
45
+////        String sql = "SELECT * FROM contact";
46
+////        List<CryptoTrade> ctList = jdbcTemplate.query(sql, new RowMapper<CryptoTrade>() {
47
+////
48
+////            @Override
49
+////            public CryptoTrade mapRow(ResultSet rs, int rowNum) throws SQLException {
50
+////                CryptoTrade aCrypto = new CryptoTrade();
51
+////
52
+////                aCrypto.setId(rs.getInt("contact_id"));
53
+////                aCrypto.setName(rs.getString("name"));
54
+////                aCrypto.setEmail(rs.getString("email"));
55
+////                aCrypto.setAddress(rs.getString("address"));
56
+////                aCrypto.setTelephone(rs.getString("telephone"));
57
+////
58
+////                return aCrypto;
59
+////            }
60
+////
61
+////        });
62
+////
63
+////        return listContact;
64
+////    }
65
+////
66
+////    public List<CryptoTrade> list();
67
+//
68
+//
69
+//}

+ 0
- 63
1.1.1/src/main/java/DatabaseController/CryptoTradeDBController.java 查看文件

@@ -1,63 +0,0 @@
1
-package DatabaseController;
2
-
3
-import Trades.CryptoTrade;
4
-import Trades.CryptoTradeRepository;
5
-import org.springframework.beans.factory.annotation.Autowired;
6
-import org.springframework.http.ResponseEntity;
7
-import org.springframework.web.bind.annotation.*;
8
-import javax.validation.Valid;
9
-import java.util.List;
10
-
11
-
12
-
13
-@RestController
14
-@RequestMapping("/api")
15
-
16
-public class CryptoTradeDBController {
17
-
18
-    @Autowired
19
-    CryptoTradeRepository cryptoTradeRepository;
20
-
21
-
22
-    @GetMapping("/crypto")
23
-    public List<CryptoTrade> getAllCryptoTrades() {
24
-        return cryptoTradeRepository.findAll();
25
-    }
26
-
27
-    @PostMapping("/crypto")
28
-    public CryptoTrade createCryptoTrade(@Valid @RequestBody CryptoTrade cryptoTrade){
29
-        return cryptoTradeRepository.save(cryptoTrade);
30
-
31
-    }
32
-
33
-//    @GetMapping("/crypto/{id}")
34
-//    public CryptoTrade getCryptoTradeById(@PathVariable(value = "id") Integer cryptoTradeId) {
35
-//        return cryptoTradeRepository.findById(cryptoTradeId);
36
-//    }
37
-
38
-
39
-    //UPDATING CRYPTOTRADE - https://www.callicoder.com/spring-boot-rest-api-tutorial-with-mysql-jpa-hibernate/
40
-//
41
-//    @PutMapping("/notes/{id}")
42
-//    public Note updateNote(@PathVariable(value = "id") Long noteId,
43
-//                           @Valid @RequestBody Note noteDetails) {
44
-//
45
-//        Note note = noteRepository.findById(noteId)
46
-//                .orElseThrow(() -> new ResourceNotFoundException("Note", "id", noteId));
47
-//
48
-//        note.setTitle(noteDetails.getTitle());
49
-//        note.setContent(noteDetails.getContent());
50
-//
51
-//        Note updatedNote = noteRepository.save(note);
52
-//        return updatedNote;
53
-
54
-//    @DeleteMapping("/crypto/{id}")
55
-//    public ResponseEntity<?> deleteNote(@PathVariable(value = "id") Integer cryptoTradeId) {
56
-//        CryptoTrade cryptoTrade = cryptoTradeRepository.findById(cryptoTradeId);
57
-//
58
-//        cryptoTradeRepository.delete(cryptoTrade);
59
-//
60
-//        return ResponseEntity.ok().build();
61
-//    }
62
-
63
-}

+ 3
- 21
1.1.1/src/main/java/Trades/CryptoTrade.java 查看文件

@@ -4,49 +4,31 @@ import javax.persistence.Column;
4 4
 import javax.persistence.GeneratedValue;
5 5
 import javax.persistence.GenerationType;
6 6
 import javax.persistence.Id;
7
-import org.springframework.context.annotation.Scope;
8 7
 
9 8
 import javax.persistence.*;
10 9
 
11 10
 @Entity
12 11
 @Table(name="crypto_test")
13
-@Scope("Session")
14 12
 public class CryptoTrade {
15 13
     @Id
16 14
     @GeneratedValue(strategy=GenerationType.AUTO)
17
-    private Integer id;
15
+    private long id;
18 16
 
19
-    @Column(nullable = false)
17
+    @Column
20 18
     String ticker;
21
-    @Column(nullable = false)
22 19
     String exchange;
23
-    @Column(nullable = false)
24 20
     double signalBuyPrice;
25
-    @Column(nullable = false)
26 21
     double actualBuyPrice;
27
-    @Column(nullable = false)
28
-    @Temporal(TemporalType.TIMESTAMP)
29 22
     String buyTimestamp;
30
-    @Column(nullable = false)
31 23
     double signalSellPrice;
32
-    @Column(nullable = false)
33 24
     double actualSellPrice;
34
-    @Column(nullable = false)
35
-    @Temporal(TemporalType.TIMESTAMP)
36 25
     String sellTimestamp;
37
-    @Column(nullable = false)
38 26
     double percentChange;
39
-    @Column(nullable = false)
40 27
     String strategy1;
41
-    @Column
42 28
     String strategy1Notes;
43
-    @Column
44 29
     String strategy2;
45
-    @Column
46 30
     String strategy2Notes;
47
-    @Column
48 31
     String strategy3;
49
-    @Column
50 32
     String strategy3Notes;
51 33
 
52 34
 
@@ -63,7 +45,7 @@ public class CryptoTrade {
63 45
         this.strategy1 = strategy1;
64 46
     }
65 47
 
66
-    public int getId(){
48
+    public Long getId(){
67 49
         return id;
68 50
     }
69 51
 

+ 0
- 9
1.1.1/src/main/java/Trades/CryptoTradeRepository.java 查看文件

@@ -1,9 +0,0 @@
1
-package Trades;
2
-
3
-import org.springframework.data.jpa.repository.JpaRepository;
4
-import org.springframework.stereotype.Repository;
5
-
6
-@Repository
7
-public interface CryptoTradeRepository extends JpaRepository<CryptoTrade, Integer> {
8
-
9
-}

+ 0
- 1
1.1.1/src/main/java/Trades/ForexTrade.java 查看文件

@@ -6,7 +6,6 @@ import javax.persistence.*;
6 6
 
7 7
 @Entity
8 8
 @Table(name="forex_test")
9
-@Scope("Session")
10 9
 public class ForexTrade {
11 10
     @Id
12 11
     @GeneratedValue(strategy=GenerationType.IDENTITY)

+ 12
- 1
1.1.1/src/main/java/tradingproject001/Application.java 查看文件

@@ -7,11 +7,21 @@ import Trades.CryptoTrade;
7 7
 import org.springframework.boot.SpringApplication;
8 8
 import org.springframework.boot.autoconfigure.SpringBootApplication;
9 9
 
10
+import javax.sql.DataSource;
11
+
12
+
10 13
 @SpringBootApplication
11 14
 public class Application {
12 15
 
16
+//    @Autowired
17
+//    DataSource dataSource;
18
+
19
+//    @Autowired
20
+//    CryptoRepository cryptoRepository;
21
+
13 22
 	public static void main(String[] args) {
14 23
 		SpringApplication.run(Application.class, args);
24
+
15 25
 		String apiKey = "FRV46SGJ2IAABHTG";
16 26
         int timeout = 3000;
17 27
         ApiConnector apiConnector = new AlphaVantageConnector(apiKey, timeout);
@@ -30,7 +40,8 @@ public class Application {
30 40
         } catch (org.AlphaVantage.output.AlphaVantageException e) {
31 41
             System.out.println("something went wrong");
32 42
         }
43
+        CryptoTrade cryptoTrade = new CryptoTrade("BTC/USD", "Kraken", 609.88, 610.10, "2018-06-06 12:01:01",615.09, 615.78, "2018-06-06 15:01:01", 15.57, "K39");
44
+
33 45
 
34
-        CryptoTrade ct = new CryptoTrade("BTC/USD", "Kraken", 609.88, 610.10, "2018-06-06 12:01:01",615.09, 615.78, "2018-06-06 15:01:01", 15.57, "K39");
35 46
 	}
36 47
 }

+ 5
- 3
1.1.1/src/main/resources/application.properties 查看文件

@@ -1,4 +1,6 @@
1 1
 spring.jpa.hibernate.ddl-auto=update
2
-spring.datasource.url=jdbc:mysql://localhost:3306/trader?autoReconnect=true&useSSL=false
3
-spring.datasource.username=trader
4
-spring.datasource.password=tradertest
2
+spring.datasource.url=jdbc:mysql://localhost:3306/trader?useSSL=false
3
+spring.datasource.username=root
4
+spring.datasource.password=
5
+spring.datasource.driver-class-name=com.mysql.jdbc.Driver
6
+spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

+ 1
- 1
UI Ionic/.sourcemaps/main.js.map
文件差異過大導致無法顯示
查看文件


+ 1
- 2
UI Ionic/www/build/main.js 查看文件

@@ -384,10 +384,9 @@ var TradePage = /** @class */ (function () {
384 384
         Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["m" /* Component */])({
385 385
             selector: 'page-trade',template:/*ion-inline-start:"/Users/vincents/Labs/CryptoTrader/UI Ionic/src/pages/trade/trade.html"*/'<!--\n  Generated template for the TradePage page.\n\n  See http://ionicframework.com/docs/components/#navigation for more info on\n  Ionic pages and navigation.\n-->\n<ion-header>\n\n  <ion-navbar>\n    <ion-title text-center>Trade</ion-title>\n  </ion-navbar>\n\n</ion-header>\n\n\n<ion-content padding>\n\n</ion-content>\n'/*ion-inline-end:"/Users/vincents/Labs/CryptoTrader/UI Ionic/src/pages/trade/trade.html"*/,
386 386
         }),
387
-        __metadata("design:paramtypes", [typeof (_a = typeof __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["e" /* NavController */] !== "undefined" && __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["e" /* NavController */]) === "function" && _a || Object, typeof (_b = typeof __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["f" /* NavParams */] !== "undefined" && __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["f" /* NavParams */]) === "function" && _b || Object])
387
+        __metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_1_ionic_angular__["e" /* NavController */], __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["f" /* NavParams */]])
388 388
     ], TradePage);
389 389
     return TradePage;
390
-    var _a, _b;
391 390
 }());
392 391
 
393 392
 //# sourceMappingURL=trade.js.map

+ 1
- 1
UI Ionic/www/build/main.js.map
文件差異過大導致無法顯示
查看文件


+ 1
- 1
UI Ionic/www/build/vendor.js.map
文件差異過大導致無法顯示
查看文件