# Copyright 2022 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

.PHONY: all init run request stop

all:
	make init run
	sleep 3 # waiting for spring boot application started
	make request stop

init:
	mysql -uroot -P3306 -h127.0.0.1 -p123456 < src/main/resources/use-sharding-initial.sql

run:
	java -jar target/bare-sharding-plan-0.0.1-SNAPSHOT.jar > bare-sharding-plan.log &

request:
	curl --location --request GET 'http://localhost:8080/event/daily' | python3 -m json.tool
	curl --location --request GET 'http://localhost:8080/personal/language?userID=66930949'  | python3 -m json.tool
	curl \
		--location --request POST 'http://localhost:8080/repo' \
		--header 'Content-Type: application/json' \
		--data-raw '[{"repoID":1,"repoName":"pingcap/same-name-repo","ownerID":0,"ownerLogin":"pingcap","ownerIsOrg":0}]' \
		| python3 -m json.tool
	curl \
		--location --request POST 'http://localhost:8080/repo' \
		--header 'Content-Type: application/json' \
		--data-raw '[{"repoID":2,"repoName":"pingcap/same-name-repo","ownerID":0,"ownerLogin":"pingcap","ownerIsOrg":0}]' \
    	| python3 -m json.tool

stop:
	kill `cat bare-sharding-plan.pid`