-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add hint model, dio client and dtos for hint generation
- Loading branch information
1 parent
d61b784
commit dbcdd18
Showing
16 changed files
with
723 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export 'create_sudoku_request_dto.dart'; | ||
export 'create_sudoku_response_dto.dart'; | ||
export 'generate_hint_request_dto.dart'; | ||
export 'generate_hint_response_dto.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'generate_hint_request_dto.g.dart'; | ||
|
||
/// {@template generate_hint_request_dto} | ||
/// A DTO to send [GenerateHintRequest] object wrapped within `data` | ||
/// for the generate hint http request. | ||
/// {@endtemplate} | ||
@immutable | ||
@JsonSerializable(explicitToJson: true) | ||
class GenerateHintRequestDto extends Equatable { | ||
/// {@macro generate_hint_request_dto} | ||
const GenerateHintRequestDto({ | ||
required this.data, | ||
}); | ||
|
||
/// The data to be sent over via http. | ||
final GenerateHintRequest data; | ||
|
||
/// Converts [GenerateHintRequestDto] into [Map]. | ||
Map<String, dynamic> toJson() => _$GenerateHintRequestDtoToJson(this); | ||
|
||
@override | ||
List<Object?> get props => [data]; | ||
} | ||
|
||
/// {@template generate_hint_request} | ||
/// Model for the generate hint http request. | ||
/// {@endtemplate} | ||
@immutable | ||
@JsonSerializable() | ||
class GenerateHintRequest extends Equatable { | ||
/// {@macro generate_hint_request} | ||
const GenerateHintRequest({ | ||
required this.puzzle, | ||
required this.solution, | ||
}); | ||
|
||
/// Converts a [Map] object to a [GenerateHintRequest] instance. | ||
factory GenerateHintRequest.fromJson(Map<String, dynamic> json) => | ||
_$GenerateHintRequestFromJson(json); | ||
|
||
/// Current state of the puzzle. | ||
final List<List<int>> puzzle; | ||
|
||
/// Solution of the puzzle. | ||
final List<List<int>> solution; | ||
|
||
/// Converts [GenerateHintRequest] into [Map]. | ||
Map<String, dynamic> toJson() => _$GenerateHintRequestToJson(this); | ||
|
||
@override | ||
List<Object?> get props => [puzzle, solution]; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:sudoku/models/models.dart'; | ||
|
||
part 'generate_hint_response_dto.g.dart'; | ||
|
||
/// {@template generate_hint_response_dto} | ||
/// A DTO to receive [GenerateHintResponse] object wrapped within `data` | ||
/// from the generate hint http request. | ||
/// {@endtemplate} | ||
@immutable | ||
@JsonSerializable() | ||
class GenerateHintResponseDto extends Equatable { | ||
/// {@macro generate_hint_response_dto} | ||
const GenerateHintResponseDto({ | ||
required this.result, | ||
}); | ||
|
||
/// Converts a [Map] json into a [GenerateHintResponseDto] instance. | ||
factory GenerateHintResponseDto.fromJson(Map<String, dynamic> json) => | ||
_$GenerateHintResponseDtoFromJson(json); | ||
|
||
/// The result to be received over via http. | ||
final GenerateHintResponse result; | ||
|
||
@override | ||
List<Object?> get props => [result]; | ||
} | ||
|
||
/// {@template generate_hint_response} | ||
/// Model for the generate hint http response. | ||
/// {@endtemplate} | ||
@immutable | ||
@JsonSerializable() | ||
class GenerateHintResponse extends Equatable { | ||
/// {@macro generate_hint_response} | ||
const GenerateHintResponse({ | ||
required this.cell, | ||
required this.entry, | ||
required this.observation, | ||
required this.explanation, | ||
required this.solution, | ||
}); | ||
|
||
/// Converts a [Map] into a [GenerateHintResponse] instance. | ||
factory GenerateHintResponse.fromJson(Map<String, dynamic> json) => | ||
_$GenerateHintResponseFromJson(json); | ||
|
||
/// The position of the cell. | ||
final List<int> cell; | ||
|
||
/// The number to be put in the cell. | ||
final int entry; | ||
|
||
/// The observation of the puzzle state for solving the cell. | ||
final String observation; | ||
|
||
/// Explanation of the puzzle, and how to determine the solution. | ||
final String explanation; | ||
|
||
/// The solution of the puzzle in a sentence. | ||
final String solution; | ||
|
||
/// Converts the [GenerateHintResponse] to [Hint]. | ||
Hint toHint() { | ||
return Hint( | ||
cell: Position(x: cell[0], y: cell[1]), | ||
entry: entry, | ||
observation: observation, | ||
explanation: explanation, | ||
solution: solution, | ||
); | ||
} | ||
|
||
@override | ||
List<Object?> get props => [ | ||
cell, | ||
entry, | ||
observation, | ||
explanation, | ||
solution, | ||
]; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:sudoku/models/models.dart'; | ||
|
||
/// {@template hint} | ||
/// Model for a sudoku puzzle hint. | ||
/// {@endtemplate} | ||
@immutable | ||
class Hint extends Equatable { | ||
/// {@macro hint} | ||
const Hint({ | ||
required this.cell, | ||
required this.entry, | ||
required this.observation, | ||
required this.explanation, | ||
required this.solution, | ||
}); | ||
|
||
/// Defines the position or the cell for the hint. | ||
final Position cell; | ||
|
||
/// The number to be put in the cell. | ||
final int entry; | ||
|
||
/// The observation of the puzzle state for solving the cell. | ||
final String observation; | ||
|
||
/// Explanation of the puzzle, and how to determine the solution. | ||
final String explanation; | ||
|
||
/// The solution of the puzzle in a sentence. | ||
final String solution; | ||
|
||
@override | ||
List<Object?> get props => [ | ||
cell, | ||
entry, | ||
observation, | ||
explanation, | ||
solution, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.