migrate to c++, all layers done except for data access
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Kotlin ###
|
||||
.kotlin
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
Generated
-3
@@ -1,3 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
Generated
-10
@@ -1,10 +0,0 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JetCodeStyleSettings>
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</JetCodeStyleSettings>
|
||||
<codeStyleSettings language="kotlin">
|
||||
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
Generated
-5
@@ -1,5 +0,0 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
||||
@@ -1,6 +0,0 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="ReplaceUntilWithRangeUntil" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
Generated
-10
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Kotlin2JvmCompilerArguments">
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
</component>
|
||||
<component name="KotlinCommonCompilerArguments">
|
||||
<option name="apiVersion" value="2.4" />
|
||||
<option name="languageVersion" value="2.4" />
|
||||
</component>
|
||||
</project>
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="KotlinJavaRuntime" type="repository">
|
||||
<properties maven-id="org.jetbrains.kotlin:kotlin-stdlib:2.4.0" />
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.4.0/kotlin-stdlib-2.4.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.4.0/kotlin-stdlib-2.4.0-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.4.0/kotlin-stdlib-2.4.0-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-8
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/cli.iml" filepath="$PROJECT_DIR$/cli.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
<orderEntry type="module-library" scope="TEST">
|
||||
<library name="JUnit4">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.13.1/junit-4.13.1.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library" scope="TEST">
|
||||
<library name="JUnit5">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.14.0/junit-jupiter-5.14.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.14.0/junit-jupiter-api-5.14.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.3.0/opentest4j-1.3.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.14.0/junit-platform-commons-1.14.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.14.0/junit-jupiter-params-5.14.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.14.0/junit-jupiter-engine-5.14.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.14.0/junit-platform-engine-1.14.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#include "include/dao.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void Dao::populate_env() {
|
||||
this->api_key = getenv("FRONTEND_API_KEY");
|
||||
this->db_url = getenv("DB_URL");
|
||||
}
|
||||
|
||||
ticket_t Dao::fetch_ticket_create(string title, string description) {
|
||||
|
||||
}
|
||||
|
||||
vector<ticket_t> Dao::fetch_ticket_get_all() {
|
||||
|
||||
}
|
||||
|
||||
vector<ticket_t> Dao::fetch_ticket_get_by_status(string status) {
|
||||
|
||||
}
|
||||
|
||||
ticket_t Dao::fetch_ticket_get_by_id(unsigned long id) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "include/handler.h"
|
||||
#include "include/printer.h"
|
||||
#include "include/dao.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/** TODO: error propagation?? (now always returns 0) */
|
||||
|
||||
int handle_create(Dao *dao, string title, string description) {
|
||||
ticket_t t = dao->fetch_ticket_create(title, description);
|
||||
vector<ticket_t> tickets;
|
||||
tickets.push_back(t);
|
||||
print_tickets(tickets);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_list(Dao *dao) {
|
||||
vector<ticket_t> tickets = dao->fetch_ticket_get_all();
|
||||
print_tickets(tickets);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_list(Dao *dao, string status) {
|
||||
vector<ticket_t> tickets = dao->fetch_ticket_get_by_status(status);
|
||||
print_tickets(tickets);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_detail(Dao *dao, unsigned long id) {
|
||||
ticket_t t = dao->fetch_ticket_get_by_id(id);
|
||||
vector<ticket_t> tickets;
|
||||
tickets.push_back(t);
|
||||
print_tickets(tickets);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef DAO_H
|
||||
#define DAO_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ticket.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Dao {
|
||||
public:
|
||||
string api_key;
|
||||
string db_url;
|
||||
void populate_env();
|
||||
|
||||
ticket_t fetch_ticket_create(string title, string description);
|
||||
vector<ticket_t> fetch_ticket_get_all();
|
||||
vector<ticket_t> fetch_ticket_get_by_status(string status);
|
||||
ticket_t fetch_ticket_get_by_id(unsigned long id);
|
||||
};
|
||||
|
||||
#endif // DAO_H
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef HANDLER_H
|
||||
#define HANDLER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "dao.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int handle_create(Dao *dao, string title, string description);
|
||||
int handle_list(Dao *dao);
|
||||
int handle_list(Dao *dao, string status);
|
||||
int handle_detail(Dao *dao, unsigned long id);
|
||||
|
||||
#endif // HANDLER_H
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef PARSER_H
|
||||
#define PARSER_H
|
||||
|
||||
#include "dao.h"
|
||||
|
||||
int parse_args(Dao *dao, int argc, char *argv[]);
|
||||
|
||||
#endif // PARSER_H
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef PRINTER_H
|
||||
#define PRINTER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "ticket.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void print_tickets(vector<ticket_t> tickets);
|
||||
|
||||
#endif // PRINTER_H
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef TICKET_H
|
||||
#define TICKET_H
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef struct {
|
||||
unsigned long id;
|
||||
string title;
|
||||
string description;
|
||||
string status;
|
||||
string created_at;
|
||||
string updated_at;
|
||||
} ticket_t;
|
||||
|
||||
#endif // TICKET_H
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "include/parser.h"
|
||||
#include "include/dao.h"
|
||||
|
||||
int main(int argc, char *argv[], char *envp[]) {
|
||||
Dao *dao = new Dao();
|
||||
dao->populate_env();
|
||||
int retval = parse_args(dao, argc, argv);
|
||||
delete dao;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
#include "include/parser.h"
|
||||
#include "include/handler.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void show_usage() {
|
||||
cout << "usage:\n"
|
||||
"these env vars have to be set: FRONTEND_API_KEY, DB_URL"
|
||||
"tickets create <title> <description>\n"
|
||||
"tickets list [-status <status>]\n"
|
||||
"tickets detail <id>" << endl;
|
||||
}
|
||||
|
||||
#define show_usage_and_die() show_usage(); return 1;
|
||||
|
||||
int parse_args(Dao *dao, int argc, char *argv[]) {
|
||||
if (argc == 1) { // not enough args
|
||||
show_usage_and_die();
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "create") == 0) { // creating a ticket
|
||||
if (argc != 4) {
|
||||
show_usage_and_die();
|
||||
}
|
||||
|
||||
return handle_create(dao, argv[2], argv[3]); // title and description
|
||||
}
|
||||
|
||||
|
||||
if (strcmp(argv[1], "list") == 0) { // listing tickets (optional filter by status)
|
||||
if (argc != 2 || argc != 4) {
|
||||
show_usage_and_die();
|
||||
}
|
||||
|
||||
if (argc == 4) {
|
||||
if (strcmp(argv[2], "-status") == 0) {
|
||||
return handle_list(dao, argv[3]); // the status text
|
||||
}
|
||||
}
|
||||
|
||||
// now we know that argc == 2
|
||||
// -> handle list (get all tickets)
|
||||
return handle_list(dao);
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "detail") == 0) {
|
||||
if (argc != 3) {
|
||||
show_usage_and_die();
|
||||
}
|
||||
|
||||
int ticket_id = atoi(argv[2]);
|
||||
|
||||
return handle_detail(dao, ticket_id); // ticket id
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "include/printer.h"
|
||||
|
||||
void print_tickets(vector<ticket_t> tickets) {
|
||||
for (ticket_t t : tickets) {
|
||||
cout << "/------+-------\n"
|
||||
"|Ticket| id: " << t.id << "\n"
|
||||
"+------/ title: " << t.title << "\n"
|
||||
"| description: " << t.description << "\n"
|
||||
"| status: " << t.status << "\n"
|
||||
"| created at: " << t.created_at << "\n"
|
||||
"| updated at: " << t.updated_at << "\n"
|
||||
"\\--------------" << endl;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* TICKETS
|
||||
*
|
||||
* a Linux cli for the mini ticket system written in C
|
||||
* features:
|
||||
* - create a ticket
|
||||
* `tickets create <title> <description>`
|
||||
* - list all tickets (or filter by status)
|
||||
* `tickets list --status=(open|in_progress|closed)`
|
||||
* - detail of one ticket
|
||||
* `tickets detail <id>`
|
||||
*/
|
||||
|
||||
fun showUsage() {
|
||||
println("usage:\n" +
|
||||
" tickets create <title> <description>\n" +
|
||||
" tickets list --status (open|in_progress|closed)\n" +
|
||||
" tickets detail <id>\n")
|
||||
}
|
||||
|
||||
fun parseCreate(title: String, description: String) {
|
||||
println("CREATE: creating a ticket with\n" +
|
||||
"title='$title'\n" +
|
||||
"description='$description'")
|
||||
}
|
||||
|
||||
fun parseList(status: String) {
|
||||
println("LIST: listing items with status '$status'")
|
||||
}
|
||||
|
||||
fun parseDetail(id: Int) {
|
||||
println("ID: the id i got is $id\ngoodbye!")
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
// only program name
|
||||
if (args.isEmpty()) {
|
||||
showUsage()
|
||||
return
|
||||
} // args.size > 1
|
||||
|
||||
// status filter or no filter
|
||||
if (args[0] == "list") {
|
||||
if (args.size >= 3 && args[1] == "--status") {
|
||||
parseList(args[2])
|
||||
} else {
|
||||
parseList("")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (args.size >= 2 && args[0] == "detail") {
|
||||
val id = args[1].toIntOrNull()
|
||||
if (id == null) {
|
||||
showUsage()
|
||||
return
|
||||
} else {
|
||||
parseDetail(id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (args.size >= 3 && args[0] == "create") {
|
||||
parseCreate(args[1], args[2])
|
||||
} else {
|
||||
showUsage()
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import java.util.Date
|
||||
|
||||
/** ticket model */
|
||||
data class Ticket(
|
||||
val title: String,
|
||||
val description: String,
|
||||
val status: String,
|
||||
val createdAt: Date,
|
||||
val updatedAt: Date
|
||||
)
|
||||
@@ -1,19 +0,0 @@
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class ArgsParseTest {
|
||||
@Test
|
||||
fun parseCreate() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseList() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parseDetail() {
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user