This PR closes #69 . (Sorry for the massive PR again)
I added a new file common/link.go for the new Link struct. This struct resembles the idea discussed in #69 :
type Link struct {
Id int
Type string
Url string
IsSource bool
}
This struct also got a new Function called l.DetermineType() string {...} which looks the URL of the link struct and tries to determine the origin (IMDb or MyAnimeList) and returns the determined type.
I also added 4 new functions to the connector interface, namely AddTag, FindTag, GetTag, DeleteTag for the usual CRUD functionality. Of course i also implemented these Functions in the JSON Connector ready to use.
I also adapted the Movie struct to work with the Link struct as well as all the logic in server.go.
For Backwards compatibility of the database i also provide a migration Script cmd/migrateLinks.go which parses the data json file from the previous versions and converts the old Movie objects to new ones which use the Link struct described above.
For my own sanity i used an external library to not go insane trying to parse the old json format (i really hate the way go handles json in the standard library).
In a nutshell the script parses the old json data - deletes the movie map after saving it into ram and creates a temporary file. Afterwards the dataconnector is used to open this temporary file and add the new movies based on the old movies while also populating the new Link map.
Lastly i adapted the movie-info.html template to make use of the new fields introduced with the Link struct.
This PR closes #69 . (Sorry for the massive PR again)
I added a new file common/link.go for the new Link struct. This struct resembles the idea discussed in #69 :
This struct also got a new Function called
l.DetermineType() string {...}
which looks the URL of the link struct and tries to determine the origin (IMDb or MyAnimeList) and returns the determined type.I also added 4 new functions to the connector interface, namely AddTag, FindTag, GetTag, DeleteTag for the usual CRUD functionality. Of course i also implemented these Functions in the JSON Connector ready to use. I also adapted the Movie struct to work with the Link struct as well as all the logic in
server.go
.For Backwards compatibility of the database i also provide a migration Script
cmd/migrateLinks.go
which parses the data json file from the previous versions and converts the old Movie objects to new ones which use the Link struct described above. For my own sanity i used an external library to not go insane trying to parse the old json format (i really hate the way go handles json in the standard library). In a nutshell the script parses the old json data - deletes the movie map after saving it into ram and creates a temporary file. Afterwards the dataconnector is used to open this temporary file and add the new movies based on the old movies while also populating the new Link map.Lastly i adapted the movie-info.html template to make use of the new fields introduced with the Link struct.