added quote flag types, updated mappings
This commit is contained in:
parent
15e03d1e20
commit
4df9f3ad08
@ -7,6 +7,10 @@ namespace VideoGameQuotes.Api {
|
||||
public class Game : Entity<Game, int> {
|
||||
private readonly Iesi.Collections.Generic.ISet<System> systems = new HashedSet<System>();
|
||||
|
||||
public Game() {
|
||||
Created = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public virtual User Creator { get; set; }
|
||||
public virtual DateTime Created { get; set; }
|
||||
public virtual IEnumerable<System> Systems { get { return systems; } }
|
||||
|
@ -14,7 +14,7 @@
|
||||
<many-to-one name="Creator" column="creator" not-null="true" foreign-key="fk_game_user"/>
|
||||
<many-to-one name="Publisher" column="publisher_id" not-null="false" foreign-key="fk_game_publisher" />
|
||||
|
||||
<set access="field" name="systems" table="game_system_map" cascade="all-delete-orphan">
|
||||
<set access="field" name="systems" table="game_system_map" cascade="save-update">
|
||||
<key column="game_id" />
|
||||
<many-to-many class="System" column="system_id" />
|
||||
</set>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="VideoGameQuotes.Api" namespace="VideoGameQuotes.Api">
|
||||
|
||||
<class name="Quote" table="quote">
|
||||
<class name="Quote" table="game_quote">
|
||||
<id column="quote_id" name="Id" type="int">
|
||||
<generator class="identity" />
|
||||
</id>
|
||||
@ -13,12 +13,12 @@
|
||||
<many-to-one name="Creator" column="creator" not-null="true" foreign-key="fk_quote_user"/>
|
||||
<many-to-one name="Game" column="game_id" not-null="true" foreign-key="fk_quote_game" />
|
||||
|
||||
<set access="field" name="votes" table="vote" cascade="all-delete-orphan">
|
||||
<set access="field" name="votes" table="vote" cascade="save-update">
|
||||
<key column="quote_id" />
|
||||
<one-to-many class="Vote" />
|
||||
</set>
|
||||
|
||||
<set access="field" name="flags" table="quote_flag" cascade="all-delete-orphan">
|
||||
<set access="field" name="flags" table="quote_flag" cascade="save-update">
|
||||
<key column="quote_id" />
|
||||
<one-to-many class="QuoteFlag" />
|
||||
</set>
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
<property name="Comment" column="flag_comment" not-null="false" length="1024" />
|
||||
<property name="Created" column="created" not-null="true" />
|
||||
<property name="Type" column="flag_type" not-null="true" type="int" />
|
||||
|
||||
<many-to-one name="User" column="user_id" not-null="true" foreign-key="fk_flag_user"/>
|
||||
<many-to-one name="Quote" column="quote_id" not-null="true" foreign-key="fk_flag_quote" />
|
||||
|
@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="VideoGameQuotes.Api" namespace="VideoGameQuotes.Api">
|
||||
|
||||
<class name="User" table="user">
|
||||
<class name="User" table="vgquote_user">
|
||||
<id column="user_id" name="Id" type="int">
|
||||
<generator class="identity" />
|
||||
</id>
|
||||
|
||||
<property name="Username" column="username" not-null="true" type="string" length="50"/>
|
||||
<property name="Username" column="username" not-null="true" type="string" length="50" unique="true"/>
|
||||
<property name="Created" column="created" not-null="true" type="DateTime" />
|
||||
<property name="Group" column="user_group" not-null="true" />
|
||||
|
||||
<component name="passwordProtector" access="field" class="Portoa.Security.NullAllowingPasswordProtector, Portoa">
|
||||
<property name="Password" column="password" not-null="false" length="100" />
|
||||
<property name="Password" column="user_password" not-null="false" length="100" />
|
||||
<property name="Salt" column="salt" not-null="false" length="100" />
|
||||
</component>
|
||||
</class>
|
||||
|
@ -3,6 +3,10 @@ using Portoa.Persistence;
|
||||
|
||||
namespace VideoGameQuotes.Api {
|
||||
public class Publisher : Entity<Publisher, int> {
|
||||
public Publisher() {
|
||||
Created = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public virtual string Name { get; set; }
|
||||
public virtual string Website { get; set; }
|
||||
public virtual DateTime Created { get; set; }
|
||||
|
@ -9,6 +9,10 @@ namespace VideoGameQuotes.Api {
|
||||
private readonly Iesi.Collections.Generic.ISet<Vote> votes = new HashedSet<Vote>();
|
||||
private readonly Iesi.Collections.Generic.ISet<QuoteFlag> flags = new HashedSet<QuoteFlag>();
|
||||
|
||||
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 });
|
||||
|
@ -3,9 +3,15 @@ using Portoa.Persistence;
|
||||
|
||||
namespace VideoGameQuotes.Api {
|
||||
public class QuoteFlag : Entity<QuoteFlag, int> {
|
||||
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; }
|
||||
}
|
||||
}
|
8
Src/VideoGameQuotes.Api/QuoteFlagType.cs
Normal file
8
Src/VideoGameQuotes.Api/QuoteFlagType.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace VideoGameQuotes.Api {
|
||||
public enum QuoteFlagType {
|
||||
Inaccurate = 1,
|
||||
Spam = 2,
|
||||
Fake = 3,
|
||||
Other = 4
|
||||
}
|
||||
}
|
@ -3,6 +3,10 @@ using Portoa.Persistence;
|
||||
|
||||
namespace VideoGameQuotes.Api {
|
||||
public class System : Entity<System, int> {
|
||||
public System() {
|
||||
Created = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public virtual DateTime Created { get; set; }
|
||||
public virtual DateTime ReleaseDate { get; set; }
|
||||
public virtual string Name { get; set; }
|
||||
|
@ -7,6 +7,10 @@ namespace VideoGameQuotes.Api {
|
||||
public class User : Entity<User, int>, 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; }
|
||||
|
@ -43,6 +43,9 @@
|
||||
<Reference Include="NHibernate">
|
||||
<HintPath>..\..\Lib\NHibernate.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NHibernate.ByteCode.LinFu">
|
||||
<HintPath>..\..\Lib\NHibernate.ByteCode.LinFu.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NHibernate.Linq">
|
||||
<HintPath>..\..\Lib\NHibernate.Linq.dll</HintPath>
|
||||
</Reference>
|
||||
@ -67,6 +70,7 @@
|
||||
<Compile Include="Publisher.cs" />
|
||||
<Compile Include="Quote.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="QuoteFlagType.cs" />
|
||||
<Compile Include="Region.cs" />
|
||||
<Compile Include="System.cs" />
|
||||
<Compile Include="User.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<User>(session).Save(admin);
|
||||
tx.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
189
Tests/VideoGameQuotes.Api.Tests/NHibernate/schema.sql
Normal file
189
Tests/VideoGameQuotes.Api.Tests/NHibernate/schema.sql
Normal file
@ -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);
|
@ -38,12 +38,16 @@
|
||||
<HintPath>..\..\Lib\MySql.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4, processorArchitecture=MSIL" />
|
||||
<Reference Include="NHibernate.ByteCode.LinFu">
|
||||
<HintPath>..\..\Lib\NHibernate.ByteCode.LinFu.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\..\Lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Portoa">
|
||||
<HintPath>..\..\Lib\Portoa.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Portoa.NHibernate, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@ -66,6 +70,9 @@
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="NHibernate\hibernate.cfg.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="NHibernate\schema.sql" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
Loading…
Reference in New Issue
Block a user