-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
17,910 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# A Marejew Gemfile | ||
source "https://rubygems.org" | ||
|
||
# Gem names | ||
gem 'sinatra' | ||
gem 'sinatra-contrib' | ||
gem 'rakuten_web_service' | ||
gem 'sqlite3' | ||
gem 'active_record' | ||
gem 'slim' | ||
gem 'thin' |
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 |
---|---|---|
@@ -1,2 +1,9 @@ | ||
marejew | ||
======= | ||
## Marejew | ||
|
||
# Marejewとは? | ||
Marejewは、OPACです。 | ||
|
||
Marejewは、[マリアン・アダム・レイェフスキ](http://ja.wikipedia.org/wiki/%E3%83%9E%E3%83%AA%E3%82%A2%E3%83%B3%E3%83%BB%E3%83%AC%E3%82%A4%E3%82%A7%E3%83%95%E3%82%B9%E3%82%AD)という数学者が由来です。 | ||
|
||
# ライセンス | ||
GPL v.2 |
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,82 @@ | ||
# -*- coding: utf-8 -*- | ||
# require 'bundler' | ||
# | ||
# Bundler.require | ||
# self.sinatra/base | ||
# self.slim | ||
# self.sinatra/reloader | ||
# self.thin | ||
# require './db' | ||
|
||
require 'sinatra/base' | ||
require 'slim' | ||
require 'sinatra/reloader' | ||
require 'thin' | ||
require './db' | ||
|
||
module Marejew2 | ||
class Application < Sinatra::Base | ||
enable :sessions | ||
get "/" do | ||
@title = "Home" | ||
@active = "home" | ||
slim :index | ||
end | ||
|
||
get "/lend" do | ||
@title = "貸出" | ||
@active = "lend" | ||
slim :lend | ||
end | ||
|
||
get "/return" do | ||
@title = "返却" | ||
@active = "return" | ||
slim :return | ||
end | ||
|
||
post "/lend_second" do | ||
users_id = params[:users_id] | ||
session[:users_id] = nil | ||
if Database::Search.user?(users_id) && Database::Search.book_limit?(users_id) | ||
puts "OK" | ||
session[:users_id] = users_id | ||
@title = "貸出" | ||
@active = "lend" | ||
slim :lend_second | ||
else | ||
redirect :lend | ||
end | ||
end | ||
|
||
post "/lend_finished" do | ||
books_number = params[:books_number] | ||
if session[:users_id] | ||
if Database::Search.book?(books_number) && !Database::Search.lend?(books_number) | ||
Database::Add.lend(session[:users_id], books_number) | ||
Database::Add.book_limit(session[:users_id]) | ||
@title = "貸出完了" | ||
@active = "lend" | ||
slim :lend_finished | ||
else | ||
redirect :lend | ||
end | ||
else | ||
redirect :lend | ||
end | ||
end | ||
|
||
post "/return_finished" do | ||
books_number = params[:books_number] | ||
if Database::Search.lend?(books_number) | ||
users_id = Database::Delete.lend(books_number) | ||
Database::Delete.book_limit(users_id) | ||
@title = "返却完了" | ||
@active = "return" | ||
slim :return_finished | ||
else | ||
redirect :return | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'sinatra' | ||
require 'sinatra/reloader' | ||
require 'slim' | ||
require 'thin' | ||
$LOAD_PATH << File.dirname(__FILE__) | ||
require 'app' | ||
run Marejew2::Application |
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,153 @@ | ||
# -*- coding: utf-8 -*- | ||
# require 'bundler' | ||
# | ||
# Bundler.require | ||
# self.active_record | ||
# self.rakuten_web_service | ||
# require 'date' | ||
# require 'yaml' | ||
|
||
require 'rakuten_web_service' | ||
require 'active_record' | ||
require 'date' | ||
require 'yaml' | ||
|
||
ActiveRecord::Base.establish_connection( | ||
:adapter => "sqlite3", | ||
:database => "./db/marejew.db" | ||
) | ||
|
||
class Users < ActiveRecord::Base | ||
end | ||
|
||
class Books < ActiveRecord::Base | ||
end | ||
|
||
class Lendbooks < ActiveRecord::Base | ||
end | ||
|
||
module Database | ||
class Add | ||
class << self | ||
def user(users_name, users_class) | ||
Users.create(name: users_name, uclass: users_class, booklimit: 0) | ||
end | ||
|
||
def book(books_title, books_author, books_publisher, isbn) | ||
Books.create(title: books_title, author: books_author, publisher: books_publisher, isbn: isbn) | ||
end | ||
|
||
def isbn_book(isbn) | ||
rakuten_id = [application_id: "", affiliate_id: ""] | ||
RakutenWebService.configuration do |c| | ||
c.application = rakuten_id[:application_id] | ||
c.affiliate_id = rakuten_id[:affiliate_id] | ||
end | ||
books = RakutenWebService::Books::Book.search(isbn: isbn) | ||
books.each do |book| | ||
title = book["title"] | ||
author = book["author"] | ||
publisher_name = book["publisherName"] | ||
isbn = book["isbn"] | ||
Books.create(title: title, author: author, publisher: publisher_name, isbn: isbn) | ||
end | ||
end | ||
|
||
def lend(users_id, books_number) | ||
lend_day = Date.today | ||
return_day = lend_day + 7 | ||
|
||
lend = Lendbooks.new do |l| | ||
l.users_id = users_id | ||
l.books_id = books_number | ||
l.lendday = lend_day.to_s | ||
l.returnday = return_day.to_s | ||
end | ||
lend.save | ||
end | ||
|
||
def book_limit(users_id) | ||
users = Users.find(users_id) | ||
book_limit = users[:booklimit] | ||
book_limit += 1 | ||
Users.update(users_id, booklimit: book_limit) | ||
end | ||
end | ||
end | ||
|
||
class Search | ||
class << self | ||
def user?(users_id) | ||
if Users.where(id: users_id) | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
def book?(books_number) | ||
if Books.find_by_id(books_number) | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
def lend?(books_number) | ||
if Lendbooks.find_by_books_id(books_number) | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
def book_limit?(users_id) | ||
begin | ||
record = Users.find_by_id(users_id) | ||
if record == nil | ||
false | ||
end | ||
books_limit = record[:booklimit] | ||
books_limit += 1 | ||
if books_limit <= 2 | ||
true | ||
else | ||
false | ||
end | ||
rescue | ||
false | ||
end | ||
end | ||
end | ||
end | ||
|
||
class Delete | ||
class << self | ||
def user(users_id) | ||
user = Users.find(users_id) | ||
user.destroy | ||
end | ||
|
||
def book(book_number) | ||
book = Books.find(book_number) | ||
book.destroy | ||
end | ||
|
||
def lend(books_number) | ||
lend = Lendbooks.find(books_number) | ||
lend.destroy | ||
return lend[:users_id] | ||
end | ||
|
||
def book_limit(users_id) | ||
users = Users.find(users_id) | ||
book_limit = users[:booklimit] | ||
book_limit -= 1 | ||
Users.update(users_id, booklimit: book_limit) | ||
end | ||
end | ||
end | ||
end | ||
p Users.all | ||
p Books.all | ||
p Lendbooks.all |
Binary file not shown.
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,28 @@ | ||
create table users ( | ||
id integer primary key, | ||
name text, | ||
uclass text, | ||
booklimit integer, | ||
created_at, | ||
updated_at | ||
); | ||
|
||
create table books ( | ||
id integer primary key, | ||
title text, | ||
author text, | ||
publisher text, | ||
isbn text, | ||
created_at, | ||
updated_at | ||
); | ||
|
||
create table lendbooks ( | ||
id integer primary key, | ||
books_id integer, | ||
users_id integer, | ||
lendday text, | ||
returnday text, | ||
created_at, | ||
updated_at | ||
); |
Oops, something went wrong.