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

2 creation of react UI of ticket availability real time updates #6

Open
wants to merge 5 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
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"git.ignoreLimitWarning": true,
"java.configuration.updateBuildConfiguration": "interactive"
}
35 changes: 35 additions & 0 deletions test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@stomp/[email protected]/bundles/stomp.umd.min.js"></script>
<script>
const onConnected = () => {
console.log("connected");
stompClient.subscribe("/allSeats", onMessageReceived);
stompClient.send("/startTimer", {}, "{}");
};

const onMessageReceived = (payload) => {
console.log("on message");
var payloadData = JSON.parse(payload.body);
console.log(payloadData);
};

const onError = (err) => {
console.log(err);
};

var sock = new SockJS("http://localhost:8080/stomp");
var stompClient = StompJs.Stomp.over(sock);
stompClient.connect({}, onConnected, onError);
</script>
</head>
<body>
check console
</body>
</html>
2 changes: 2 additions & 0 deletions ticket-websocket/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ build/

### VS Code ###
.vscode/

ticket-websocket/target
Empty file modified ticket-websocket/mvnw
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.setApplicationDestinationPrefixes("/app");
config.enableSimpleBroker("/database", "/client");
config.setUserDestinationPrefix("/client");
config.setApplicationDestinationPrefixes("/");
config.enableSimpleBroker("/");
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ticket").setAllowedOriginPatterns("*").withSockJS();
registry.addEndpoint("/stomp").setAllowedOriginPatterns("*").withSockJS();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ArrayList;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

import com.teamig.ticket_websocket.model.Tickets;
import com.teamig.ticket_websocket.model.Ticket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
Expand All @@ -18,18 +22,44 @@ public class TicketController {
@Autowired
private SimpMessagingTemplate simpMessagingTemplate;

@MessageMapping("/message")
@SendTo("/database/ticketarray")
private Tickets randomTicket(@Payload Tickets tickets) {
ArrayList<String> tickArray = new ArrayList<String>();
ArrayList<String> removeArray = new ArrayList<String>()
for(int i = 1; i < 101; i++) {
tickArray.add("a"+i)
private Timer timer = null;

static ArrayList<Ticket> tickArray = new ArrayList<Ticket>();

static{
for(int i = 1; i <= 20; i++) {
tickArray.add(new Ticket("A"+i, true));
}
for(int i = 0; i < 5; i++){
String randStr = getRandomElement(tickArray)
removeArray.add(randStr)
}

@MessageMapping("/startTimer")
private void startTimer() {
if (timer == null) {
System.out.println("Starting timer");

simpMessagingTemplate.convertAndSend("/allSeats", tickArray);

TimerTask task = new TimerTask() {
public void run() {
System.out.println("Running timer");
for(int i = 0; i < 5; i++){
Ticket randomTicket = getRandomElement(tickArray);
randomTicket.available = false;
}
simpMessagingTemplate.convertAndSend("/allSeats", tickArray);
}
};

timer = new Timer("Timer");

long delay = 5000L;
long rate = 5000L;
timer.schedule(task, delay, rate);
}
return removeArray;
}

public Ticket getRandomElement(ArrayList<Ticket> list) {
Random rand = new Random();
return list.get(rand.nextInt(list.size()));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.teamig.ticket_websocket.model;

import java.sql.Array;

import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class Tickets {
private String ticketArray[] = {};
public class Ticket {
public String name;
public boolean available;
}
1 change: 1 addition & 0 deletions ticket-websocket/target/classes/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions ticket-websocket/target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=ticket
groupId=com.teamig
version=0.0.1-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
com/teamig/ticket_websocket/controller/TicketController$1.class
com/teamig/ticket_websocket/controller/TicketController.class
com/teamig/ticket_websocket/config/WebSocketConfig.class
com/teamig/ticket_websocket/model/Ticket.class
com/teamig/ticket_websocket/TicketApplication.class
com/teamig/ticket_websocket/model/Status.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/Users/melissatranfield/Documents/Projects/ticketing-saas/ticket-websocket/src/main/java/com/teamig/ticket_websocket/model/Ticket.java
/Users/melissatranfield/Documents/Projects/ticketing-saas/ticket-websocket/src/main/java/com/teamig/ticket_websocket/controller/TicketController.java
/Users/melissatranfield/Documents/Projects/ticketing-saas/ticket-websocket/src/main/java/com/teamig/ticket_websocket/model/Status.java
/Users/melissatranfield/Documents/Projects/ticketing-saas/ticket-websocket/src/main/java/com/teamig/ticket_websocket/TicketApplication.java
/Users/melissatranfield/Documents/Projects/ticketing-saas/ticket-websocket/src/main/java/com/teamig/ticket_websocket/config/WebSocketConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/melissatranfield/Documents/Projects/ticketing-saas/ticket-websocket/src/test/java/com/teamig/ticket/TicketApplicationTests.java
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

23 changes: 23 additions & 0 deletions ticketing-saas-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
46 changes: 46 additions & 0 deletions ticketing-saas-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
Loading