From 4df9f3ad0890378bb9895f913ba058b819f236c4 Mon Sep 17 00:00:00 2001 From: tmont Date: Wed, 9 Feb 2011 03:41:35 +0000 Subject: [PATCH] added quote flag types, updated mappings --- Src/VideoGameQuotes.Api/Game.cs | 4 + Src/VideoGameQuotes.Api/Mappings/Game.hbm.xml | 2 +- .../Mappings/Quote.hbm.xml | 6 +- .../Mappings/QuoteFlag.hbm.xml | 1 + Src/VideoGameQuotes.Api/Mappings/User.hbm.xml | 6 +- Src/VideoGameQuotes.Api/Publisher.cs | 4 + Src/VideoGameQuotes.Api/Quote.cs | 5 + Src/VideoGameQuotes.Api/QuoteFlag.cs | 6 + Src/VideoGameQuotes.Api/QuoteFlagType.cs | 8 + Src/VideoGameQuotes.Api/System.cs | 4 + Src/VideoGameQuotes.Api/User.cs | 4 + .../VideoGameQuotes.Api.csproj | 4 + .../NHibernate/SchemaExporter.cs | 34 +++- .../NHibernate/schema.sql | 189 ++++++++++++++++++ .../VideoGameQuotes.Api.Tests.csproj | 7 + 15 files changed, 271 insertions(+), 13 deletions(-) create mode 100644 Src/VideoGameQuotes.Api/QuoteFlagType.cs create mode 100644 Tests/VideoGameQuotes.Api.Tests/NHibernate/schema.sql diff --git a/Src/VideoGameQuotes.Api/Game.cs b/Src/VideoGameQuotes.Api/Game.cs index 547e3b8..c1b84a8 100644 --- a/Src/VideoGameQuotes.Api/Game.cs +++ b/Src/VideoGameQuotes.Api/Game.cs @@ -7,6 +7,10 @@ namespace VideoGameQuotes.Api { public class Game : Entity { private readonly Iesi.Collections.Generic.ISet systems = new HashedSet(); + public Game() { + Created = DateTime.UtcNow; + } + public virtual User Creator { get; set; } public virtual DateTime Created { get; set; } public virtual IEnumerable Systems { get { return systems; } } diff --git a/Src/VideoGameQuotes.Api/Mappings/Game.hbm.xml b/Src/VideoGameQuotes.Api/Mappings/Game.hbm.xml index f0e523d..65d52c3 100644 --- a/Src/VideoGameQuotes.Api/Mappings/Game.hbm.xml +++ b/Src/VideoGameQuotes.Api/Mappings/Game.hbm.xml @@ -14,7 +14,7 @@ - + diff --git a/Src/VideoGameQuotes.Api/Mappings/Quote.hbm.xml b/Src/VideoGameQuotes.Api/Mappings/Quote.hbm.xml index 0361b5f..bceed6c 100644 --- a/Src/VideoGameQuotes.Api/Mappings/Quote.hbm.xml +++ b/Src/VideoGameQuotes.Api/Mappings/Quote.hbm.xml @@ -1,7 +1,7 @@  - + @@ -13,12 +13,12 @@ - + - + diff --git a/Src/VideoGameQuotes.Api/Mappings/QuoteFlag.hbm.xml b/Src/VideoGameQuotes.Api/Mappings/QuoteFlag.hbm.xml index e522033..f6b1d6c 100644 --- a/Src/VideoGameQuotes.Api/Mappings/QuoteFlag.hbm.xml +++ b/Src/VideoGameQuotes.Api/Mappings/QuoteFlag.hbm.xml @@ -8,6 +8,7 @@ + diff --git a/Src/VideoGameQuotes.Api/Mappings/User.hbm.xml b/Src/VideoGameQuotes.Api/Mappings/User.hbm.xml index 1cec489..f63b269 100644 --- a/Src/VideoGameQuotes.Api/Mappings/User.hbm.xml +++ b/Src/VideoGameQuotes.Api/Mappings/User.hbm.xml @@ -1,17 +1,17 @@  - + - + - + diff --git a/Src/VideoGameQuotes.Api/Publisher.cs b/Src/VideoGameQuotes.Api/Publisher.cs index c63c0a3..3c7b4e8 100644 --- a/Src/VideoGameQuotes.Api/Publisher.cs +++ b/Src/VideoGameQuotes.Api/Publisher.cs @@ -3,6 +3,10 @@ using Portoa.Persistence; namespace VideoGameQuotes.Api { public class Publisher : Entity { + public Publisher() { + Created = DateTime.UtcNow; + } + public virtual string Name { get; set; } public virtual string Website { get; set; } public virtual DateTime Created { get; set; } diff --git a/Src/VideoGameQuotes.Api/Quote.cs b/Src/VideoGameQuotes.Api/Quote.cs index b63022b..a19576f 100644 --- a/Src/VideoGameQuotes.Api/Quote.cs +++ b/Src/VideoGameQuotes.Api/Quote.cs @@ -9,6 +9,10 @@ namespace VideoGameQuotes.Api { private readonly Iesi.Collections.Generic.ISet votes = new HashedSet(); private readonly Iesi.Collections.Generic.ISet flags = new HashedSet(); + public Quote() { + Created = DateTime.UtcNow; + } + public virtual User Creator { get; set; } public virtual DateTime Created { get; set; } public virtual DateTime? Modified { get; set; } @@ -28,6 +32,7 @@ namespace VideoGameQuotes.Api { votes.Remove(currentVote); currentVote.Direction = direction; + currentVote.Created = DateTime.UtcNow; votes.Add(currentVote); } else { votes.Add(new Vote { Direction = direction, Quote = this, Voter = user }); diff --git a/Src/VideoGameQuotes.Api/QuoteFlag.cs b/Src/VideoGameQuotes.Api/QuoteFlag.cs index 6a007a5..39cb721 100644 --- a/Src/VideoGameQuotes.Api/QuoteFlag.cs +++ b/Src/VideoGameQuotes.Api/QuoteFlag.cs @@ -3,9 +3,15 @@ using Portoa.Persistence; namespace VideoGameQuotes.Api { public class QuoteFlag : Entity { + public QuoteFlag() { + Created = DateTime.UtcNow; + Type = QuoteFlagType.Other; + } + public virtual User User { get; set; } public virtual Quote Quote { get; set; } public virtual DateTime Created { get; set; } public virtual string Comment { get; set; } + public virtual QuoteFlagType Type { get; set; } } } \ No newline at end of file diff --git a/Src/VideoGameQuotes.Api/QuoteFlagType.cs b/Src/VideoGameQuotes.Api/QuoteFlagType.cs new file mode 100644 index 0000000..56bb1fc --- /dev/null +++ b/Src/VideoGameQuotes.Api/QuoteFlagType.cs @@ -0,0 +1,8 @@ +namespace VideoGameQuotes.Api { + public enum QuoteFlagType { + Inaccurate = 1, + Spam = 2, + Fake = 3, + Other = 4 + } +} \ No newline at end of file diff --git a/Src/VideoGameQuotes.Api/System.cs b/Src/VideoGameQuotes.Api/System.cs index 6373781..9539304 100644 --- a/Src/VideoGameQuotes.Api/System.cs +++ b/Src/VideoGameQuotes.Api/System.cs @@ -3,6 +3,10 @@ using Portoa.Persistence; namespace VideoGameQuotes.Api { public class System : Entity { + public System() { + Created = DateTime.UtcNow; + } + public virtual DateTime Created { get; set; } public virtual DateTime ReleaseDate { get; set; } public virtual string Name { get; set; } diff --git a/Src/VideoGameQuotes.Api/User.cs b/Src/VideoGameQuotes.Api/User.cs index e86906a..f1cdb5b 100644 --- a/Src/VideoGameQuotes.Api/User.cs +++ b/Src/VideoGameQuotes.Api/User.cs @@ -7,6 +7,10 @@ namespace VideoGameQuotes.Api { public class User : Entity, IPasswordProtected { private readonly IPasswordProtected passwordProtector = new NullAllowingPasswordProtector(); + public User() { + Created = DateTime.UtcNow; + } + public virtual DateTime Created { get; set; } public virtual string Username { get; set; } public virtual UserGroup Group { get; set; } diff --git a/Src/VideoGameQuotes.Api/VideoGameQuotes.Api.csproj b/Src/VideoGameQuotes.Api/VideoGameQuotes.Api.csproj index f93bba5..d3083b0 100644 --- a/Src/VideoGameQuotes.Api/VideoGameQuotes.Api.csproj +++ b/Src/VideoGameQuotes.Api/VideoGameQuotes.Api.csproj @@ -43,6 +43,9 @@ ..\..\Lib\NHibernate.dll + + ..\..\Lib\NHibernate.ByteCode.LinFu.dll + ..\..\Lib\NHibernate.Linq.dll @@ -67,6 +70,7 @@ + diff --git a/Tests/VideoGameQuotes.Api.Tests/NHibernate/SchemaExporter.cs b/Tests/VideoGameQuotes.Api.Tests/NHibernate/SchemaExporter.cs index 68390d6..1b51b44 100644 --- a/Tests/VideoGameQuotes.Api.Tests/NHibernate/SchemaExporter.cs +++ b/Tests/VideoGameQuotes.Api.Tests/NHibernate/SchemaExporter.cs @@ -1,18 +1,40 @@ using NHibernate.Cfg; using NHibernate.Tool.hbm2ddl; using NUnit.Framework; +using Portoa.NHibernate; namespace VideoGameQuotes.Api.Tests.NHibernate { - [TestFixture] + [TestFixture, Ignore] public class SchemaExporter { [Test] public void Export_schema() { - var config = new Configuration(); - config.Configure(GetType().Assembly, GetType().Namespace + ".hibernate.cfg.xml"); - new SchemaExport(config) - //.SetOutputFile(@"c:\users\tmont\code\VideoGameQuotes\schema.sql") - .Execute(true, true, false); + new SchemaExport(GetConfig()) + .SetDelimiter(";") + .SetOutputFile(@"c:\users\tmont\code\VideoGameQuotes\Tests\VideoGameQuotes.Api.Tests\NHibernate\schema.sql") + .Execute(false, true, false); + } + + private Configuration GetConfig() { + return new Configuration().Configure(GetType().Assembly, GetType().Namespace + ".hibernate.cfg.xml"); + } + + [Test] + public void Create_admin() { + var config = GetConfig(); + + var admin = new User { + Username = "admin", + Group = UserGroup.Admin + }; + + admin.ChangePassword("password"); + + var session = config.BuildSessionFactory().OpenSession(); + using (var tx = session.BeginTransaction()) { + new NHibernateRepository(session).Save(admin); + tx.Commit(); + } } } diff --git a/Tests/VideoGameQuotes.Api.Tests/NHibernate/schema.sql b/Tests/VideoGameQuotes.Api.Tests/NHibernate/schema.sql new file mode 100644 index 0000000..5fe656e --- /dev/null +++ b/Tests/VideoGameQuotes.Api.Tests/NHibernate/schema.sql @@ -0,0 +1,189 @@ + + +alter table vote drop foreign key fk_vote_user +; + + +alter table vote drop foreign key fk_vote_quote +; + + +alter table game drop foreign key fk_game_user +; + + +alter table game drop foreign key fk_game_publisher +; + + +alter table game_system_map drop foreign key FK5B40970FD86811D9 +; + + +alter table game_system_map drop foreign key FK5B40970FD968AB11 +; + + +alter table quote_flag drop foreign key fk_flag_user +; + + +alter table quote_flag drop foreign key fk_flag_quote +; + + +alter table game_quote drop foreign key fk_quote_user +; + + +alter table game_quote drop foreign key fk_quote_game +; + + drop table if exists vote; + + drop table if exists game; + + drop table if exists game_system_map; + + drop table if exists publisher; + + drop table if exists system; + + drop table if exists vgquote_user; + + drop table if exists quote_flag; + + drop table if exists game_quote; + + create table vote ( + vote_id INTEGER NOT NULL AUTO_INCREMENT, + created DATETIME not null, + direction INTEGER not null, + voter_id INTEGER not null, + quote_id INTEGER not null, + primary key (vote_id) + ); + + create table game ( + game_id INTEGER NOT NULL AUTO_INCREMENT, + game_name TEXT not null, + created DATETIME not null, + screenshot BLOB, + game_region INTEGER not null, + creator INTEGER not null, + publisher_id INTEGER, + primary key (game_id) + ); + + create table game_system_map ( + game_id INTEGER not null, + system_id INTEGER not null, + primary key (game_id, system_id) + ); + + create table publisher ( + publisher_id INTEGER NOT NULL AUTO_INCREMENT, + publisher_name TEXT not null, + website TEXT, + created DATETIME not null, + primary key (publisher_id) + ); + + create table system ( + system_id INTEGER NOT NULL AUTO_INCREMENT, + system_name TEXT not null, + system_abbreviation VARCHAR(12), + created DATETIME not null, + release_date DATETIME, + primary key (system_id) + ); + + create table vgquote_user ( + user_id INTEGER NOT NULL AUTO_INCREMENT, + username VARCHAR(50) not null unique, + created DATETIME not null, + user_group INTEGER not null, + user_password VARCHAR(100), + salt VARCHAR(100), + primary key (user_id) + ); + + create table quote_flag ( + quote_flag_id INTEGER NOT NULL AUTO_INCREMENT, + flag_comment TEXT, + created DATETIME not null, + flag_type INTEGER not null, + user_id INTEGER not null, + quote_id INTEGER not null, + primary key (quote_flag_id) + ); + + create table game_quote ( + quote_id INTEGER NOT NULL AUTO_INCREMENT, + quote_text TEXT not null, + created DATETIME not null, + modified DATETIME, + creator INTEGER not null, + game_id INTEGER not null, + primary key (quote_id) + ); + + alter table vote + add index (voter_id), + add constraint fk_vote_user + foreign key (voter_id) + references vgquote_user (user_id); + + alter table vote + add index (quote_id), + add constraint fk_vote_quote + foreign key (quote_id) + references game_quote (quote_id); + + alter table game + add index (creator), + add constraint fk_game_user + foreign key (creator) + references vgquote_user (user_id); + + alter table game + add index (publisher_id), + add constraint fk_game_publisher + foreign key (publisher_id) + references publisher (publisher_id); + + alter table game_system_map + add index (system_id), + add constraint FK5B40970FD86811D9 + foreign key (system_id) + references system (system_id); + + alter table game_system_map + add index (game_id), + add constraint FK5B40970FD968AB11 + foreign key (game_id) + references game (game_id); + + alter table quote_flag + add index (user_id), + add constraint fk_flag_user + foreign key (user_id) + references vgquote_user (user_id); + + alter table quote_flag + add index (quote_id), + add constraint fk_flag_quote + foreign key (quote_id) + references game_quote (quote_id); + + alter table game_quote + add index (creator), + add constraint fk_quote_user + foreign key (creator) + references vgquote_user (user_id); + + alter table game_quote + add index (game_id), + add constraint fk_quote_game + foreign key (game_id) + references game (game_id); diff --git a/Tests/VideoGameQuotes.Api.Tests/VideoGameQuotes.Api.Tests.csproj b/Tests/VideoGameQuotes.Api.Tests/VideoGameQuotes.Api.Tests.csproj index cbfd208..8ab8572 100644 --- a/Tests/VideoGameQuotes.Api.Tests/VideoGameQuotes.Api.Tests.csproj +++ b/Tests/VideoGameQuotes.Api.Tests/VideoGameQuotes.Api.Tests.csproj @@ -38,12 +38,16 @@ ..\..\Lib\MySql.Data.dll + + ..\..\Lib\NHibernate.ByteCode.LinFu.dll + ..\..\Lib\nunit.framework.dll ..\..\Lib\Portoa.dll + @@ -66,6 +70,9 @@ + + +