蔵書管理処理のドラフト完了
authorOHASHI, Norikazu <katz@neko-mori.sakura.ne.jp>
Tue, 30 Apr 2019 14:46:33 +0000 (23:46 +0900)
committerOHASHI, Norikazu <katz@neko-mori.sakura.ne.jp>
Tue, 30 Apr 2019 14:46:33 +0000 (23:46 +0900)
create_table.sql
sinatra/app/controllers/web_gui.rb
sinatra/app/models/books_db.rb
sinatra/app/views/book_info.haml [new file with mode: 0644]
sinatra/app/views/book_regist.haml [moved from sinatra/app/views/coffee/book_regist.haml with 95% similarity]

index 8a5df9a..bfe59de 100644 (file)
@@ -29,9 +29,9 @@ CREATE TABLE book_collections (
        isbn VARCHAR(14) NOT NULL,
        user_id INTEGER NOT NULL,
        summary TEXT,
-       rank INTEGER,
+       book_rank INTEGER,
        create_at DATETIME NOT NULL,
-       update_at DATETIME NOT NULL
+       update_at DATETIME NOT NULL,
        PRIMARY KEY(isbn, user_id));
        
 CREATE TABLE book_covers (
index 80ea3bf..12fdb9e 100644 (file)
@@ -209,7 +209,7 @@ class WebGui < Sinatra::Base
   # @post_param cover_file [Hash] イメージファイル情報
   # @post_param cover_base64 [String] イメージ情報(Base64)
   # @post_param summary  [String] 蔵書概要
-  # @post_param rank [Integer] 蔵書評価(0-5)
+  # @post_param book_rank [Integer] 蔵書評価(0-5)
   # @raise [WebError] セッションの期限切れ
   # @raise [WebError] 蔵書情報編集失敗
   post '/book_regist' do
@@ -228,7 +228,7 @@ class WebGui < Sinatra::Base
     
     params.each do |key, value|
       case key
-      when :sammary, :rank, :cover_base64, :cover_file
+      when :sammary, :book_rank, :cover_base64, :cover_file
         # 対象キーは書籍情報ではないので飛す
         next
       end
@@ -263,7 +263,7 @@ class WebGui < Sinatra::Base
       end
 
       # 蔵書情報の更新
-      BookManager.createBookCollect(isbn, id, params[:summary], params[:rank])
+      BookManager.createBookCollect(isbn, id, params[:summary], params[:book_rank])
       
     rescue BookManager::NotFoundInstanceError,
            BookManager::AlreadyInstanceError
@@ -277,6 +277,7 @@ class WebGui < Sinatra::Base
   # @raise [WebError] セッションの期限切れ
   # @raise [WebError] 登録済みの蔵書だった。
   post '/book_search_isbn' do
+    id = session[:userId]
     if (id == nil)
       raise WebError.new(status: 408, message: "セッション期限切れです。再ログインをしてください。")
     end
@@ -294,6 +295,7 @@ class WebGui < Sinatra::Base
   # @post_param [Hash] cover_file イメージファイル情報
   # @raise [WebError] セッションの期限切れ
   post '/book_upload_cover' do
+    id = session[:userId]
     if (id == nil)
       raise WebError.new(status: 408, message: "セッション期限切れです。再ログインをしてください。")
     end
@@ -307,7 +309,34 @@ class WebGui < Sinatra::Base
     end
     goPage :book_regist
   end
-  
+
+  # 書影の表示
+  get '/book_image/:hash' do
+    image_hash = params[:hash]
+    book_cover = BookManager.getBookCover(image_hash)
+    
+    status 200
+    headers \
+      "Content-Type" => "image/jpeg",
+      "Last-Modified" =>  book_cover.create_at.httpdate
+    body book_cover.cover
+
+  end
+
+  get '/book_info/:isbn' do
+    id = session[:userId]
+    isbn = params[:isbn]
+    if (id == nil)
+      raise WebError.new(status: 408, message: "セッション期限切れです。再ログインをしてください。")
+    end
+
+    begin
+      @book_info = BookManager.getBookCollect(isbn, id)
+    rescue BookManager::NotFoundInstanceError
+      raise WebError.new(status: 404, message: "", refs: "/user_home")
+    end
+    goPage :book_info
+  end
   # ログアウトページ
   get '/logout' do
     # 最終ログイン情報登録
index 754824a..69a4e6d 100644 (file)
@@ -461,9 +461,9 @@ class BookManager
   # @param [String] isbn 登録するISBN
   # @param [Integer] user_id 登録対象のユーザID
   # @param [String] summary ユーザ毎の紹介分
-  # @param [Integer] rank ユーザの評価
+  # @param [Integer] book_rank ユーザの評価
   # @return [BookCollection]  蔵書情報
-  def createBookCollect(isbn, user_id, summary, rank)
+  def createBookCollect(isbn, user_id, summary, book_rank)
     if (BookCollection.find_by(isbn: isbn, user_id: user_id) != nil)
       raise NotFoundInstanceError
     end
@@ -471,7 +471,7 @@ class BookManager
     book_collect.isbn = isbn
     book_collect.user_id = user_id
     book_collect.summary = summary
-    book_collect.rank = rank
+    book_collect.book_rank = book_rank
     book_collect.create_at = DateTime.now
     book_collect.update_at = DateTime.now
     if (not book_collect.save)
diff --git a/sinatra/app/views/book_info.haml b/sinatra/app/views/book_info.haml
new file mode 100644 (file)
index 0000000..720f68a
--- /dev/null
@@ -0,0 +1,103 @@
+- # encoding: utf-8
+- admin_f = @admin_f
+- id = @id
+- book_info = @book_info
+
+%h2
+  #{book_info[:title]}
+
+  %image{:border => '1', :src => book_info[:cover_uri], :width => '256', :height => '364'}
+    
+.book_table  
+  %table
+    %tr
+      %th
+        ISBN
+      %td
+        #{book_info[:isbn]}
+    %tr
+      %th
+        書名
+      %td
+        #{book_info[:title]} 
+        - if book_info [:value] != nil
+          : #{book_info[:value]} 巻
+    - if book_info[:series] != nil
+      %tr
+        %th
+          単行本シリーズ
+        %td
+          #{book_info[:series]}
+    - if book_info[:author] != nil
+      %tr
+        %th
+          著者
+        %td
+          #{book_info[:author]}
+    - if book_info[:orignal_author] != nil
+      %tr
+        %th
+          原作者
+        %td
+          #{book_info[:orignal_author]}
+    - if book_info[:illustrator]
+      %tr
+        %th
+          作画
+        %td
+          #{book_info[:illustrator]}
+    - if book_info[:translator] != nil
+      %tr
+        %th
+          翻訳
+        %td
+          #{book_info[:translator]}
+    - if book_info[:supervisor] != nil
+      %tr
+        %th
+          監修
+        %td
+          #{book_info[:supervisor]}
+    - if book_info[:publisher] != nil
+      %tr
+        %th
+          出版社
+        %td
+          #{book_info[:publisher]}
+    - if book_info[:pubdate] != nil
+      %tr
+        %th
+          出版日
+        %td
+          #{book_info[:pubdate]}
+    - if book_info[:summary] != nil
+      %tr
+        %th
+          書籍概要
+        %td
+          %pre
+            #{book_info[:summary]}
+    - if book_info[:book_rank] != nil
+      %tr
+        %th
+          評価
+        %td
+          - case book_info[:book_rank]
+          - when 0 then
+            .rank
+              ☆ ☆ ☆ ☆ ☆
+          - when 1 then
+            .rank
+              ★ ☆ ☆ ☆ ☆
+          - when 2 then
+            .rank
+              ★ ★ ☆ ☆ ☆
+          - when 3 then
+            .rank
+              ★ ★ ★ ☆ ☆
+          - when 4 then
+            .rank
+              ★ ★ ★ ★ ☆
+          - when 5 then
+            .rank
+              ★ ★ ★ ★ ★
similarity index 95%
rename from sinatra/app/views/coffee/book_regist.haml
rename to sinatra/app/views/book_regist.haml
index a33afd9..e802e79 100644 (file)
           #{book_info[:summary]}
 
       .item
-        %label{ :for => 'rank' }
+        %label{ :for => 'book_rank' }
           %span
             評価:
-        %input{:name => 'rank', :type => 'text', :id => 'rank', :value => book_info[:rank], :pattern => '[0-5]'}
+        %input{:name => 'book_rank', :type => 'text', :id => 'book_rank', :value => book_info[:book_rank], :pattern => '[0-5]'}
         
     .buttons
       %hr