object

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2024 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

* Copyright (c) 2024 flowerinsnow * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/.

* Copyright (c) 2024 flowerinsnow * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/.

* Copyright (c) 2024 flowerinsnow * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Book

type Book struct {
	Id   int
	Name string
}

func NewBook

func NewBook(id *sql.NullInt32, name *sql.NullString) *Book

NewBook 返回一个新的 Book 指针 如果无效返回空

func (*Book) String

func (b *Book) String() string

type BookWithHeldStudent

type BookWithHeldStudent struct {
	Instance *Book
	Borrower *Student
}

type Library

type Library interface {
	// BorrowBook 是让 Student 借走 Book
	// 如果书已被借走、学生已经借过书了、书不存在于数据库中、学生不存在于中会返回 error
	BorrowBook(int, int) error
	// ListBooks 将列出图书馆中所有的书籍以及它们的持有者
	ListBooks() []*BookWithHeldStudent
	// ListStudents 将列出数据库中所有的学生以及它们持有的图书
	ListStudents() []*StudentWithHeldBook
	// FindStudentById 用于通过 id 查找学生
	FindStudentById(int) (*StudentWithHeldBook, bool)
	// FindBookById 用于通过 id 查找学生
	FindBookById(int) (*BookWithHeldStudent, bool)
	// ReleaseBook 将将 Book 从一名学生手中归还
	// 如果 Book 不存在,则返回 error
	ReleaseBook(int) error
}

Library 是一个抽象的图书馆,提供了最基本的内容

type Student

type Student struct {
	Id   int
	Name string
}

func NewStudent

func NewStudent(id *sql.NullInt32, name *sql.NullString) *Student

NewStudent 返回一个 Student 指针 如果无效返回空

func (*Student) String

func (s *Student) String() string

type StudentWithHeldBook

type StudentWithHeldBook struct {
	Instance *Student
	Borrowed *Book
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL