Commit 3795f75d authored by Hephi2's avatar Hephi2
Browse files

Deleted unnecessary code

parent 3c6efb7d
Pipeline #628393 failed with stage
in 1 minute and 29 seconds
import 'dart:convert';
List<Artwork> modelFromJson(String str, String apiLink) => List<Artwork>.from(
json.decode(str).map(
(x) => Artwork.fromJson(x, apiLink),
),
);
String modelToJson(List<Artwork> data) => json.encode(
List<dynamic>.from(
data.map(
(x) => x.toJson(),
),
),
);
/// An abstract display of artwork
class Artwork {
//***************************************************
//****** class Attributes **********
//***************************************************
/// A flag indicating whether the audio source is valid
final bool hasValidAudio;
/// A flag indicating whether the video source is valid
final bool hasValidVideo;
/// unique identifier
final String id;
/// A flag indicating whether this art is favourite or not
bool isFavourite;
/// the time of the Exhibition
String? timeOfExhibition;
/// the name of the work of art
final String name;
/// year of origin
int? year;
/// artwork type
String? type;
/// artist name
String? artistName;
/// artist's year of birth and death
String? lebensDaten;
/// information about the material
String? material;
/// information about the artwork location
String? locationInfo;
/// artwork location info
String? address;
/// artwork address
String? locationStreet;
/// location on campus
String? locationCampus;
/// X navigation coordinations
double? navX;
/// Y navigation coordinations
double? navY;
/// unique nr of Artwork
final int nr;
/// description
String? description;
/// information about the artist
String? artistInfo;
/// ID of the exhibition this artworks belongs to
String? exhibitionID;
/// a list containing keys/links of the images on the server
List<String>? images = [];
/// a list containing keys/links of the audio files on the server
List<String>? audio = [];
/// a list containing keys/links of the videos on the server
List<String>? videos = [];
//***************************************************
//****** Constructor *********
//***************************************************
Artwork(
{required this.id,
required this.nr,
this.timeOfExhibition,
required this.name,
this.hasValidAudio = false,
this.hasValidVideo = false,
this.year,
this.type,
this.artistName,
this.lebensDaten,
this.material,
this.locationInfo,
this.address,
this.locationStreet,
this.locationCampus,
this.navX,
this.navY,
this.description,
this.artistInfo,
this.exhibitionID,
this.images,
this.audio,
this.videos,
this.isFavourite = false});
factory Artwork.fromJson(Map<String, dynamic> json, String apiLink) {
//fetch image links
//List<String> imageLinks = ['https://picsum.photos/500/300'];
List<dynamic> imageLinksResponse = json['image']['key'];
List<String> imageLinks = ["-1"];
if (imageLinksResponse.isNotEmpty) {
imageLinks = imageLinksResponse.fold(<String>[],
(List<String>? previousValue, dynamic element) {
previousValue!.add(apiLink + element);
return previousValue;
});
}
//fetch audio links
List<String> audioLinks = ["-1"];
bool hasValidAudio = false;
Map<String, dynamic> audioResponse = json['audio'] ?? {};
if (audioResponse.isNotEmpty) {
List<dynamic> audioLinksResponse = audioResponse['key'];
if (audioLinksResponse.isNotEmpty) {
audioLinks = audioLinksResponse.fold(<String>[],
(List<String>? previousValue, dynamic element) {
previousValue!.add(apiLink + element);
return previousValue;
});
hasValidAudio = true;
}
}
//fetch video links
Map<String, dynamic> videoResponse = json['video'] ?? {};
bool hasValidVideo = false;
List<String> videoLinks = ["-1"];
if (videoResponse.isNotEmpty) {
List<dynamic> videoLinksResponse = videoResponse['key'];
if (videoLinksResponse.isNotEmpty) {
videoLinks = videoLinksResponse.fold(<String>[],
(List<String>? previousValue, dynamic element) {
previousValue!.add(apiLink + element);
return previousValue;
});
hasValidVideo = true;
}
}
return Artwork(
id: json['_id'] ?? "",
nr: json['Nummerierung'] ?? -1,
timeOfExhibition: json['zeitpunktDerAusstellung'] ?? "",
name: json['kunstwerksname'] ?? "",
hasValidAudio: hasValidAudio,
hasValidVideo: hasValidVideo,
year: json['entstehungsjahr'] ?? -1,
type: json['kunstwerksart'] ?? "",
artistName: json['kuenstlerin'] ?? "",
lebensDaten: json['lebensdaten'] ?? "",
material: json['materialinfo'] ?? "",
locationInfo: json['WieAnDieTU'] ?? "",
address: json['standortLageinfo'] ?? "",
locationStreet: json['standortStrasse'] ?? "",
locationCampus: json['standortCampus'] ?? "",
navX: json['standortKarteBreitengrad'] ?? -1.0,
navY: json['standortKarteLaengengrad'] ?? -1.0,
description: json['werkinfos'] ?? "",
artistInfo: json['kuenstlerinfos'] ?? "",
exhibitionID: json['Ausstellung'] ?? "",
images: imageLinks,
audio: audioLinks,
videos: videoLinks);
}
Map toJson() => {
'id': id,
'Nummerierung': nr,
timeOfExhibition: timeOfExhibition,
'name': name,
'year': year,
'type': type,
'artistName': artistName,
'lebensDaten': lebensDaten,
'material': material,
'locationInfo': locationInfo,
'address': address,
'locationStreet': locationStreet,
'locationCampus': locationCampus,
'navX': navX,
'navY': navY,
'description': description,
'artistInfo': artistInfo,
'exhibition': exhibitionID,
};
}
......@@ -15,18 +15,6 @@ class Collection {
{required this.count, this.next, this.previous, required this.results});
factory Collection.fromJson(Map<String, dynamic> json) {
//List<dynamic> resultList = json["results"].cast<Map<String,dynamic>>();
//List<Map<String,dynamic>> results = resultList.map((e) => e as Map<String,dynamic>).toList();
/*Map<String,dynamic> valueMap;
for (var value in resultList) {
print(value.toString());
valueMap = value;
results.add(valueMap);
}
resultList.map((e) => null);
*/
return Collection(
count: json["count"],
next: json["next"],
......
......@@ -71,34 +71,4 @@ class Exhibition {
(json["end_date"] * 1000).round()),
artworkCount: json["artwork_count"]);
}
// add one artwork to the list
void addArtwork(int value) {
artworkList.add(value);
}
//remove one artwork from the list
void removeArtwork(int value) {
artworkList.remove(value);
}
//sort artworks by name
/*void sortByName() {
artworkList.sort((a, b) => a.name.compareTo(b.name));
}*/
//sort artworks by creation year
/*void sortByYear() {
artworkList.sort((a, b) => a.year!.compareTo(b.year!));
}*/
// returns a map of artworks grouped by exhibition (Ausstellung)
/*Map groupArtworksByExhibitions() {
var result = Map<String, List>();
for (var e in artworkList) {
var list = result.putIfAbsent(e.exhibitionID!, () => []);
list.add(e);
}
return result;
}*/
}
......@@ -5,93 +5,5 @@ import 'package:kunstforum_tu_darmstadt/models/exhibition.dart';
//this is a Flutter models test to verify creation of objects and data manipulation
void main() {
test('an artwort object must be created, new values must match', () {
var artwork = Artwork(
id: 'id1',
nr: 0,
name: 'name',
year: 2020,
type: 'type',
artistName: 'artistName',
lebensDaten: 'yearOfBirthAndDead',
material: 'material',
locationInfo: 'locationInfo',
address: 'address',
locationCampus: 'locationCampus',
navX: 50.1,
navY: 40.1,
description: 'text1',
artistInfo: 'kuenstlerinfos1',
exhibitionID: 'ausstellung1');
String json = jsonEncode(artwork);
final string =
'{"id":"id1","name":"name","year":2020,"type":"type","artistName":"artistName","yearOfBirthAndDead":"yearOfBirthAndDead","material":"material","locationInfo":"locationInfo","address":"address","locationCampus":"locationCampus","navX":50.1,"navY":40.1,"description":"text1","artistInfo":"kuenstlerinfos1","exhibition":"ausstellung1"}';
expect(json, string);
expect(artwork.name, "name");
});
test('adding and sorting artworks to a list', () {
var artwork1 = Artwork(
id: 'id1',
nr: 1,
name: 'name',
year: 2020,
type: 'type',
artistName: 'artistName',
lebensDaten: 'yearOfBirthAndDead',
material: 'material',
locationInfo: 'locationInfo',
address: 'address',
locationCampus: 'locationCampus',
navX: 50.1,
navY: 40.1,
description: 'text1',
artistInfo: 'kuenstlerinfos1',
exhibitionID: 'ausstellung1');
var artwork2 = Artwork(
id: 'id12',
nr: 3,
name: 'name12',
year: 2020,
type: 'type12',
artistName: 'artistName12',
lebensDaten: 'yearOfBirthAndDead12',
material: 'material12',
locationInfo: 'locationInfo12',
address: 'address12',
locationCampus: 'locationCampus12',
navX: 50.1,
navY: 40.1,
description: 'text12',
artistInfo: 'kuenstlerinfos12',
exhibitionID: 'ausstellung12');
var artwork3 = Artwork(
id: 'id13',
nr: 2,
name: 'name13',
year: 2020,
type: 'type13',
artistName: 'artistName13',
lebensDaten: 'yearOfBirthAndDead13',
material: 'material13',
locationInfo: 'locationInfo13',
address: 'address13',
locationCampus: 'locationCampus13',
navX: 50.1,
navY: 40.1,
description: 'text13',
artistInfo: 'kuenstlerinfos13',
exhibitionID: 'ausstellung13');
var artworks = Exhibition(id: "1", name: "test", hasLocalImage: false);
artworks.addArtwork(artwork1);
artworks.addArtwork(artwork2);
artworks.addArtwork(artwork3);
expect(artworks.artworkList.length, 3);
expect(artworks.artworkList.first.name, "kunstwerksname1");
artworks.sortByYear();
expect(artworks.artworkList.first.year, 2000);
});
//TODO: We don't need the functionality that was tested. Should we test something else?
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment