-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
institution membership dlpsDeleted flag check
- Loading branch information
1 parent
c79644c
commit 5a8455d
Showing
5 changed files
with
200 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module Lauth | ||
module Repositories | ||
class InstitutionMembershipRepo < ROM::Repository[:institution_memberships] | ||
include Deps[container: "persistence.rom"] | ||
struct_namespace Lauth | ||
# auto_struct true | ||
# commands :create, update: :by_pk, delete: :by_pk | ||
|
||
def index | ||
undeleted_institution_memberships.to_a | ||
end | ||
|
||
def create(document) | ||
document = Hanami::Utils::Hash.deep_symbolize(document) | ||
user_id = document[:data][:attributes][:user_id] | ||
institution_id = document[:data][:attributes][:institution_id] | ||
institution_membership = undeleted_institution_memberships.where(userid: user_id, inst: institution_id).one | ||
return nil if institution_membership | ||
|
||
if deleted_institution_memberships.where(userid: user_id, inst: institution_id).one | ||
deleted_institution_memberships.where(userid: user_id, inst: institution_id).changeset(Lauth::Persistence::Changesets::InstitutionMembershipUpdate, document).commit | ||
else | ||
undeleted_institution_memberships.changeset(Lauth::Persistence::Changesets::InstitutionMembershipCreate, document).commit | ||
end | ||
|
||
undeleted_institution_memberships.where(userid: user_id, inst: institution_id).one | ||
end | ||
|
||
def find(user_id, institution_id) | ||
undeleted_institution_memberships.where(userid: user_id, inst: institution_id).one | ||
end | ||
|
||
def update(document) | ||
document = Hanami::Utils::Hash.deep_symbolize(document) | ||
user_id = document[:data][:attributes][:user_id] | ||
institution_id = document[:data][:attributes][:institution_id] | ||
institution_membership = deleted_institution_memberships.where(userid: user_id, inst: institution_id).one | ||
return nil if institution_membership | ||
|
||
if undeleted_institution_memberships.where(userid: user_id, inst: institution_id).one | ||
undeleted_institution_memberships.where(userid: user_id, inst: institution_id).changeset(Lauth::Persistence::Changesets::InstitutionMembershipUpdate, document).commit | ||
end | ||
|
||
undeleted_institution_memberships.where(userid: user_id, inst: institution_id).one | ||
end | ||
|
||
def delete(user_id, institution_id) | ||
institution_membership = find(user_id, institution_id) | ||
undeleted_institution_memberships.where(userid: user_id, inst: institution_id).update(dlpsDeleted: "t") if institution_membership | ||
institution_membership | ||
end | ||
|
||
protected | ||
|
||
def undeleted_institution_memberships | ||
institution_memberships.where(dlpsDeleted: "f") | ||
end | ||
|
||
def deleted_institution_memberships | ||
institution_memberships.where(dlpsDeleted: "t") | ||
end | ||
end | ||
end | ||
end |
16 changes: 16 additions & 0 deletions
16
lauth/lib/lauth/persistence/changesets/institution_membership_create.rb
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,16 @@ | ||
module Lauth | ||
module Persistence | ||
module Changesets | ||
class InstitutionMembershipCreate < ROM::Changeset::Create | ||
map do | ||
deep_symbolize_keys | ||
unwrap :data | ||
unwrap :attributes | ||
reject_keys [:type] | ||
rename_keys user_id: :userid, institution_id: :inst | ||
deep_merge lastModifiedTime: Time.now | ||
end | ||
end | ||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
lauth/lib/lauth/persistence/changesets/institution_membership_update.rb
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,24 @@ | ||
module Lauth | ||
module Persistence | ||
module Changesets | ||
class InstitutionMembershipUpdate < ROM::Changeset::Update | ||
map do | ||
deep_symbolize_keys | ||
unwrap :data | ||
unwrap :attributes | ||
reject_keys [:type] | ||
rename_keys user_id: :userid, institution_id: :inst | ||
deep_merge lastModifiedTime: Time.now | ||
end | ||
|
||
def clean? | ||
false | ||
end | ||
|
||
def diff? | ||
true | ||
end | ||
end | ||
end | ||
end | ||
end |
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