Skip to content
Merged
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
70 changes: 70 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Check

on:
push:
branches: [main]
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
with:
sdk: stable

- name: Install dpk
shell: bash
run: dart install dpk

- name: Add Dart bin to PATH
shell: bash
run: echo "$HOME/.local/state/Dart/install/bin" >> $GITHUB_PATH

- name: Get dependencies
shell: bash
run: dart pub get

- name: Run format
shell: bash
run: dpk run ci:format

analyze:
name: Analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
with:
sdk: stable

- name: Install dpk
shell: bash
run: dart install dpk

- name: Add Dart bin to PATH
shell: bash
run: echo "$HOME/.local/state/Dart/install/bin" >> $GITHUB_PATH

- name: Get dependencies
shell: bash
run: dart pub get

- name: Copy .env.example to .env
shell: bash
run: cp .env.example .env

- name: Run build
shell: bash
run: dpk run build

- name: Run analyze
shell: bash
run: dpk run ci:analyze
8 changes: 8 additions & 0 deletions dpk.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version: ^0.6.5

scripts:
docker: docker compose up
dev: arcade serve
Expand All @@ -11,3 +13,9 @@ scripts:
clean:watch: |
dpk run clean
dpk run watch

fix: dart fix --apply
format: dart format .

ci:format: dart format . --set-exit-if-changed
ci:analyze: dart analyze . --fatal-infos --fatal-warnings
9 changes: 2 additions & 7 deletions lib/core/database/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ class Database extends $Database {
);

static QueryExecutor _openConnection() {
final Uri(
:host,
:userInfo,
:port,
:pathSegments,
:queryParameters,
) = Uri.parse(Env.databaseUrl);
final Uri(:host, :userInfo, :port, :pathSegments, :queryParameters) =
Uri.parse(Env.databaseUrl);
final [username, password] = userInfo.split(':');
final sslModeString = queryParameters['sslmode'] ?? 'disable';

Expand Down
78 changes: 35 additions & 43 deletions lib/core/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,41 @@ final getIt = GetIt.instance;
Future<void> init() async {
await getIt.init();

setupSwagger(
title: 'Aracde API',
version: '1.0.0',
);
setupSwagger(title: 'Aracde API', version: '1.0.0');

route.addBeforeHookForPath(
'/ui',
(context) {
// Validate basic auth. Send a prompt for the browser if not authenticated.
final auth = context.requestHeaders['Authorization'];
if (auth == null) {
context.statusCode = 401;
context.responseHeaders.set('WWW-Authenticate', 'Basic');
return context;
}
route.addBeforeHookForPath('/ui', (context) {
// Validate basic auth. Send a prompt for the browser if not authenticated.
final auth = context.requestHeaders['Authorization'];
if (auth == null) {
context.statusCode = 401;
context.responseHeaders.set('WWW-Authenticate', 'Basic');
return context;
}

const username = 'admin';
const password = 'admin';
final authValue = auth.first.split(' ').last;
final decoded = base64Decode(authValue);
final decodedString = utf8.decode(decoded);
final credentials = decodedString.split(':');
if (credentials.length != 2) {
context.statusCode = 401;
context.responseHeaders.set('WWW-Authenticate', 'Basic');
return context;
}
const username = 'admin';
const password = 'admin';
final authValue = auth.first.split(' ').last;
final decoded = base64Decode(authValue);
final decodedString = utf8.decode(decoded);
final credentials = decodedString.split(':');
if (credentials.length != 2) {
context.statusCode = 401;
context.responseHeaders.set('WWW-Authenticate', 'Basic');
return context;
}

final [authUsername, authPassword] = credentials;
if (authUsername != username || authPassword != password) {
context.statusCode = 401;
context.responseHeaders.set('WWW-Authenticate', 'Basic');
return context;
}
final [authUsername, authPassword] = credentials;
if (authUsername != username || authPassword != password) {
context.statusCode = 401;
context.responseHeaders.set('WWW-Authenticate', 'Basic');
return context;
}

// If we get here, the user is authenticated.
context.responseHeaders.set('X-Auth-Username', username);
// If we get here, the user is authenticated.
context.responseHeaders.set('X-Auth-Username', username);

return context;
},
);
return context;
});
}

@module
Expand All @@ -69,13 +63,11 @@ abstract class AdditionalDependencies {
Future<BaseCacheManager> get cacheManager async {
final cache = RedisCacheManager();
final uri = Uri.parse(Env.redisUrl);
await cache.init(
(
host: uri.host,
port: uri.port,
secure: uri.scheme == 'rediss',
),
);
await cache.init((
host: uri.host,
port: uri.port,
secure: uri.scheme == 'rediss',
));
return cache;
}
}
25 changes: 7 additions & 18 deletions lib/modules/todos/controllers/todo_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ class TodoController {
summary: 'Create a todo',
description: 'Create a todo',
request: $CreateTodoRequestSchema,
responses: {
'201': $$TodoDataResponseSchema,
},
responses: {'201': $$TodoDataResponseSchema},
)
.post('/')
.handle(createTodo);
Expand All @@ -47,10 +45,7 @@ class TodoController {
summary: 'Mark a todo as done',
description: 'Mark a todo as done',
parameters: const [
Parameter.path(
name: 'id',
description: 'The id of the todo',
),
Parameter.path(name: 'id', description: 'The id of the todo'),
],
)
.put('/:id/complete')
Expand All @@ -61,10 +56,7 @@ class TodoController {
summary: 'Mark a todo as not done',
description: 'Mark a todo as not done',
parameters: const [
Parameter.path(
name: 'id',
description: 'The id of the todo',
),
Parameter.path(name: 'id', description: 'The id of the todo'),
],
)
.put('/:id/incomplete')
Expand All @@ -75,10 +67,7 @@ class TodoController {
summary: 'Delete a todo',
description: 'Delete a todo',
parameters: const [
Parameter.path(
name: 'id',
description: 'The id of the todo',
),
Parameter.path(name: 'id', description: 'The id of the todo'),
],
)
.delete('/:id')
Expand All @@ -88,9 +77,9 @@ class TodoController {
}

Future<List<TodoDataResponse>> getTodos(RequestContext context) {
return todoService
.getTodos()
.then((todos) => todos.map((todo) => todo.toTodoDataResponse).toList());
return todoService.getTodos().then(
(todos) => todos.map((todo) => todo.toTodoDataResponse).toList(),
);
}

Future<TodoDataResponse> createTodo(RequestContext context) async {
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/todos/repositories/todo_repository.drift.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:start/modules/todos/tables/todos_table.drift.dart' as i2;
import 'package:drift/internal/modular.dart' as i3;

mixin $TodoRepositoryMixin on i0.DatabaseAccessor<i1.Database> {
i2.$TodosTableTable get todosTable =>
i3.ReadDatabaseContainer(attachedDatabase)
.resultSet<i2.$TodosTableTable>('todos');
i2.$TodosTableTable get todosTable => i3.ReadDatabaseContainer(
attachedDatabase,
).resultSet<i2.$TodosTableTable>('todos');
}
4 changes: 1 addition & 3 deletions lib/modules/todos/services/todo_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ class TodoService {

Future<void> deleteTodo(String id) {
return _todoRepository.deleteTodo(
TodosTableCompanion(
id: Value(UuidValue.fromString(id)),
),
TodosTableCompanion(id: Value(UuidValue.fromString(id))),
);
}
}
Loading